Rsnapshot is a Perl script that utilizes rsync and hard links to make automated backups quick and efficient. Setting up a central backup server with rsnapshot is simple, and the client-side requirements are minimum. This guide assumes you already have ssh setup with a passwordless login using ssh keys and are using FreeBSD as your operating platform.
Determine your Backup Needs
The first step to any backup plan is determining your backup and restore needs. Determine what server will hold your backups. This server should have redundant disk arrays with plenty of storage space. Also, compile a list of the servers that need to be backed up, including the files and directories that are important. Estimate the total size of these files and directories to make sure your backup server has enough capacity. The second part of this equation is to determine how often, and with what retention history you need. For this article, we will assume a daily backup schedule with a seven day retention period.
Client Configuration
Make sure you have rsync installed on all the clients you wish to backup. Passwordless ssh access from the backup server is also required for this article.
Server Install and Configuration
The following instructions will help you setup rsnapshot on your central backup server.
-
Choose your installation method:
-
Source:
or
- Package:
-
Source:
-
Copy the example configuration file:
Modify rsnapshot.conf
snapshot_root /usr/.snapshots/ cmd_rm /bin/rm cmd_rsync /usr/local/bin/rsync cmd_ssh /bin/ssh cmd_logger /usr/bin/logger retain daily 7 verbose 2 loglevel 3 lockfile /var/run/rsnapshot.pid rsync_short_args -a rsync_long_args --delete --numeric-ids --relative --delete-excluded --bwlimit=10000 backup server1.example.com:/etc/ server1/ backup server2.example.com:/usr/local/etc/ server2
Let's take a moment to explain some important parts of rsnapshot.conf. Please note that all elements in rsnapshot.conf require a tab character between elements. For example:
- is the full path where you want the backups to be stored. usually has the largest amount of space on a default FreeBSD system, so I'll be putting my backups in Please note, the trailing slash is REQUIRED.
- is the path to your ssh binary. In order to use rsnapshot over ssh, you MUST uncomment this line and confirm the path to ssh.
- defines the retention period. For our example, we'll be using “retain daily 7”. You can also add hourly and monthly backups if you wish.
- contains arguments rsnapshot will pass to rsync. If you are sending data over a high latency link, it would be wise to add to the short arguments. See the rsync man page for a full list of available arguments.
- contains arguments rsnapshot will pass to rsync. is a useful argument so you don't saturate your network card during the transfer. Do NOT define include and exclude arguments here. There is a specific section in the configuration file for these entries. See the rsync man page for a full list of available arguments.
- contains arguments passed to ssh when the connection is established. If you are using a non-standard ssh port, you would define that here.
- are passed to rsync as include/exclude arguments. See the rsync man page on how to specify these.
- are passed to rsync. This allows you to consolidate include and exclude arguments into a file. See the rsync man page on how to specify these files.
- is used to specify a backup source and destination. By default, rsnapshot is configured to backup Please note, that all directory entries need to have a trailing forward slash “/”. Use tabs to separate the elements of the line.
- is used to call a script instead of using the basic rsync call. This is useful if you need to dump a database before backing up the files. I prefer to use the simple backup call, and leave the database dumping to a script on the actual database server. This leaves your rsnapshot.conf file with a cleaner look.
Testing your Configuration
Once rsnapshot.conf has been edited to your needs, test the configuration by running This will parse the configuration file and report any errors you have made. My most common error in the file was not using tab between elements. Fix any errors the parser finds.
Now we are going to test the backup interval. Run to print out the commands rsnapshot will execute. This will allow you to check the syntax on the commands, and make sure there are no errors.
If you have done everything correctly, running will execute the backup, placing the files into your snapshot_root directory. Once the command finishes, go confirm the existence of the files that were supposed to be backed up.
Automating your Backups
Once you have successfully tested your configuration, it is time to automate your backups. Simply edit /etc/crontab and add the following entry:
0 3 * * * root /usr/local/bin/rsnapshot daily
Now, your backup server will pull backups from each server defined in rsnapshot.conf daily at 3:00 AM.
