Rsnapshot – A backup Utility

There are many ways to backup Servers. One of the better ways to accomplish this is using rsnapshot. Rsnapshot is nothing but a filesystem snapshot utility for backing up local and remote systems.

Rsnapshot is written in Perl, and depends on rsync. With ssh access, it is possible to backup remote servers.

Hire Bobcares Linux Server Administrators
Get super reliable servers and delighted customers

See how we do it!

 

Why Rsnapshot?

We have many familiar ways to generate full backup and copy it to another server which includes ftp, scp and all. But now the question that comes to your mind will be “Why should I use rsnapshot ? or What is so special about this tool?”
Listed below are the major advantages of rsnapshot, which make you feel that it is worth using.

  • Using rsync and hard links, it is possible to keep multiple, full backups instantly available. The disk space required is just a little more than the space of one full backup, plus incrementals. This comes as a criteria when your drive is lacking enough free space to accommodate 3 copies of backup.
  • 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.
  • There are no tapes to change, so once it’s set up, you may never need to think about it again.
  • Rsnapshot takes advantage of hard links (multiple directory pointers to the same data) to give the appearance of multiple full backups yet requires only enough disk capacity to store the complete data set plus any changed files. Thus we have the illusion of full hourly, daily, weekly, and monthly backups without having the physical space to hold that many copies.
  • Another benefit is that rsync is cross-platform, so it isn’t constrained to *nix systems.

Installation of rsnapshot

Rsnapshot can be installed in a few minutes of time. It requires the following prerequisites.
1) Perl
2) rsync

i). Download the latest source tarball from http://www.rsnapshot.org/downloads.html

ii). Untar the source code package

tar xzvf rsnapshot-1.3.0.tar.gz

iii). Change to the source directory.

cd rsnapshot-1.3.0/

iv). Select the directory to install the files. Usually the files are placed in /usr/local directory and the config files in the /etc directory.

v). Run the configure script

./configure --sysconfdir=/etc

vi). Install the program by

make install

Now rsnapshot is installed under /usr/local, with the config file in /etc.

Configuration

A sample copy of the rsnapshot config file is provided with the package. We need to just copy the file.

cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf

The directives that need to be configured in rsnapshot.conf

1. snapshot_root
This is the snapshot root directory which holds the file system snapshots.

snapshot_root   /.snapshots/

2. Modify the path to the various programs like rm for removing files, rsync, ssh etc. Usually not much modification is needed here.

3. Specify thebackup intervals.

interval        hourly  6
interval        daily   7
interval        weekly  4

In this example, rsnapshot is taken every four hours, or six times a day (these are the hourly intervals), 7 times a week, 4 times a month. Thus it covers the whole month (4 weeks)

4. Select verbose level, loglevel and logfile path. Typical values used are

verbose         2
loglevel        3
logfile        /var/log/rsnapshot

5. Next main configuration to be done is BACKUP POINTS / SCRIPTS

This is the section where you tell rsnapshot what files you actually want to back up. You put a “backup” parameter first, followed by the full path to the directory or network path you’re backing up. The third column is the relative path you want to back up to inside the snapshot root.

# LOCALHOST

backup   /home/          localhost/
backup   /etc	         localhost/
backup  /usr/local/      localhost/

For example, take case 1, where the parameter is “backup”. We are backing up the /home partition of the server on the rsnapshot root of our server itself. Thus with this backup parameter, a backup of /home is created in /root/.snapshots

In addition to full paths on the same server, we can also backup filesystems on remote systems using rsync over ssh. To get this done,

a) The ssh daemon must be running on the remote server.

b) You must have access to the account you specify the remote machine, in this case the root user on remote server.

c) You must have key-based logins enabled for the root user at remote server, without passphrases.

# EXAMPLE.COM

backup root@example.com:/home/ example.com/
backup root@example.com:/home/ example.com/ exclude=mtab,exclude=core

In example 1, /home partion of remote server example.com is backed up to the server where snapshot is running. In example 2, similarly /etc partion is backed up, excluding mtab and core directories.
This backup parameter is commonly used in live servers for backup configuration.

Allowing remote logins with no passphrase is a security risk that may or may not be acceptable in your situation. Make sure you guard access to the backup server very carefully! If we wish to perform backup as another user, we could specify the other user instead of root for the source (i.e. user@example.com).

Now with this we have completed the basic configuration of rsnapshot.

6. Testing configuration file.

rsnapshot configtest

If all is well, it should say Syntax OK, or else the errors are shown. We have to use tabs in the config file and not spaces.

7. Test run of rsnapshot

rsnapshot -t hourly

This tells rsnapshot to simulate an “hourly” backup. It will print out the commands it will perform when it runs for real.

Automating rsnapshot using cron job

Edit root’s crontab by command

crontab -e

Add the following entries,
0 */4 * * * /usr/local/bin/rsnapshot hourly
30 23 * * * /usr/local/bin/rsnapshot daily

Cron should be timed in a way that the hourly backup is finished before performing the daily backup.

How it works

All backups are stored in the snapshot directory. New directories inside the snapshot root are created when rsnapshot hourly and weekly are run. Thus when rsnapshot hourly is run 6 times, the directories with name hourly.0, hourly.1, ….hourly.5 are created. Similarly when rsnapshot weekly is run, 7 new directories are created namely weekly.0, weekly.1, weekly.2 till weekly.6.

Each subsequent time rsnapshot is run with the hourly command, it will rotate the hourly.X directories, and then “copy” the contents of the hourly.0 directory (using hard links) into hourly.1.

When rsnapshot daily is run, it will rotate all the daily.X directories, then copy the contents of hourly.5 into daily.0.

hourly.0 will always contain the most recent snapshot, and daily.6 will always contain a snapshot from a week ago.
Unless the files change between snapshots, the “full” backups are really just multiple hard links to the same files.
That is how rsnapshot saves disk space. If the file changes at any point, the next backup will unlink the hard link in hourly.0, and replace it with a brand new file.

When weekly, monthly, and yearly intervals defined (in that order), the weekly ones would get updated directly from the filesystem, the monthly ones would get updated from weekly, and the yearly ones would get updated from monthly.

Conclusion

When the aforesaid instructions are followed, rsnapshot installation is quite simple and is very efficient in performing automatic backups of your system. The amount of disk space taken up will be equal to one full backup, plus an additional copy of every file that is changed.

Reference:

http://www.rsnapshot.org/


Articles by Sijin

About the author:
Sijin A. George works as Sr. Software Engineer (Grade II) in Bobcares.com.
She has worked in Bobcares for 3 years and specializes mainly on linux server administration.



Backup

7 Comments

  1. Hi Sijin,

    I am trying to use Rsnapshot, but in my case I have to send the files and directories I want to backup on another server, and only by ftp. Would you know how it is possible to add information to allow the connection to the server by ftp ?

    Thanks for your blog 🙂

    jim

  2. Hi Jim,

    Rsnapshot is performed over ssh. A quick workaround for you will be, to have rsnapshot taken on the same server and then copy the directory/files via ftp to remote backup server using a script.

    Sijin

  3. Thank you for showing me the Rsnapshot configuration I found it very useful. Keep up the good work.

  4. I also thank you Sijin 🙂

  5. Oh by the way,
    If we don’t want to do the hourly backup, just comment it. It will skip directly to daily backup.

  6. Currently I am trying to back up over SSH some 27GB or so, but most of the data exists locally at /mnt/usbdrive/weekly.0/ so with rSnapshot it should be a minimal transfer. But the program is fighting my backup points!

    My rsnapshot.conf file has these entries:

    == CUT ==
    snapshot_root /mnt/usbdrive/


    # BACKUP POINTS AND SCRIPTS #
    backup root@remote.domain.com:/mnt/backups/weekly.0/ backUPS
    === END ===

    My problem is that when I run my weekly (or any) backup, rather than having the remote files dumped to:
    > /mnt/usbdrive/weekly.0
    or even to:
    > /mnt/usbdrive/backUPS/weekly.0
    they are instead being written to:
    > /mnt/usbdrive/backUPS/mnt/backups/weekly.0/

    That is, the rSnapshot is writing the whole remote file tree to my /rsnapshot root/backUPS/ folder. Not what I want, but I don’t know how to rewrite the “root@remote.domain.com:/mnt/backups/weekly.0/ ” part to just go to the one folder that I want.

    The remote site has daily weekly and monthly rsnapshot backups to /mnt/backups/ and I just want to rsnapshot the weekly ones to my office. However this is creating a too-complex tree on my end.

    And, now that I have about 15 versions due to testing all of this, and they’re all hardlinks, am I safe to remove 14 of them and keep the single /mnt/usbdrive/backUPS/weekly.0/ folder? or will removing all of these attempts end up following the hardlinks and erasing my real data?

  7. Hi lefty.crupps,

    Rsnapshot uses hard links and it copies the entire source tree in the backup server too. So the source tree name will be added in the backup path. But, if you wish to skip the backup of few directories you can use the parameter ‘exclude’ in the config file.

    You can safely remove folders from earlier test snapshots. But make sure that you are not modifying the souce tree when rsnapshot is being done.

    Sijin

KEEP OUT MALWARE & HACKERS

Hackers

Security specialists will audit, update, patch, harden and monitor your server 24/7.

Starting at $69.99/month

SEE PLANS