rsync backups

I'd argue that at least as important as anything you do on a computer is being able to back it up. I've lost quite a lot of work to bit rot, a mistyped rm command or two, and a spilled beverage or two. Those are mistakes that will probably be repeated more than once, so it's time to plan for them.

There are a lot of ways of going about this, with varying levels of work required. I'm not so much afraid of the work, but I only want to do this once. I have an Apple laptop, XP desktop, and one of those NSLU2 slugs, plus some stuff on a remote unix server I wouldn't mind pulling into this.

The solution I'm going with is rsync, a *nix command line utility. Basically, it copies files from place, and either place can be on the local machine or on a remote box. If a file hasn't changed since the last copy, it won't re-copy it. It can copy the files to a remote box across an ssh connection, and to run rsync automatically, it's useful to automatically log into ssh without a password.

rsync is preinstalled on OS/X, "apt-get install rsync" can put it on the slug, and a quick cygwin install puts it on the XP desktop. (cygwin should probably get it's own post. It gives you a linux shell under windows, and is an awesome tool to have around.) If you're using cygwin, you'll probably also want the cygwin UTF-8 layer, which allows non-ASCII characters in filenames without causing rsync grief.

The rsync project page's examples list comes in really handy, especially 'backup to spare disk'. If you're using a FAT filesystem - Windows - the timestamps won't ever match up, it seems, so you'll want to use the --size-only option; if you let rsync decide if something has been updated based on timestamp, FAT filesystems will cause rsync to always copy every file.

Inside of cygwin, I'm using the following options, spelled out for clarity. I don't always use them all, obviously, but the idea's there.
--verbose --recursive --times --links --delete --delete-after --size-only --dry-run --exclude
--verbose: list every file copied and deleted
--times: preserve the modification times
--links: copy symbolic links as symbolic links
--delete: delete extra files from destination when it finds them
--delete-after: delete extra files from destination after it finishes copying successfully
--size-only: only compare by size, not by checksum or by timestamp
--dry-run: do a dry run, and do not change anything on the destination filesystem
--exclude: exclude a file, for example, Apple's .DS_Store files

No comments: