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:
- 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$.
- 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).
- 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).
- 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
- 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.
- 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.