philippe::niquille | regular niche market thoughts

AppleScript Rsync hotplug backup v0.1

Mar 13th 2007
3 Comments
respond
trackback

After having had some desperate hours due to a complete MacBook harddrive crash lately I took action and coded a nice little AppleScript to backup my /Users/fluppel and /Applications to my external harddrive automatically after plugging it in.
I know that there are a couple of ways (commercial or free) out there to do this job. Despite the variety I did not find anything nicely interacting with growl and rsync though.

My script is able to copy local or remote (via SSH) folders to any locally available folder. I also implemented an experimental security feature. The size of the local and destination copy are looked up for comparison. If the source folder is significantly smaller the user gets a notification and the possibility to abort the transfer. Since I did not implement incremental backups (I don’t like them) the security feature could be handy, if you try to backup a local copy although you actually want to restore it from the disk itself.
Statistics get sent to growl for notification purposes.
If you do want incremental backups, the script could be easily changed to call rsnapshot or rsyncbackup. They both make use of (hard)links in order to preserve disk space.

1) You need a trigger to launch the AppleScript when you hot plug your device. Either use “Do something when” or configure launchd to do the same task for you.
- reference: TUAW

2) Get rsyncX if you haven’t done that yet (modified to better use HFS).

3) Get Growl and also install GrowlHelper (should be default).

4) Download my AppleScript:

MyRsyncBackup v0.1 as zip or raw text

Also configure the header to fit your needs:

(*
the name of your mounted volume (HD, Thumb drive, whatever is writable)
*)
property myDrive : “/Volumes/320GB”

(*
source folders on your local harddrive or remote server
- never add a / or /* as suffix - it won’t sync your .* files
- use “-e ssh user@mydomain.com:/home” for remote to local backups with SSH. Be sure to configure your SSH-Keys.
*)
property backupList : {”/Users/youruser/Desktop”,”/Applications”}

(*
destination folders (in the same order as backupList items !) on myDrive
- leave blank if you want the last folder in the source path to be the backup directory in myDrive root (ex. /Volumes/320B/mydest)
- do NOT add a / as prefix
- if you add a / as suffix (ex. sample/) your source directory will be copied into ex. mydest (ex. /Volumes/320GB/sample/mydest)
*)
property destinationList : {”test/”,”"}

property simulate : false — for debugging or testing (executes the rsync command with –dry-run)
property askFirst : true — security question, prevents destruction of a backup ready for recovery
property logger : true — log to system.log?
property deviation : 0.05 — security check. Ask if source directory is more than 5% smaller than your current backup dir, prevents destruction

Also be sure that the script is executable (save it as program). Then configure “Do something when” or launchd (see above) to launch this script.

The first time the script runs it should register with growl and show the corresponding notifications.

Your are all set!




screenshot_1.pngsource.png

3 Comments

  1. You have an amazing blog!
    I am really inspired by your design and writings, and truth be told, have been this way for quite some time now.

    In the future I only hope my blog is as good as yours!

    Yuck, I sound all mushy! But its a great blog!
    I was actually wondering what your “my del.icio.us” sidebar widget does?
    Is it just like a collection of RSS links?

    Okay, another question!
    What plug-ins do you use?
    AND!
    What do you use for your tag cloud?

    Sorry! I’m just really loving all the nifty features here!

  2. script is great - but - rsync doesn’t copy resource-forks. maybe you should extend the script to make this an option.
    I also made a small enhancement to your logic. Imagine you have 4 external disks (in my case DVD-RAM) the are formatted DISC_01 to DISC_04. Beginning from week 1 of the year I want the script to check if DISC_01 is mounted and only the make the backup. The next week it only should backup if DISC_02 is mounted and so on. In the fifth week it should again look for DISC_01 (modulo 4) and so on. So I have four generations of backups.
    If you are interested I could send you my (ugly!) code.
    Otherwise - great script!
    Bye, Rudi

  3. hmm, I should include it in an update.

    Sure! Send me your copy :-)

Incoming Links

Leave a Reply