Log backup success and failure

This commit is contained in:
Janek Bevendorff 2016-11-18 00:36:27 +01:00
parent 1a0c1b984f
commit 5f03542d07
5 changed files with 53 additions and 6 deletions

View File

@ -31,7 +31,7 @@ command -v lsb_release > /dev/null 2>&1
if [ $? -eq 0 ]; then
lsb_release -is
elif [ -e /etc/synoinfo.conf ] || [ -e /usr/lib/libsynoutils.so ]; then
elif [ -e /etc/synoinfo.conf ] || [ -e /lib/$(ls /lib | grep libsynosdk | head -n1) ]; then
echo "Synology"
else
echo "unknown"

View File

@ -37,10 +37,9 @@ if [ "$1" != "info" ] && [ "$1" != "warn" ] && [ "$1" != "err" ]; then
fi
distribution=$(rs-detect-distribution)
if [[ "Synology" == "${distribution}" ]]; then
# Use Synology's crappy synologd if we're on DSM
synologset1 sys $1 0x99000001 "$2"
/usr/syno/bin/synologset1 sys $1 0x99000001 "[rs-backup-server] $2"
else
# Any other distribution
command -v logger > /dev/null
@ -48,12 +47,13 @@ else
logger -p $1 -t rs-backup-server "$2"
else
# Log to STDOUT/STDERR if we have no syslog facility
prefix="$(date) [rs-backup-server]"
if [ "$1" == "err" ]; then
echo "ERROR: $2" >&2
echo "$prefix ERROR: $2" >&2
elif [ "$1" == "warn" ]; then
echo "WARNING: $2" >&2
echo "$prefix WARNING: $2" >&2
else
echo "INFO: $2"
echo "$prefix INFO: $2"
fi
fi
fi

View File

@ -36,7 +36,35 @@ if [ "$RSYNC_EXIT_STATUS" == "" ]; then
exit 1
fi
# rsync exit code descriptions found at
# <https://lxadm.com/Rsync_exit_codes>
msg="unknown code"
case $RSYNC_EXIT_STATUS in
0) msg="Success" ;;
1) msg="Syntax or usage error" ;;
2) msg="Protocol incompatibility" ;;
3) msg="Errors selecting input/output files, dirs" ;;
4) msg="Requested action not supported: an attempt was made to manipulate 64-bit files on a platformi " \
"that cannot support them; or an option was specified that is supported by the client and not by the server" ;;
5) msg="Error starting client-server protocol" ;;
6) msg="Daemon unable to append to log-file" ;;
10) msg="Error in socket I/O" ;;
11) msg="Error in file I/O" ;;
12) msg="Error in rsync protocol data stream" ;;
13) msg="Errors with program diagnostics" ;;
14) msg="Error in IPC code" ;;
20) msg="Received SIGUSR1 or SIGINT" ;;
21) msg="Some error returned by waitpid()" ;;
22) msg="Error allocating core memory buffers" ;;
23) msg="Partial transfer due to error" ;;
24) msg="Partial transfer due to vanished source files" ;;
25) msg="The --max-delete limit stopped deletions" ;;
30) msg="Timeout in data send/receive" ;;
35) msg="Timeout waiting for daemon connection" ;;
esac
if [ $RSYNC_EXIT_STATUS -eq 0 ] || [ $RSYNC_EXIT_STATUS -eq 24 ]; then
rs-logger info "Backup for user '$(id -un)' finished with exit code ${RSYNC_EXIT_STATUS} (${msg})"
RSNAPSHOT="rsnapshot"
if [ -x /usr/bin/rsnapshot ]; then
RSNAPSHOT="/usr/bin/rsnapshot"
@ -44,4 +72,14 @@ if [ $RSYNC_EXIT_STATUS -eq 0 ] || [ $RSYNC_EXIT_STATUS -eq 24 ]; then
RSNAPSHOT="/opt/bin/rsnapshot"
fi
$RSNAPSHOT -c "$1" push
rsnapshot_exit_code=$?
if [ $rsnapshot_exit_code -eq 1 ]; then
rs-logger err "Backup rotation for level 'push' of user '$(id -un)' failed."
elif [ $rsnapshot_exit_code -eq 2 ]; then
rs-logger warn "Backup rotation for level 'push' of user '$(id -un)' finished with warnings."
else
rs-logger info "Backup rotation for level 'push' of user '$(id -un)' finished."
fi
else
rs-logger err "Backup for user '$(id -un)' failed with exit code ${RSYNC_EXIT_STATUS} (${msg})"
fi

View File

@ -36,6 +36,7 @@ if $(echo "${SSH_ORIGINAL_COMMAND}" | grep -q "^\(internal-sftp\|.*/sftp-server\
[ -x /usr/libexec/sftp-server ] && exec /usr/libexec/sftp-server -R
[ -x /opt/libexec/sftp-server ] && exec /opt/libexec/sftp-server -R
else
rs-logger info "Starting backup for user '$(id -un)'."
RSYNC_OPTS="--server --daemon --config='$home_dir/rsync.conf' ."
[ -x /usr/bin/rsync ] && exec /usr/bin/rsync $(eval echo $RSYNC_OPTS)
[ -x /opt/bin/rsync ] && exec /opt/bin/rsync $(eval echo $RSYNC_OPTS)

View File

@ -63,5 +63,13 @@ for home_dir in "${BACKUP_ROOT}"/*; do
owner=$(${stat_cmd} -c '%U' .)
su - "${owner}" -c "rsnapshot -c '${home_dir}/rsnapshot.conf' '$1'"
rsnapshot_exit_code=$?
if [ $rsnapshot_exit_code -eq 1 ]; then
rs-logger err "Backup rotation for level '$1' of user '$(id -un)' failed."
elif [ $rsnapshot_exit_code -eq 2 ]; then
rs-logger warn "Backup rotation for level '$1' of user '$(id -un)' finished with warnings."
else
rs-logger info "Backup rotation for level '$1' of user '$(id -un)' finished."
fi
fi
done