#!/bin/bash # This very simple script will take an rsync source and mountable target disk and synchronize the source and targets. # Specify the path the rsync command or comment it out and comment out the default RSYNC=/usr/bin/rsync # RSYNC=`which rsync` # The rsync source to synchronize RSYNCSOURCE=/data/shared # The label of the ext4 formatted rsync drive to backup to RSYNCLABEL=RSYNCBACKUPS # The mount point for the rsync drive RSYNCMOUNT=/data/rsync die() { echo "[FATAL] - $@" echo This script will abort. exit 1 } # flush the drive cache (of the source) before rsyncing and the target before ejecting flushcache() { sync ; echo 3 > /proc/sys/vm/drop_caches } doRsync() { flushcache; $RSYNC -av $RSYNCSOURCE $RSYNCMOUNT flushcache; } if [ ! -x $RSYNC ]; then echo "" echo "" echo "" echo "rsync is not installed in standard location as:" echo "$RSYNC" echo "Sorry." echo "Install or link it in this location, or edit:" echo "" echo "$0" echo "" echo "to update this script with the correct location" echo "Aborting." echo "" echo "" echo "" exit 1 fi if mount -l|grep $RSYNCLABEL >/dev/null; then doRsync else mount -t ext4 LABEL=$RSYNCLABEL $RSYNCMOUNT || die "The rsync target ($RSYNCLABEL) is not mounted!" doRsync fi