in DevOps

How to configure rsnapshot for remote backups ?

rsnapshot is a filesystem snapshot utility based on rsync. rsnapshot makes it easy to make periodic snapshots of local machines, and remote machines over ssh. The code makes extensive use of hard links whenever possible, to greatly reduce the disk space required.

Depending on your configuration, it is quite possible to set up in just a few minutes. Files can be restored by the users who own them, without the root user getting involved.

In this article, let us review how to backup remote Linux host using this utility.

1. Setup Key Based Authentication

#create public & private key on host server
[[email protected]]# ssh-keygen -t rsa

#Copy public key to remote server authorized key file
[[email protected]]# ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

2. Verify the password less login between servers

Login to the remote-host from local host without entering the password.

[[email protected]]# ssh remote-host
Last login: Sun Mar 15 16:45:40 2009 from localhost

[[email protected]]#

3. Configure rsnapshot and specify Remote Host Backup Directories

Define your  rsnapshot root directory where backup would be saved in /etc/rsnapshot.conf .

#vi /etc/rsnapshot.conf

snapshot_root            /.rsnapshot/ 

You will also want to uncomment the cmd_ssh line to allow for remote backups.

cmd_ssh            /usr/bin/ssh

Remove the “#” from before the cmd_du line to enable accurate disk usage reports.

cmd_du             /usr/bin/du

If you had changed the port number on the remote server you are backing up, you may also need to set the below parameter (Replace 25000 with port configured on remote server) .

ssh_args           -p 25000

Next, we need to consider how many old backups we would like to keep.We set these up under the “BACKUP INTERVALS” section of the configuration.  Edit this section to look like this:

#########################################
#           BACKUP INTERVALS            #
# Must be unique and in ascending order #
# i.e. hourly, daily, weekly, etc.      #
#########################################

retain      hourly  6
retain      daily   7
retain      weekly  4
retain      monthly 3

Now define your remote-host destination backup directories in /etc/rsnapshot.conf as shown below. In this example,

  • [email protected]:/var/www/ – Source directory on the remote-host that should be backed-up. i.e remote backup destination directory.
  • remote-host-backup/ – destination directory where the backup of the remote-host will be stored.
backup  [email protected]:/var/www/  remote-host-backup/

4. Test rsnapshot Configuration

Perform configuration test to make sure rsnapshot is setup properly.

# rsnapshot configtest
Syntax OK

5. Add Crontab Entry for rsnapshot

Once you’ve verified that the rsync hourly and daily backup configurations are setup properly in the rsnapshot rsync utility, it is time to set this in the crontab as shown below.

# crontab -e
0 0/4 * * * /usr/bin/rsnapshot hourly
@daily /usr/bin/rsnapshot daily
@weekly /usr/bin/rsnapshot weekly
30 2 1 * * /usr/bin/rsnapshot monthly

6. Manually test the remote-host backup once

[[email protected]]# /usr/bin/rsnapshot hourly

[[email protected]]# ls -l /.rsnapshots/hourly.0/
total 8
drwxr-xr-x 3 root root 4096 Jul 22 04:19 remote-host-backup
drwxr-xr-x 3 root root 4096 Jul 13 05:07 localhost

[[email protected]]# ls -l /.rsnapshots/hourly.0/remote-host-backup/
total 4
drwxr-xr-x 93 root root 4096 Jul 22 03:36 var