#!/bin/bash

# Script to use rsync to remove deleted/renamed/otherwise unwanted photos from their backup.

# Run weekly at 0100 hrs on Mondays via cron

# Standard disclaimers apply.

# V0.1 Created by canoemoose 31/12/14

# V0.2 Uses script's PID when creating files in /tmp/ to allow more than one running instance. Also tidies up in /tmp/ afterwards. 14/1/15

source = "/media/Network/photos/"

destination = "/media/Backups/Photos"

mailaddr = "someone@somewhere.com"

verbosity = 3 #0=report nothing, 1=report failures only, 2=report success too, 3=success with full logs

if rsync --dry-run --delete -azvv $source $destination 2 > / tmp / $$ .error > / tmp / $$ .output

then

if [ $verbosity -eq 3 ] ; then

cat < ( echo -e "Weekly rsync backup on $(hostname) on $(date) of $source to $destination completed successfully.



STDOUT follows:" ) / tmp / $$ .output | mail -s "Backup complete" $mailaddr

fi

if [ $verbosity -eq 2 ] ; then

echo "Weekly rsync backup on $(hostname) on $(date) of $source to $destination completed successfully" | mail -s "Backup complete" $mailaddr

fi

else

if [ $verbosity -ge 1 ] ; then

cat < ( echo -e "Weekly rsync backup on $(hostname) of $source to $destination FAILED at $(date)

Output of STDERR follows:" ) / tmp / $$ .error < ( echo -e "



STDOUT follows:" ) / tmp / $$ .output | mail -s "ERROR: Backup on $(hostname) failed" $mailaddr

fi

fi

rm / tmp / $$ . *