Author: Matthew Phillips <firstname.lastname@example.org>
Click here for Belorussian translation (thankyou to Marina)
Click here for German translation (thankyou to Marina Dmitrieva)
Click here for Portuguese translation (thankyou to Diana Gomes from Travel-Ticker.com)
Click here for Indonesion translation (thankyou to Jordan Silaen from ChameleonJohn.com)
This document describes how to setup a system for automatically
backing up a Mac (OS X 10.2 or later) to an external drive using the
rsync utility. This applies to any kind
of external drive including FireWire, USB and network drives. It does
not apply to CD-R or DVD-R media. It also does not apply if you want
to implement an incremental backup system.
If you've already set up the external drive you'll be backing up to, you can skip to the next section.
To create a partition on the disk drive, connect the drive and wait
for Mac OS X to offer to run
Disk Utility to initialise
The details of how to use
Disk Utility are beyond this
HOWTO and are well covered by the Mac's online help: just run help and
search for "Partitioning a hard disk".
Below is a screenshot of a partitioned drive in
Utility. In this example I've chosen to create two partitions,
Data, one for backing up the
core system and user accounts, and one for large data files such as
music and movies. These appear as drives on the desktop and as
folders in the
/Volumes folder. If you're not sure what
you want, just create a single
When you've created the partitions, you'll see them appear as empty drives in the Finder and on the Desktop.
For some reason Mac OS turns off permissions management for new
partitions by default, which will result in "chown" errors from
rsync if not rectified.
To enable permissions, select the partition in on the Desktop and show its information page by hitting Command+I. Expand the "Ownership & Permissions" section and make sure that "Ignore ownership on this volume" is not checked as shown below.
Note to users of Mac OS X 10.4 and later: Apple extended the
rsync shipped with Mac OS X 10.4 to directly support
resource forks, so if you don't want to use the GUI provided
rsyncx, you can skip the software installation
and go to the Advanced section.
You only need one piece of software to backup your Mac that's not
already part of Mac OS:
rsyncx. Although Mac OS X
comes packaged with bog-standard
rsyncx is needed in order to
preserve Mac-specific resource forks. While Apple is no longer
recommending applications use resource forks, some classic Mac apps
still rely on them.
rsyncx also comes with a graphical
front end that can make it much easier to get started.
You can download rsyncx from VersionTracker (version 2.1 was current when this document was last updated). More information about rsyncx and its developer, Kevin Boyd, is available here.
rsyncx, simply extract
rsyncx archive and find the installer package inside
it which will be called something like
RsyncX_v2.1.pkg. Double-clicking this will install the
rsyncx GUI and the command line program
/usr/local/bin/rsync (it will not delete the built-in
If you just want to create a backup of your entire Mac hard disk (and optionally make it bootable), then this section is for you. If you want to back up only some of the drive or use multiple partitions, see the Advanced section.
The simplest way to use
rsyncx is to use the graphical
front end: just select
RsyncX from the Applications
folder. Below is a screenshot of how to set up the application to back
up the entire Mac hard drive to the external drives'
partition and make it bootable.
rsyncxto delete any files on the external drive that have been deleted since the last backup. Coupled with Archive mode (which preserves all file modification times, ownerships, etc), this will produce an exact copy of the drive.
Note: this option will also mean that any files you may have accidentally deleted will also be deleted from the backup too, making it possible to lose a file permanently if you don't notice its deletion in time.
The simplest way to do this is to create a
special "Backup" user and, when you do a backup, log off from your
account and log back in as Backup to run the backup process. This
will result in your home folder also being encrypted in the backup
(it appears as a single, large, encrypted
file). The one downside of doing it this way is that you'll also
need to grant the backup user admin
rights as described in the advanced
In fact running the backup while logged in as another user can be a good idea even if you're not using FileVault, since it reduces the likelihood that processes will modify files while they're being copied.
Obviously the best way to test whether the backup will work in an
emergency is to boot from it. To do this, restart the Mac and hold the
Option key down while it boots. You will be presented with
a screen that allows you to choose the boot drive. If you can
successfully boot and login from the external drive, then you can be
fairly confident of being able to recover from a disaster by simply
booting from backup and using
rsync in reverse to restore the
If you want to do more funky things like backup different parts of
the drive to different partitions, exclude certain files from backup
or any other sort of customised stuff, then you may want to write some
scripts to drive
rsync from the command line. This
section contains some tips on doing this. It assumes you know
Unix-type stuff like
As of 10.4 Apple's shipping
rsync supports resource
forks by specifying the
flag on the command line. The example script allows switching to the
OS X built-in
rsync by swapping commented definition
RSYNC at the top of the script.
Below is the text of a script called
can be used to backup all of the main hard disk, with a specified set
of exceptions listed in a file called
#!/bin/sh # To use Apple's rsync switch commented lines below # To use rsyncx: RSYNC=/usr/local/bin/rsync --eahfs --showtogo # To use built-in rsync (OS X 10.4 and later): # RSYNC=/usr/bin/rsync -E # sudo runs the backup as root # --eahfs enables HFS+ mode # -a turns on archive mode (recursive copy + retain attributes) # -x don't cross device boundaries (ignore mounted volumes) # -S handle sparse files efficiently # --showtogo shows the number of files left to process # --delete deletes any files that have been deleted locally # $* expands to any extra command line options you may give sudo $RSYNC -a -x -S --delete \ --exclude-from backup_excludes.txt $* / /Volumes/OSX/ # make the backup bootable - comment this out if needed sudo bless -folder /Volumes/OSX/System/Library/CoreServices
You can copy and paste this text into a new new and then execute
chmod u+x backup.sh to make it
into an executable command.
backup_excludes.txt contains a list of files
to exclude. An example is shown below — this list can be used as
the default set of directories that should not be backed up which you
can add to as needed.
/tmp/* /Network/* /cores/* */.Trash /afs/* /automount/* /private/tmp/* /private/var/run/* /private/var/spool/postfix/* /private/var/vm/* /Previous Systems.localized .Spotlight-*/
-noption to test it. In this mode
rsyncwill run through the motions but not make any actual changes. Adding
rsyncto print out all the files it will be changing.
blesscommands as root. To do this you need to run "
sudo visudo" as an admin user and add the lines highlighted in green to make it look like the example below.
# sudoers file. # # This file MUST be edited with the 'visudo' command as root. # # See the sudoers man page for the details on how to write a sudoers file. # # Host alias specification # User alias specification # Cmnd alias specification Cmnd_Alias BACKUP = /usr/bin/rsync, /usr/local/bin/rsync, /usr/sbin/bless # Defaults specification # User privilege specification root ALL=(ALL) ALL %admin ALL=(ALL) ALL backup ALL=BACKUP
rsyncxhas the same name as the built-in
rsynccarries the danger that you may not be using the right one. The standard rsync that comes with Mac OS X is in
/usr/local/binis usually used before
/usr/bin, the extended rsync should be what you get. If you want to be sure, run "
rsync 2>&1 | head -n 3" and if you see "HFS+ filesystem support for OSX (C)2004 Kevin A. Boyd" as the last line, then you're using