How to Backup Your Mac Using Rsync
Please also take a look at Macinstruct's other backup article: Mac Backup Basics.
Do you manually back up your Mac to an external hard drive? Do you know it is very easy to make automatic backups without spending any time or money on fancy applications? We'll show you how to do it!
Rsync is a wonderful backup tool that packs a powerful punch and is easy to set up. This free application is included with nearly all Unix operating systems -- including Mac OS X. It can be accessed directly by using the Terminal, but we're going to access it here by saving a very simple bash script.
We'll assume you have an external USB drive called backup, and you want to back up your home folder. Launch TextEdit. (It's located in your Applications folder.) From the Format menu, select "Make Plain Text." Paste the following command into the TextEdit window:
rsync -aE --delete ~ "/Volumes/backup/"
(Obviously, you can change "backup" to the name of your USB drive.)
You're probably looking at that command and thinking, What the heck is that?! Rsync is the name of the program we'll be running. The "-aE" tells rsync to preserve permissions and to copy metadata (resource forks.) The "--delete" tells rsync to make the backup copy exactly the same as the source. If you do not include the "--delete" option, anything that was deleted or moved will show up in your backup. The "~" is the bash shell's shorthand for the path to the currently logged-in user's home directory. The "/Volumes/backup/" is the path to the destination or backup copy of where the home folder will be cloned. Change the "/backup/" to the name of your external drive.
Now, let's save this file in a format that will allow you to double click it to start a backup. From the File menu, select Save As. Name the file backup.command and uncheck the If no extension is provided, use .txt checkbox. Save the file to your Documents folder. The .command extension allows you to double click on the file and run it in the Terminal application.
What you have created is a very basic shell script, but first we need to make it executable. Launch the Terminal application. It's located in Applications > Utilities. Type in the following command:
chmod u+x ~/Documents/backup.command
This chmod command is used to change permissions of files and directories. The "u+x" tells chmod to allow the owner to execute the item. For a nice explanation of the chmod command, check out this link:
Don't Stop There: Automate It With iCal!
You can schedule backups to run at a desired date and time using iCal. Launch iCal. (It's located in your Applications folder.) From the File menu, select New Event.
Enter the date and time you want the backup to start. You can also set a repeat interval. Under the Alarm option, select "Open File," and under that it will change to iCal. Click on it and select "Other." Select the backup.command script from the Documents folder.
When it comes time to perform the back up, iCal will launch the Terminal application to run your backup bash script.
If iCal Doesn't Tickle Your Fancy, Use Cron
There are other methods of schedule the backup. One of them is to set up a crontab. Cron is an old (and free) Unix program used for scheduling jobs. The advantage of using cron is that it will run the script in the background and never open the terminal application. Apple has developed a more sophisticated replacement for cron named launchd. For now, I will show you the crontab method and leave launchd for another tutorial.
Launch the Terminal application. (It's located in Application > Utilities.) Type the following command and hit return:
This will put you into the vi editor. Hit the i key, and type in the following command:
30 3 * * * sh ~/Documents/backup.command
Hit the ESC key, and then hold the shift key down while hitting the z key twice to save the crontab entry.
This tells your Mac to run the script everyday at 3:30 AM. Cron uses military time, so if you wanted to run the script at 6:30 PM, you would type "30 18 * * *". If you wanted it to run every Tuesday at 10 PM, you would type "00 22 * * 2". You can learn more about cron here: http://www.adminschoice.com/docs/crontab.htm
One Other Option
We can't recommend this option, but we did want you to know about RsyncX -- a graphical version of rsync for Mac OS X.
Why can't we recommend it? The reviews are mixed, to say the least. Some say it "works great!", and others say it "crashed my Mac." If you decide to use this free tool, please use it at your own risk!
Meet Your Macinstructor
David Miller has been supporting Macs since the mid '90s. He has worked for large ISPs and DOE sites, and he's currently working as a Unix systems administrator. He has graciously allowed Macinstruct to reprint this tutorial, which was originally written for his personal website: http://www.sdmachelp.com/