containers-borg/backup.sh
f 1f91c59c70
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
fix: use user pubkeys
2022-11-12 14:58:22 -03:00

31 lines
833 B
Bash
Executable file

#!/bin/sh
set -e
# Password can't be empty
test -n "${BORG_PASSPHRASE}"
test -n "${DEST}"
test -n "${SSH_ALIAS}"
DATE="$(date +%F)"
ORIG=/srv/data
if ! grep -q "${SSH_ALIAS}" /root/.ssh/config ; then
echo "Host ${SSH_ALIAS}" >> /root/.ssh/config
echo " Port ${SSH_PORT:-22}" >> /root/.ssh/config
echo " HostName ${SSH_SERVER:-${SSH_ALIAS}}" >> /root/.ssh/config
echo " User ${SSH_USER:-root}" >> /root/.ssh/config
fi
ssh -fN ${SSH_ALIAS}
for signal in TERM QUIT HUP EXIT INT KILL; do
trap "ssh -O exit \"${SSH_ALIAS}\"" ${signal}
done
# It'll fail the second time
borg init --encryption=repokey "${SSH_ALIAS}:${DEST}" || :
borg create -v --stats "${SSH_ALIAS}:${DEST}::${DATE}" "${ORIG}"
borg prune -v --stats --keep-daily ${KEEP} "${SSH_ALIAS}:${DEST}"
exit $?