rsync backups on OS X

OS X El Capitan (10.11.4) comes with an outdated version of rsync (2.6.9) due to licensing issues. It's easy to build the latest rsync from source. I followed this guide, adapted for rsync 3.1.2.

cd ~/Desktop
curl -O https://download.samba.org/pub/rsync/src/rsync-3.1.2.tar.gz
curl -O https://download.samba.org/pub/rsync/src/rsync-patches-3.1.2.tar.gz
tar -xvf rsync-3.1.2.tar.gz 
tar -xvf rsync-patches-3.1.2.tar.gz
cd rsync-3.1.2
patch -p1 < patches/fileflags.diff
patch -p1 < patches/crtimes.diff
patch -p1 < patches/hfs-compression.diff
./configure
make

Once rsync is built, you can optionally run sudo make install to put the binary in /usr/local/bin.

Patches for OS X

fileflags preserves the st_flags stat() field (see sys/stat.h). Adds --fileflags option, as well as some --force-* options.

crtimes preserve create times. Adds --crtimes (-N) option.

hfs-compression adds support for HFS+ compression. Adds --hfs-compression and --protect-decmpfs options. A diff of the --help output between standard and patched versions of rsync.

Testing your rsync arguments

Backup Bouncer is useful for verifying your rsync arguments. I used the fork by mbaltaks, which seemed to have more recent fixes and updates. The test files bbouncer creates utilize basic permissions, timestamps, symlinks, symlink ownership, hardlinks, resource forks, finder flags, finder locks, create dates, BSD flags, extended attributes, HFS compression, and ACLs. You can decide which you want to preserve and experiment with different rsync options until you're satisfied.

./bbouncer create-vol mysrc
./bbouncer create-vol mydst
./bbouncer create /Volumes/mysrc/
rysnc --your-options /Volumes/mysrc/ /Volumes/mydst/
./bbouncer verify -d /Volumes/mysrc/ /Volumes/mydst/

A simple rm -rf may not be able to delete the test files bbouncer creates. Use the clean command instead.

./bbouncer clean /Volumes/mydst

rsync options

Here's what I currently use to backup my files to another HFS+ disk. These arguments pass all of the bbouncer tests, though that's not required depending on your backup strategy.

rsync -aNHAx --hfs-compression --force-change --delete
  • a archive mode (--archive), equivalent to passing -rlptgoD
  • N preserve create times (--crtimes)
  • H preserve hard links (--hard-links)
  • A preserve ACLs (--acls)
  • x don't cross filesystem boundaries (--one-file-system)
  • hfs-compression transfer com.apple.decmpfs xattr (compressed file) instead of decompressed file, if supported
  • protect-decmpfs transfer decmpfs xattr instead of decompressed file regardless of support at destination
  • force-change disables user- and system-immutable flags on files being updated/deleted in destination. If omitted, rsync may fail to set times on some files depending on their flags.
  • delete remove extraneous files from destination

Note that hfs-compression and protect-decmpfs imply the following options:

  • X preserve extended attributes (--xattrs)
  • fileflags update destination files with same file-flags (see chflags command) as source

This is equivalent to the command above, but includes implied options for clarity:

rsync -aNHAXx --fileflags --hfs-compression --force-change --delete