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:
- Create a directory for your keys and scripts.
- Create an SSH key pair with ssh-keygen.
- Identify the data you want to back up by configuring an rsync backup.
- 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
sudo mkdir /backup
Step Two: Generating an SSH Key Pair with ssh-keygenNotes:
- 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
Note the command ends with two single quote characters.
sudo ssh-keygen -f /backup/ssh_key -t rsa -N ''
- Why do I need an SSH keypair? »
- « OK. Hide this
An SSH key pair allows you to securely log in 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 firstname.lastname@example.org:ssh_keys/key1.pub
ssh email@example.com addkeysShow Me
- Notes about uploading »
- « OK. Hide this
userwith your EVBackup account name.
- When you enter this command, you might see a message indicating that your computer 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 log in without a password
sudo ssh -i /backup/ssh_key firstname.lastname@example.org
- 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:
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:
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 email@example.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
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 firstname.lastname@example.org:home-data
If you have any questions, concerns or problems, don't beat your head on the desk: email@example.com .
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.
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.
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: firstname.lastname@example.org .