How To Backup Remote Linux Host Using rsnapshot rsync Utility

by Ramesh Natarajan on September 16, 2009

Ubuntu, Debian, Linux Remote BackupIn the previous article we reviewed how to backup local unix host using rsnapshot 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/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.

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

[root@remote-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)
[receiver=2.6.8]
----------------------------------------------------------------------------
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@192.168.2.2:/etc/

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.

Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

If you enjoyed this article, you might also like..

  1. How To Backup Local Unix Host Using rsnapshot rsync Utility
  2. How To Monitor Remote Linux Host using Nagios 3.0
  3. Backup and Restore MySQL Database using mysqlhotcopy
  4. How To Execute SSH and SCP in Batch Mode (Only when Passwordless login is enabled)
  5. Free Windows Backup Software – GFI Backup Home Edition Freeware
  

Vim 101 Hacks Book

{ 2 comments… read them below or add one }

1 Marko September 17, 2009 at 2:32 pm

Hi,
I am able to backup files and folders from Debian machine to windows machine.
I would like to know how to backup the entire hdd from Debian machine to usb-hdd atached to windows machine?
It would be nice to know how to do this.
How to do daily snapshots of linux hdd – I mean exact copy of linux hdd.
Is it possible to create a snapshot and then just incremental backup to that snapshot?
I will crate webpage with drawing of my configuration if someone is intresting in giveing any advice about my questions…

Marko

2 Marko September 18, 2009 at 3:23 am

So here is web page where I made a drawing of my problem:
http://www.pc-help-ambrozic.com/config/

Leave a Comment

Previous post:

Next post: