From 5f03542d07304b3f49f1dfe0eb03cf32bff9c0b8 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Fri, 18 Nov 2016 00:36:27 +0100 Subject: [PATCH] Log backup success and failure --- server/usr/bin/rs-detect-distribution | 2 +- server/usr/bin/rs-logger | 10 +++---- server/usr/bin/rs-rotate | 38 +++++++++++++++++++++++++++ server/usr/bin/rs-run-ssh-cmd | 1 + server/usr/sbin/rs-rotate-cron | 8 ++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/server/usr/bin/rs-detect-distribution b/server/usr/bin/rs-detect-distribution index 41726be..49fb274 100755 --- a/server/usr/bin/rs-detect-distribution +++ b/server/usr/bin/rs-detect-distribution @@ -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" diff --git a/server/usr/bin/rs-logger b/server/usr/bin/rs-logger index bd3416a..2b5f77d 100755 --- a/server/usr/bin/rs-logger +++ b/server/usr/bin/rs-logger @@ -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 diff --git a/server/usr/bin/rs-rotate b/server/usr/bin/rs-rotate index af3eaed..449b08e 100755 --- a/server/usr/bin/rs-rotate +++ b/server/usr/bin/rs-rotate @@ -36,7 +36,35 @@ if [ "$RSYNC_EXIT_STATUS" == "" ]; then exit 1 fi +# rsync exit code descriptions found at +# +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 diff --git a/server/usr/bin/rs-run-ssh-cmd b/server/usr/bin/rs-run-ssh-cmd index d0c50b6..c7ec9cf 100755 --- a/server/usr/bin/rs-run-ssh-cmd +++ b/server/usr/bin/rs-run-ssh-cmd @@ -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) diff --git a/server/usr/sbin/rs-rotate-cron b/server/usr/sbin/rs-rotate-cron index b938a62..aae734a 100755 --- a/server/usr/sbin/rs-rotate-cron +++ b/server/usr/sbin/rs-rotate-cron @@ -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