Enterprise Offsite Backup Since 2001

Scheduled Backups with the OSX rsync Command


Like most Unix distributions, OSX comes preinstalled with the rsync command.

With no additional software, your Mac OSX system is ready to begin nightly, bandwidth efficient backups.

Simply follow these short, step by step instructions and you will have an rsync backup configured in a few minutes.


Entering the Terminal and su'ing to root


Simply navigate to your Applications folder, then enter the Utilities folder, and double-click on the Terminal program.

Once the terminal windows is open, run this command:

sudo su root

After hitting Enter you will be shown a brief warning about using the super-user (root) account, and prompted for a password. Simply enter your regular admin password and hit Enter.

You can test the success of your change to the root user by running:


The output of the whoami command should be "root".

It is absolutely essential that every step of this HOWTO be run as root, the user you just became. If you open a new terminal window, you will need to re-run the "sudo su root" command above.


Setting up your public/private keypair


In your terminal, as root, run this command:

ssh-keygen -t rsa

After taking a few moments to generate the "public/private RSA key pair" you will be asked where to save the key. Simply hit ENTER to accept the default that you are given (which should be /var/root/.ssh/id_rsa, or something similar).

Now, upload the newly created public key to your rsync.net account with this command:

scp /var/root/.ssh/id_rsa.pub 1234@usw-s001.rsync.net:.ssh/authorized_keys

When you run this command, you will be asked to confirm the first connection - enter "yes", and when prompted for your password, enter the password that was given to you in your rsync.net welcome email.

Your RSA public key is now uploaded to your rsync.net filesystem, and any further logins over ssh will not require a password.

NOTE: you should insert your own username and your own rsync.net hostname in place of the "1234" and "usw-s001.rsync.net" in the command above.

Now that your key has been uploaded, you can test passwordless logins by simply re-running the above "scp" command. This time the command should complete without asking you for any input, and without asking you for your password.


Choosing What To Back Up


Now you need to decide what to back up. Generally, installed programs, like the ones in your Applications folder are not important to back up. Generally you are only interested in backing up your data, often times limited to your home directory inside of /Users. In this example, we will back up two directories - the /Users/JenniferMack folder, and the /var directory.

Here are what the two rsync commands would look like:

/usr/bin/rsync -avHS /Users/JenniferMack user@rsync.net:
/usr/bin/rsync -avHS /var user@rsync.net:

Some notes:

Your rsync.net username will NOT be "user", and the servername will not be just "rsync.net" - your actual command would look something like this:

/usr/bin/rsync -avHS /var 5221@usw-s005.rsync.net:

... so please see your welcome email to determine your username and servername.

Second, note the ':' character at the end of the command - that is REQUIRED. Also note that there is NO leading '/' character in the remote path. This means that if you want to place these backups into a subdirectory in your rsync.net account, the syntax would be:

/usr/bin/rsync -avHS /var 5221@usw-s005.rsync.net:subdir


Running the Backup


Your backup will run on a schedule and each night that it runs it will only send the data required to synchronize the remote copy with your local copy. This means that your daily backups will take very little time. However, the initial backup may take quite a while to complete.

For this reason, we highly recommend running your first backup manually, and only scheduling the job once the initial backup has completed.

To run your initial backup, simply enter the command, or commands, that you crafted in the previous step, above. Remember, you need to be logged in as "root" as we did in the beginning of this HOWTO.

The initial run of these commands may take minutes or hours, depending on the size of your dataset. You may also choose to add the --progress switch to the commands to see some reporting of progress and upload speed.

If your transfer is interrupted for any reason, don't worry. rsync always picks right back up where it left off, so all you need to do is re-run the exact same command again until it completes without errors.


Scheduling the Backup


There are several different ways (editing plists, creating applescripts and running out of iCal) to schedule these rsync commands to run nightly, but by far the simplest is to just put them into the existing 900.rsync.net script:

echo "/usr/bin/rsync -avHS /var 5221@usw-s005.rsync.net:" >> /etc/periodic/daily/900.rsync.net

... you would run an echo command like that for each of the rsync commands that you crafted. Note that the entire rsync command is enclosed in "quotes".


Testing the Backup


The easiest way to view the results of the backup is to simply view your rsync.net filesystem in the Finder.

There are detailed instructions available that show you how to open your rsync.net filesystem in a normal Finder window.


Restoring from the Backup


Depending on whether you wish to restore one, or just a few files or directories, or if you want to do a full restore of your entire backup, you will choose different methods for the restore.

If you simply want to restore one file, or just a few files, just open your rsync.net filesystem as window in the Finder and drag and drop the files you need.

However, if you wish to do a full restore of your rsync.net filesystem, just reverse the source and destination paths in your rsync command, effectively running the backup command in reverse.

For example, if your rsync command looks like this:

/usr/bin/rsync -avHS /var 5221@usw-s005.rsync.net:

simply open a terminal window, 'sudo su root' (see above) and then create a temporary directory to restore to:

mkdir /restore

Then run an rsync command like this:

/usr/bin/rsync -avHS 5221@usw-s005.rsync.net:var /restore

As always, inserting your actual username and the hostname you have been assigned into that command. Remember, if the transfer is interrupted or ends in an error, simply re-run the rsync command again. rsync always picks up right where it left off, so you do not need to worry about an interrupted transfer. Just keep re-running the command until it completes successfully.


Please see the entire Macintosh Integration Guide for details of other access methods.


Back to Mac Product Page