Automatically sync Documents folder to iDisk

Jul 23, '08 07:30:00AM

Contributed by: Supp0rtLinux

Google searches for Sync iDisk largely show results that say something along the lines of "just edit the iDisk version." For me, iDisk is more about backup than anything else. I don't really have the need to share Documents with other people, and the local Documents folder of my laptop is always authoritative for my data. However, it would be nice to have a synced and restorable copy of my Documents "in the cloud" in the event my laptop fails. rsync works well for this.

My first step was to log into MobileMe, click the Account link, then to click on Storage Settings. Here I dropped my mail storage from 10Gb to 2Gb and ended up with an 18Gb iDisk, perfect for backing up my critical documents. Next, I wrote up a simple shell script to handle the rsync function and to copy the data from my local Documents folder to my iDisk's Documents folder.

The script is below:

#!/bin/sh

# Sync all data from Documents dir (except Virtual Machines) to MobileMe iDisk

export LOG=/Volumes/"Macintosh HD"/Users/MyName/idisk.log

echo `date` > $LOG
echo "Starting copy of Documents to iDisk..." >> $LOG

rsync -a -E -4 -u --exclude=.DS_Store --exclude=.TemporaryItems --exclude=.VolumeIcon.icns --exclude=tmp --exclude="Virtual Machines" --exclude="Virtual Machines.localized" --stats --progress /Volumes/"Macintosh HD"/Users/MyName/Documents/ /Volumes/iDisk/Documents/ >> $LOG

echo "Backup of Documents to iDisk complete..." >> $LOG
echo "" >> $LOG
echo `date` >> $LOG

exit 0
With the script saved and executable, simply run it with ./rsync_idisk.sh. The first run will take quite some time. (iDisk seems to only be giving up about 50Kbps these days, whereas it used to be 250Kbps or better). If you like, open another console and do a tail -f log_name and watch the files sync in real time. Additionally, opening up Finder and drilling in on the Documents folder under your iDisk will show "Syncing iDisk... Item x of x" in the bottom of the Finder window.

While this works well, it's still a manual process. The joy of rsync is that after the first (long) run, future iterations only sync over what's changed. This is where Lingon comes into play. Lingon allows you to schedule jobs to run at specific/recurring times via launchd (like cron on most other *nix systems). Download and install Lingon, then open a new item. I called mine com.apple.idisk.rsync. In the "What" section, enter the path to the script (ie: Macintosh HD/Users/MyName/scripts/rsync_idisk.sh), then set a time to run every so often. I chose every two hours.

For those who want a little closure, adding the following to the end of the script would email a copy of the log file to yourself, assuming you have a local mail server running.
cat $LOG | mail -s "Output of rsync to iDisk" user@domain.org
For the more advanced, a simple update to the script that would check for access to the internet could be used to only do the rsync if internet access is currently available.

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2008071710372562