How To Backup Remote Linux Host Using rsnapshot rsync Utility

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


1. Setup Key Based Authentication

As we’ve explained earlier setup the key based authentication as explained either in ssh-keygen and ssh-copy-id article or openSSH article.

[root@local-host]# ssh-keygen

[root@local-host]# ssh-copy-id -i ~/.ssh/ remote-host

2. Verify the password less login between servers

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

[root@local-host]# ssh remote-host
Last login: Sun Mar 15 16:45:40 2009 from local-host


3. Configure rsnapshot and specify Remote Host Backup Directories

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

  • root@remote-host:/etc – 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. Please note that this directory will be created under local-host /.snapshots/{internal.n}/ directory as shown in the last step.
# vi /etc/rsnapshot.conf

backup  root@remote-host:/etc/  remote-host-backup/  exclude=mtab,exclude=core

4. Test rsnapshot Configuration

Perform configuration test to make sure rsnapshot is setup properly and ready to perform Linux rsync backup.

# 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 cwrsync utility, it is time to set this puppy up in the crontab as shown below.

# crontab -e
0 */4 * * * /usr/local/bin/rsnapshot hourly
30 23 * * * /usr/local/bin/rsnapshot daily

Check out Linux crontab examples article to understand how to setup and configure crontab.

6. Manually test the remote-host backup once

[root@local-host]# /usr/local/bin/rsnapshot hourly

[root@local-host]# ls -l /.snapshots/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

[root@local-host]# ls -l /.snapshots/hourly.0/remote-host-backup/
total 4
drwxr-xr-x 93 root root 4096 Jul 22 03:36 etc

Troubleshooting Tips

Problem: rsnapshot failed with ERROR: /usr/bin/rsync returned 20 as shown below.

[root@local-host]# /usr/local/bin/rsnapshot hourly
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(260)
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot hourly
ERROR: /usr/bin/rsync returned 20 while processing copyman@

Solution: This typically happens when the users who is performing the rsnapshot (rsync) doesn’t have access to the remote directory that you are trying to backup. Make sure the remote host backup directory has appropriate permission for the user who is trying to execute the rsnapshot.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s