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 exit 1
fi fi
rsync_errors="" do_backup() {
% for path in sorted(paths):
rsync -zaAP --numeric-ids --delete --relative \ rsync -zaAP --numeric-ids --delete --relative \
--rsync-path="/usr/bin/rsync --fake-super" \ --rsync-path="/usr/bin/rsync --fake-super" \
-e "ssh -o IdentityFile=/etc/backup.priv -o StrictHostKeyChecking=accept-new -p ${port}" \ -e "ssh -o IdentityFile=/etc/backup.priv -o StrictHostKeyChecking=accept-new -p ${port}" \
"${path}" "$ssh_login":backups/ "$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=$? exitcode=$?
if [[ $exitcode != 0 ]] && [[ $exitcode != 24 ]] if [[ $exitcode != 0 ]] && [[ $exitcode != 24 ]]
then then
rsync_errors+=" $exitcode" rsync_errors+=" $exitcode"
fi fi
}
rsync_errors=""
% for path in sorted(paths):
do_backup "${path}"
% endfor % endfor
if [[ -n "$rsync_errors" ]] if [[ -n "$rsync_errors" ]]