Is my backup complete?

Heads up! This post was written when Metric Marketing was known as Canada's Web Shop.
headshot

Many server administrators use rsync to synronize files between local as well as offsite media. Often it's used within a scheduled backup script. But how can you tell if rsync was successful or not without looking through the output of the command in detail? If it wasn't successful, how can you tell if it was an error or warning that you would normally ignore (for example, the "Partial transfer due to vanished source files" error that happens in  maildir files that come and go normally during the backup and don't need to be backed up)? Here's an example script that can help.

#!/bin/bash

#example rsync line, use your own

rsync --delete --exclude sys --exclude var/lib/php/session --exclude proc --exclude dev --exclude tmp --exclude var/named/chroot/var/run --exclude var/named/chroot/var/tmp --exclude var/named/chroot/proc --exclude var/named/chroot/dev --stats -a -z / -e 'ssh -ax root@remoteserver.com:/backup/.  > /var/log/backup.log

codes[0]="Success"
codes[1]="Syntax or usage error"
codes[2]="Protocol incompatibility"
codes[3]="Errors selecting input/output files, dirs"
codes[4]="Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server"
codes[5]="Error starting client-server protocol"
codes[6]="Daemon unable to append to log-file"
codes[10]="Error in socket I/O"
codes[11]="Error in file I/O"
codes[12]="Error in rsync protocol data stream"
codes[13]="Errors with program diagnostics"
codes[14]="Error in IPC code"
codes[20]="Received SIGUSR1 or SIGINT"
codes[21]="Some error returned by waitpid()"
codes[22]="Error allocating core memory buffers "
codes[23]="Partial transfer due to error"
codes[24]="Partial transfer due to vanished source files"
codes[25]="The --max-delete limit stopped deletions"
codes[30]="Timeout in data send/receive"
codes[35]="Timeout waiting for daemon connection"

RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo "Failure in rsync."
echo "Exit status was ${codes[$RETVAL]}"
fi

if [ $RETVAL -eq 0 ]; then
echo "rsync successful"
fi

Your scripted output will appear below your normal rsync output, so what I did at the end of my rsync command is redirect the output to a log file (/var/log/backup.log), and go look at the log if there was a problem reported by the above script.

Like what you read? Sign up for our Newsletter.