Automatically sync your documents to iDisk with rsync

by Mitch on 14/01/2009

One of the coolest things about owning a Mac is using the powerful underlying Linux tools available in a termal. If you’re new to Mac and/or Linux, I strongly recommend if you want to get the most out of your operating system you spend some time learning what is under the hood.

Recently I’ve done some searching around for some ideas on utilizing my iDisk storage a little more and unearthed the usage of rsync to automatically synchronize between my Documents folder and my iDisk/Documents folder.

Disclaimer: You can do this by automatically syncing using the GUI tools, however this gives little control over exactly what is synchronized, so I have written this tutorial.

The bash script:

#!/bin/sh

export LOG=/Volumes/"Macintosh HD"/Users/USERNAME/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=.localized --exclude="Virtual Machines.localized" --stats --progress /Volumes/"Macintosh HD"/Users/USERNAME/Documents/ /Volumes/iDisk/Documents/ >> $LOG echo "Backup of Documents to iDisk complete..." >> $LOG
echo "" >> $LOG echo `date` >> $LOG exit 0

Now pull that script apart a little and customise it to your needs:

  1. Replace both instances of USERNAME (highlighted so yo can find it) with your username. This is not necessarily the sign-in name that you use, it is the shortened version which will appear in your terminal when you open it. For instance, when I open a terminal it says mitch-malones-macbook:~ mitch$.
  2. Decide what you don’t want and –exclude it. I would recommend excluding everything except those folders you want explicitly saved. My exclude list is quite long, but it ensures that I don’t synchronise large groups of images that I really just don’t need (i.e. my online comic collection).
  3. Save the script. I would recommend saving it somewhere like /Volumes/”Macintosh HD”/Users/USERNAME/docsync.sh or similar. Again, replace the USERNAME with your username (duh).
  4. Go to the directory where you just saved the script and make the script executable. This can be done using the chmod +x command, e.g. chmod +x docsync.sh
  5. Run the script, do this by typing sh docsync.sh. This will take a while to run as it is the first time these documents have been synced. The script won’t display anything during this time because all of the output is going to a log file, so just be patient and let it run.
  6. Lastly, you’ll want to automate this by using a tool called Lingon. To make it easy I have taken a screenshot of my Lingon setup and posted it here. Just start a new agent and put in similar to what I have put in, once again replacing USERNAME and ensuring that the file references are correct.

There you have it, your own customized synchronization, running every 2 hours to ensure all of your important documents are backed up.

No comments yet.

  1. 7/05/2009Matt says:

    How do i remove this process?

  2. 14/02/2011nevertell says:

    Is there a way to sync a folder on Ubuntu computer to my online iDisk?

  3. 22/02/2011Mitch says:

    Actually, there is. iDisk is just a WebDAV share.

    Firstly: sudo apt-get install davfs2
    This will install the required utility to mount webdav file systems.

    Then open up /etc/davfs2/secrets and put in an entry like this:
    http://idisk.mac.com/username USERNAME PASSWORD

    Then edit /etc/fstab and add: http://idisk.mac.com/username /mnt/idisk davfs user 0 0

    Then you will automatically mount the iDisk when you boot in.

    Enjoy!

  4. 19/05/2011Mark Dallimore says:

    Quick question. Once this script has run once, does it just overwrite new data in to the iDisk location or does it copy it all over again?

    Thanks,

    Mark