Backing Up a Hard Disk to Another in OS X
Rsync is a utility you run by typing commands in Terminal, and it was designed exactly for doing that one job - it looks at one source folder and all its subfolders, finds all the files in there, then look at the destination folder and copies over only what needs to be copied, making it very fast. It’s got a ton of options, but all you need is to find that one command that works for you and use it again and again as needed.
Syncing two hard disks with rsync
Let’s say you have two hard disks, “ORIGINAL” and “BACKUP DISK”. For the first transfer, you may as well copy manually all the files from ORIGINAL to BACKUP DISK by dragging them, rsync doesn’t do it any better or faster. From then on, whenever you want to backup the disk (every day, every week, whatever) you can start with this command:
The command breaks down as follows:
- calls the utility
- turns on archive mode, which basically ensures all subfolders, permissions and files parameters are copied
- if there wasn’t already a dash for -a, this would be -S. This compacts sparse files for efficiency
- this ensures that any files in the destination that were not there in the source will be deleted
- the original
- /Volumes/BACKUP\ DISK
- the destination. Note that I have typed a backslash before the space after BACKUP, BACKUP\ DISK - that tells Terminal that the word isn’t finish yet, and the space is part of the word
If you want to skip some files or folders, you can add their paths to the command. Note that you have one
--exclude options for every patter you want to exclude. Also note the
* wildcards, which basically means “anything here”
If you have a lot of excludes it makes sense to put the list in a file, and then tell rsync to use that. It makes sense even if you only have a few files, because then you can easily add and remove things from there without having to change the command - as you start playing with rsync you soon find out there are a few system folders you don’t want to backup, like Spotlight indices and so on.
and .rsync_exclude_list can have all the patterns in there, one per line. The file can be named whatever you want - I have put it in the home folder (that’s what ~/ at the beginning means) and used a name that starts with a dot because it works well with my dotfiles.
1 2 3 4 5
Making things easier with an alias
Instead of trying to remember that command every time you need to back up, you can create an alias, i.e. a shortcut to the command. Depending on your setup, you can just add it to your bash_profile file. If you use dotfiles, just add it to the .alias file and then run bootstrap.sh again.
1 2 3 4 5 6 7 8 9 10 11 12