Secure Offsite Backup

Powerful, Scheduled Backups with the OSX rsync Command

 

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

With no additional software needed, your Mac OSX system is ready to immediately begin powerful, bandwidth-efficient backups on whatever schedule you choose.

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

 

Entering the Terminal and su'ing to root

 

There is a GUI front-end to rsync, however if you are looking for a simple, standard rsync backup setup, you need to enter the Terminal program.

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:

whoami

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 the /Users/JenniferMack Folder.

From the terminal, still logged in as root, run this command:

vi /var/root/rsyncnet.sh

and hit ENTER. You will now be inside the 'vi' editor. Every keypress counts, so only type exactly:

- a single lowercase "i"

- this string:

/usr/bin/rsync -av /Users/JenniferMack 1234@usw-s001.rsync.net:

- press "ESC" once

- type a single ":" (a colon, using the shift key)

- type wq

- hit enter

Remember - your home directory is not JenniferMack, your rsync.net username is not 1234, and you may not be on usw-s001.rsync.net - so check your welcome email and enter in the correct values for the string above.

Now, make your script executable by running this command:

chmod +x /var/root/rsyncnet.sh

 

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 this command into the terminal:

/var/root/rsyncnet.sh

and hit ENTER. You will see a message "Building file list..." and eventually you will see the filenames of the files in your directory scrolling by - perhaps quite rapidly.

When the rsync backup completes successfully (which may take minutes, or may take hours, depending on your network connection and how many files you have) you will see a final status message that looks something like:

sent 3427 bytes  received 42 bytes  770.89 bytes/sec
total size is 3321  speedup is 0.96

If you see an error, or a connection failure, or anything other than that final message, don't panic - simply re-run the exact same command from above. rsync picks up right where it left off, so if an intermittent network connection or some other difficulty interrupts this inital backup, just re-run the command until it finishes properly.

 

Scheduling the Backup

 

After you have run your script once, to completion, you can schedule it using launchd to run at the time and interval of your choice.

In the terminal window, as root, run these commands:

cd /Library/LaunchAgents

curl -O http://www.rsync.net/resources/examples/rsyncnet.daily.plist

launchctl load rsyncnet.daily.plist

The job will now be set to run every night at 2am. If you would like to run it at a different time, you may edit /Library/LaunchAgents/rsyncnet.daily.plist and change:

<key>Hour</key>
<integer>2</integer>

to a different number.

 

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 in /var/root/rsyncnet.sh looks like this:

/usr/bin/rsync -av /Users/JenniferMack 1234@usw-s001.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 -av 1234@usw-s001.rsync.net: /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