Back up key files via rsync and ssh
Jul 01, '08 07:30:00AM
Contributed by: Pat_Gilmour
If you find online backup solutions expensive and heavy on your system, you might be pleased to hear there is a cheap, easy way to create a mirror backup your Mac (or other UNIX variant) to a secure online server using a program named rsync. And as of Mac OS X Leopard, rsync will even transfer metadata associated with your files like tags and comments.
This method does not allow you to roll back to previous dated backups like certain backup solutions do (Time Machine, for example). What it does is create a mirrored backup of your Mac on a remote server, so it's best used in conjunction with a local hard drive-based incremental backup solution. Still, if the house burns down, your files will be safe and once you've done the initial backup, rsync is very efficient at keeping your remote backup mirrored with your disk.
In this example, we're going to backup the currently logged-in user's Documents folder.
What you'll need:
- rsync running on your Mac (it's there on 10.4 and 10.5)
- An Internet Service Provider (ISP) who allows you to connect via SSH. Examples: 1 2 3.
Procedure:
- Set up the remote server
- You're going to need shell access to your server. If you don't already have it, and you use cPanel to administer your server, then there is often a 'Request Shell Access/Remote Login' option. If there isn't, contact your ISP directly.
- With shell access set up, create a folder that is outside of the scope of your webserver. You could use FTP to do this, if you prefer. For example, set up a folder called private_BKP at the root level of your server, and put a folder in there called Mac_One_BKP. The path is then /home/private_BKP/Mac_One_BKP, and it's in there that we're going to put the contents of our Documents folder.
- Set up your Mac
Some notes:
- If you want to check out what the -avz -e stuff does, take a look at the rsync man page.
- Your first backup can take hours, if not days (don't worry -- it'll be much faster the second time around, thanks to rsync's ability to transfer only the parts of files that have changed. Take a break from the computer and have a buy a real copy of this instead.
Deletes and Excludes:
One you've backed up your Mac's Documents folder using the method above, there will come a time when you will want to run the script again -- like when you add new content to your folder! However, you many also have deleted some content from your Documents folder.
- To have rsync delete files on the remote server that are no longer on your machine, add --delete to the command: rsync -avz --delete -e ssh ...etc.
- To have rsync exclude the transfer of certain files to the remote server , add --exclude='myFileName' to the command: rsync -avz --delete --exclude='myFileName' -e ssh ....etc.. You can add multiple --exclude statements, or add a list via an --exclude_from file (see the manual).
[robg adds: I use a variation on this technique (combined with password-free SSH connections and cron) to create a redundant offsite backup for certain critical data. I also use it to back up sensitive documents (financials, images of passports, etc.) after first writing them to an encrypted disk image. Some day, I'll write it all up in detail for posting...]
Comments (12)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20080701060927183