2020-11-13 11:36:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
statusfile=/var/tmp/backup.monitoring
|
|
|
|
ssh_login="${username}@${server}"
|
|
|
|
|
2021-08-04 13:55:14 +00:00
|
|
|
NL=$'\n'
|
|
|
|
|
2020-11-13 11:36:52 +00:00
|
|
|
if ! [[ -f /etc/backup.priv ]]
|
|
|
|
then
|
|
|
|
echo "abort_no_key" > "$statusfile"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-02-07 19:47:22 +00:00
|
|
|
run-parts --exit-on-error -- /etc/backup-pre-hooks.d
|
|
|
|
exitcode=$?
|
2021-02-09 06:17:25 +00:00
|
|
|
if [[ $exitcode != 0 ]]
|
2021-02-07 19:47:22 +00:00
|
|
|
then
|
|
|
|
echo "hook $exitcode" > "$statusfile"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-02-13 08:18:00 +00:00
|
|
|
do_backup() {
|
2021-05-14 08:47:58 +00:00
|
|
|
# Compress level 1 is a good compromise between speed and cpu usage.
|
|
|
|
rsync --compress-level=1 -aAP --numeric-ids --delete --relative \
|
2021-02-13 08:18:00 +00:00
|
|
|
--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
|
2021-08-04 13:55:14 +00:00
|
|
|
<%text>
|
|
|
|
rsync_errors+="${NL}${1} ${exitcode}"
|
|
|
|
</%text>
|
2021-02-13 08:18:00 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-11-13 11:36:52 +00:00
|
|
|
rsync_errors=""
|
|
|
|
% for path in sorted(paths):
|
2021-02-13 08:18:00 +00:00
|
|
|
do_backup "${path}"
|
2020-11-13 11:36:52 +00:00
|
|
|
% endfor
|
|
|
|
|
|
|
|
if [[ -n "$rsync_errors" ]]
|
|
|
|
then
|
|
|
|
echo "rsync_error$rsync_errors" > "$statusfile"
|
2020-11-13 12:23:57 +00:00
|
|
|
else
|
|
|
|
echo "ok" > "$statusfile"
|
2020-11-13 11:36:52 +00:00
|
|
|
fi
|