Skip to content

Instantly share code, notes, and snippets.

@tommeier
Created March 20, 2012 00:05
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save tommeier/2128730 to your computer and use it in GitHub Desktop.
Save tommeier/2128730 to your computer and use it in GitHub Desktop.
RSync backup script for Mac OSX from External drive
#!/bin/sh
echo "Running..."
PROG=$0
RSYNC="/usr/bin/rsync"
SCRIPT_MOUNTED='false'
MOUNT_VOLUME="/Volumes/Qdownload"
SRC="$MOUNT_VOLUME/transmission/completed/"
DST="/Users/tom/Dumping Ground/Qnap Downloads"
HOME="/users/tom/Development/Projects/backup"
# Mount the backup
if [ ! -e "$MOUNT_VOLUME" ]; then
SCRIPT_MOUNTED='true'
echo 'Mounting drive'
mkdir $MOUNT_VOLUME
mount_smbfs //admin:<REPLACE_PASSWORD>@192.168.1.20/Qdownload $MOUNT_VOLUME
fi
# rsync options
# -v increase verbosity
# -a turns on archive mode (recursive copy + retain attributes)
# -x don't cross device boundaries (ignore mounted volumes)
# -E preserve executability
# -S handle spare files efficiently
# --delete delete deletes any files that have been deleted locally
# --exclude-from reference a list of files to exclude
if [ ! -r "$SRC" ]; then
MESSAGE="Source $SRC not readable - Cannot start the sync process"
/usr/bin/logger -t $PROG $MESSAGE
echo $MESSAGE
exit;
fi
if [ ! -w "$DST" ]; then
MESSAGE="Destination $DST not writeable - Cannot start the sync process"
/usr/bin/logger -t $PROG $MESSAGE
echo $MESSAGE
exit;
fi
/usr/bin/logger -t $PROG "Start rsync"
sudo $RSYNC -vaE -S --progress --human-readable --force --delete --exclude-from=$HOME/rsync_excludes.txt "$SRC" "$DST"
/usr/bin/logger -t $PROG "End rsync"
#Unmount drive if script mounted it
if [ "$SCRIPT_MOUNTED"=="true" ]; then
echo 'Unmounting drive'
umount $MOUNT_VOLUME;
fi
exit 0
.Spotlight-*/
.Trashes
/tmp/*
/Network/*
/cores/*
/afs/*
/automount/*
/private/tmp/*
/private/var/run/*
/private/var/spool/postfix/*
/private/var/vm/*
/Previous Systems.localized
/Volumes/*
*/.Trash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment