rsync 101 for Linux, Unix and BSD

rsync is a snap to use. It's easily the best backup utility out there. You can also use it in place of other copy tools like cp, rcp, and mv.

To get started with rsync:

  1. Create a directory for your keys and scripts.
  2. Create an SSH key pair with ssh-keygen.
  3. Identify the data you want to backup by configuring an rsync backup.
  4. Upload the initial backup data to your EVBackup account.

Step One: Create the Backup Directory

To begin, open a terminal (Gnome-Terminal, Xterm, Kterm, etc.) and create a directory for your backup files. We recommend /backup.

sudo mkdir /backup

Step Two: Generating an SSH Key Pair with ssh-keygen

Notes:
  • Each of the following commands are entered as a single line.
  • You'll want to run all of the commands here as the 'super-user' (using sudo), so that you have full access to all the files on your machine.
1. Create an SSH key pair with ssh-keygen
sudo ssh-keygen -f /backup/ssh_key -t rsa -N ''
Note the command ends with two single quote characters.
  • Why do I need an SSH keypair? »
  • « OK. Hide this

An SSH key pair allows you to securely login to your backup server without entering a password each time.

2. Upload and activate the public key to your EVBackup account
sudo rsync -e ssh /backup/ssh_key.pub user@user.evbackup.com:ssh_keys/key1.pub
ssh user@user.evbackup.com addkeys
Show Me
Successful SSH key pair generation in Linux

Successful SSH key pair generation in Linux

  • Notes about uploading »
  • « OK. Hide this
  • Substitute user with your EVBackup account name.
  • When you enter this command, you might see a message indicating that your computer is doesn't recognize the server. Just enter yes when prompted and you'll never be bothered again.
  • You'll be asked to enter the password for your EVBackup account. Once the key is uploaded and activated, this won't be necessary again.
  • If Terminal simply returns (looking as though nothing has happened), then you have successfully uploaded your key!
3. Test that you can login without a password
sudo ssh -i /backup/ssh_key user@user.evbackup.com
  • How do I know if it worked? »
  • « OK. Hide this

If you were successful, then something very similar to the following will appear in Terminal:

Last login: Thu Jul 15 16:16:44 2010 from c-28-26-13-101.
Copyright (c) 1983, 1986, 1988, 1990, 1991, 1993, 1994
The Regents of the University of California. All rights reserved.

FreeBSD 6.4-STABLE (EXAVAULT) #1:
[your-account@quark ~]$

Step Three: Configuring a Backup Session

Once you have your SSH key pair generated, uploaded and tested, the next step is to run a simulation of the backup command. rsync provides a really neat argument to help you do this: --dry-run. The --dry-run argument will help you sort out the options you'll be using in the backup script that you'll be automating later.

A basic rsync command with --dry-run command looks like this (all on one line):

sudo rsync -avz --dry-run -e "ssh -i /backup/ssh_key" /local/folder user@user.evbackup.com:remote-folder

You might have noticed that you are running the command as the "super-user." While this is optional depending on your system, we suggest that you run the command with root privileges so that you can be sure everything is backed up.

Example rsync Command

User bobsmith wants to backup the local directory /home. He wants to put the backed up files in the home-data directory on the server. Here is what his rsync command would look like (again, all on one line):

sudo rsync -avz --dry-run -e "ssh -i /backup/ssh_key" /home bobsmith@bobsmith.evbackup.com:home-data

If you have any questions, concerns or problems, don't beat your head on the desk: .

Step Four: Running the Initial Backup

Once you've sorted out the the rsync command and its arguments, then it's time to run the initial backup. All that you'll need to do is remove the --dry-run argument from the command you ran previously.

Show Me
Logging into your EVBackup account with EVFTP: the ExaVault Secure FTP Java web client

Logging into your EVBackup account with EVFTP: the ExaVault Secure FTP Java web client

We recommend that you run your first full backup from the command line. That way, if something goes awry, you'll be able to catch it right away.

Once the command has completed, you'll want to double-check what was uploaded. To verify, you can use any desktop S/FTP client, or you can use our Secure FTP web client.

Next Steps

Congratulations! The few minutes you've just spent covers what you need to know to backup your data. Moving on from here:

  • There's more to rsync arguments than -avz »
  • rsync is best used when it is scripted and automated with cron »
  • If you have any questions, concerns or problems, don't get frustrated: .

Successful SSH key pair generation in Linux

Uploading your public key in Linux

Verifying your uploaded data with EVFTP: ExaVault's Secure FTP web client

A Grsync simulation is a "dry-run" in rsync parlance.