Implementing Redundant Backups with rsnapshot

  • Do you need full backups more than once per month?
  • Do you want redundant (more than one) copy of backed up data?
  • Do you want to avoid having several scripts to backup multiple locations?
  • DDo you need to back up several servers into a centralized location?

If you answered yes to any of those questions, then rsnapshot is the tool for you. With rsnapshot, this is what your backup plan will look like:

  1. rsnapshot will make hard-link snapshots of your folders and files.
  2. rsync will backup the snapshot directory from the previous step to your EVBackup account.

What this means to you is speedy and redundant recovery:

  • If you need to restore a file quickly, you have it locally.
  • Your EVBackup account becomes your fall-back (redundant) backup site.

rsnapshot Installation

To check whether you have rsnapshot installed on your *nix machine, open up a terminal and enter the following command

whereis rsnapshot

  • If you see a path returned, you are good to go!
  • If you see rsnapshot: , then you need to get it installed.
  • How do I install rsnapshot? »
  • « Gotcha. Hide this stuff!

Installing rsnapshot may be as simple as using your package management system. Depending on your flavor of *nix, enter one of the following into a terminal:

Ubuntu
sudo apt-get install rsnapshot
CentOS / Fedora / RHEL
sudo yum install rsnapshot
OpenSuSE / SLES
sudo zypper install rsnapshot
Other Flavors of *nix
The rsnapshot download page has instructions and links to pre-built packages for just about every distribution imaginable.
@#?! It Doesn't Work!
Nobody was born knowing how to fly a plane, yet we still have pilots. Just send us an email — we're here to help: support@evbackup.com

Step One: Edit /etc/rsnapshot.conf

Once you are assured that rsnapshot is installed, you'll want to edit rsnapshot.conf. It's kept in the /etc, so you'll need to be in super-user (sudo) mode to edit it. The following is a list of edits that you'll need to make.

Main Program Settings

snapshot_root

This is the local path to where rsnapshot will place it's snapshots. You'll need to use a trailing slash ( "/" ) for all directory paths.

  • Why can't this be my EVBackup account? »
  • « OK. Hide this

If you wondered about this, you are in good company: so did we. This is just how rsnapshot works:

"Rsnapshot does not support a remote snapshot root via SSH."

However, this isn't necessarily a bad thing. Consider the following:

  • A local backup is always the fastest to restore.
  • The snapshots will be synced with your EVBackup account. That means redundancy — which is a requirement for every disaster recovery plan.
  • rsnapshot does support taking snapshots of remote servers. Therefore, you can use it as a centralized backup management tool for several servers:
    • Critical data from each and every one of servers (even on servers outside of your network) would be backed up to snapshot_root.
    • snapshot_root is synchronized with your EVBackup account.
  • ... all configured within one configuration file.

We suggest: /backup/snapshots/

Backup Intervals

Backup Intervals controls two things:

  1. Controls the directory name of the snapshot in snapshot_root.
  2. Sets a argument for running the rsnapshot command.
We suggest: Use only daily, weekly and monthly
  • Show me »
  • « Hide this

# interval   hourly   6
interval     daily    7
interval     weekly   4
interval     monthly  3

Backup Points

Backup points are how you direct rsnapshot what you want to to take snapshots of. You can have as many snapshot directives as you like. Each directive has three tab separated fields:

[instruction]   [path to backup target]/   [snapshot_root subdirectory name]/

  • Show me examples »
  • « OK. Hide this

For example, you might want to backup:

  • The contents of /var/www/ (your web pages)
  • The contents of /etc/ (your configuration files)
  • A database dump from your e-commerce database
  • The contents of a folder on another server

backup   /var/www/   localhost/
backup   /etc/       localhost/
backup_script   /backup/ecommerce-mysqldump.sh   localhost/ecommerce-mysqldb/
backup   user@my-ssh-enabled-server.com:/path/   my-ssh-enabled-server/path/

Note: remember the trailing slash for directories! 

  • Can you explain further? »
  • « Ah ...now I get it! Hide this
Instruction
Instruction may be one of two values:
backup
Indicates a backup point.
backup_script
Indicates that the target to backup must be accessed by a script. This is commonly done when you want to backup a database, and you need to run a script to get the database to create a backup file.
The thing to remember with backup_script is that the output of the script must be placed in the same directory as the script. For further details, consult the rsnapshot HOWTO page for backup_script.
Path to Backup Target
This is simply full path to the files or folder to snapshot with a backup directive, or the full path to the script to run with a backup_script directive.
Note that if you use backup_script, we suggest that you place the scripts in /backup/scripts/
You can also enter in a URI to another server — provided that SSH is running on the other server. An example is shown above, and further details can be found on the rsnapshot HOWTO page for backup.
snapshot_root Subdirectory Name
This is a relative path to snapshot_root. In the examples above, the full path to the snapshot files would be:

/backup/snapshots/localhost/var/www/
/backup/snapshots/localhost/etc/
/backup/snapshots/my-ssh-enabled-server/path/

Executing rsnapshot test-config

Once you are ready to test your rsnapshot configuration, enter the following into a terminal:

rsnapshot test-config

Of course, if you hit a snag, don't get frustrated. Contact us — we're here to help: support@evbackup.com .

Step Two: Set Up the rsync Script to Your EVBackup Account

Note: If you would like a more detailed guide to setting up an rsync script, then check out:

Essentially, the rsync script that you create needs only to back up the contents of snapshot_root. Here are the steps / commands to creating the rsync script to back up your snapshots to your EVBackup account:

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 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 ~]$
4. Enter an rsync command with --hard-links and --dry-run
The following command needs to be entered as a single statement:
sudo rsync -avz --hard-links --dry-run -e "ssh -i /backup/ssh_key" /backup/snapshots user@user.evbackup.com:remote-folder
Note that you need to use a --hard-links argument so that the links are uploaded to the site — and not extra copies of the linked files.
  • Why aren't you using trailing slashes? »
  • « OK. Hide this

Because the rsync argument -a implies a --recursive argument. Effectively, that means that if the target of the rsync script is a directory, then it and all sub-directories will be backed up.

Note that rsnapshot still requires a trailing slash on directories.

5. Paste and render executable the contents of your rsync command (sans --dry-run) into a file
The first command needs to be entered as a single statement, and remember to \escape \internal \quotes \":
sudo echo "rsync -avz -e \"ssh -i /backup/ssh_key\" /backup/snapshots user@user.evbackup.com:remote-folder" > /backup/backup-snapshots.sh
sudo chmod +x /backup/backup-snapshots.sh
6. Edit the cmd_postexec directive in /etc/rsnapshot.conf
cmd_postexec   /backup/backup-snapshots.sh

Remember: if you need help, just ask: support@evbackup.com

Step Three: Run and Verify the Initial Backup

When you are ready to go, run the daily backup. Enter the following into a terminal:

sudo rsnapshot daily

The expected sequence of events that you will need to validate are:

  1. rsnapshot populated snapshot_root with the initial backup of all targeted files and directories.
  2. rsync uploaded the contents of snapshot_root to your EVBackup account.  
    • How do I check this? »
    • « Hide this

    Here are two easy ways to check:

    1. Log in with SSH at a terminal:

      ssh user@user.evbackup.com ls -Ar remote-folder

    2. Use Filezilla or another FTP client to log in and review your files.

Step Four: Automate the Backup with cron

Once you have your backup script created and saved, you need only to add a cron job to automate it. To automate a cron job for your rsync script:

  1. At terminal, add a cron job for the superuser:

    sudo crontab -e

  2. Enter the schedule command for the rsnapshot daily command.

    For example, to run rsnapshot daily Monday through Saturday at 11:42 PM, you would enter:

    42 23 * * 1-6 rsnapshot daily

      What are the crontab fields? »
      « Hide this

    The fields in crontab (separated by s p a c e s or tabs) are:

    [minute] [hour] [day of month] [month] [weekday] [command] [command args]
    Use commas to designate a more than one value: 00,09,11,22
    Use hyphens to designate a range of values: 0-6

  3. Enter the schedule command for the rsnapshot weekly command.

    For example, to run rsnapshot weekly on Sunday at 1:42 PM, you would enter:

    42 13 * * 0 rsnapshot weekly

  4. Enter the schedule command for the rsnapshot monthly command.

    For example, to run rsnapshot monthly on the 3rd of each month at 4:42 AM, you would enter:

    42 04 03 * * rsnapshot monthly

  5. Save your crontab file and close your text editor. You're all set!

Should you have questions or need help: support@evbackup.com