bundles/backup-client: use a bash function to do backups instead of repeating the same code over and over

This commit is contained in:
Franzi 2021-02-13 09:18:00 +01:00
parent adeb8eff88
commit 65e6b8d053
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -17,18 +17,24 @@ then
exit 1
fi
do_backup() {
rsync -zaAP --numeric-ids --delete --relative \
--rsync-path="/usr/bin/rsync --fake-super" \
-e "ssh -o IdentityFile=/etc/backup.priv -o StrictHostKeyChecking=accept-new -p ${port}" \
"$1" "$ssh_login":backups/
# Exit code 24 means some files have vanished during rsync.
# I don't know why, but this is very common, apparently?
exitcode=$?
if [[ $exitcode != 0 ]] && [[ $exitcode != 24 ]]
then
rsync_errors+=" $exitcode"
fi
}
rsync_errors=""
% for path in sorted(paths):
rsync -zaAP --numeric-ids --delete --relative \
--rsync-path="/usr/bin/rsync --fake-super" \
-e "ssh -o IdentityFile=/etc/backup.priv -o StrictHostKeyChecking=accept-new -p ${port}" \
"${path}" "$ssh_login":backups/
exitcode=$?
if [[ $exitcode != 0 ]] && [[ $exitcode != 24 ]]
then
rsync_errors+=" $exitcode"
fi
do_backup "${path}"
% endfor
if [[ -n "$rsync_errors" ]]