Null Disquisition

Python, AWS, Grad School, and your face

Time Machine In Your Pocket – Part 2

with one comment

After a little tinkering here, a little tinkering there, I’ve finally settled on a good solution for my portable backup drive (8GB usb thumb drive). As outlined in my previous post, I wanted a portable backup solution that could do incremental backups (like Apple’s TimeMachine does). I looked, of course, to the wonderful unix utility rsync. Here’s my latest version.


#!/bin/bash -x

DEST="/Volumes/PNY8GB/Backups"
LATEST="Latest"
EXCLUDES_FILE="$HOME/.rsyncexcludes"
FILES_FROM="$HOME/.rsyncfiles"
RSYNC="/usr/bin/rsync --max-size 10m"

# Make sure user is root
if (( `id -u` != 0 )); then
    { echo "Sorry, must be root. Exiting..."; exit; }
fi;

# Make sure backup device is attached
! test -d "$DEST" && echo "Please mount the backup drive!" && exit

# Run rsync
DATE=`date "+%Y-%m-%d-%H%M%S"`
n=`$RSYNC -r -a -x -S -R --stats --delete --link-dest=$DEST/$LATEST \
 --exclude-from $EXCLUDES_FILE --files-from $FILES_FROM $* $HOME \
 $DEST/$DATE | sed -n 's/Number of files transferred: \([^0]\)/\1/p'`

# Update 'Latest' link
rm $DEST/$LATEST
ln -s $DEST/$DATE $DEST/$LATEST

# Send a growl notification
if [ $n ]
then
    /usr/local/bin/growlnotify -m 'rsync complete,
number of files: '$n
fi


By using ––exlude-from and ––files-from, you get more fine grained control of what gets backed up. My Code folder is ~1GB, and my School folder is about 3GB. When I exclude all of my compiled code, data files, images, .git and .svn folders, and other various annoying swap files my base backup footprint is less than 500MB (for both Code and School).

Here’s my excludes file – it’s just one line per exclude filter

*.sql
*.bak
*.swp
.svn
*.pyc
*.log
*.tar.gz
*.dvi
*.o
*.out
*.d
*.tmp
.git


Similarly, the files-from file is one file path per line (remember the trailing slash!). An important note (found in the rsync manual) is that when you specify ––files-from, -r is no longer implied with -a. So make sure to add -r to your argument list.

And yet again, I leave the scheduling to you.

-David

Written by david

March 28th, 2009 at 4:46 pm

Posted in Mac

Tagged with , , ,

One Response to 'Time Machine In Your Pocket – Part 2'

Subscribe to comments with RSS or TrackBack to 'Time Machine In Your Pocket – Part 2'.

  1. [...] Addendum to two previoius posts. [...]

Leave a Reply