Debianhelp.co.uk


rsnapshot Backup Configuration in Debian

What is rsnapshot ?

rsnapshot is a filesystem snapshot utility for making backups of local and remote systems.

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.

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 is written entirely in Perl. It should work on any reasonably modern UNIX compatible OS, including: Debian, Redhat, Fedora, SuSE, Gentoo, Slackware, FreeBSD, OpenBSD, NetBSD, Solaris, Mac OS X, and even IRIX.

rsnapshot documentation and how-to

http://www.rsnapshot.org/howto/

Download rsnapshot

http://www.rsnapshot.org/downloads.html

rsnapshot Upgrade Guide

http://www.rsnapshot.org/upgrade/

rsnapshot FAQ

http://www.rsnapshot.org/faq.html

rsnapshot man page

http://www.rsnapshot.org/rsnapshot.html

rsnapshot installation in Debian

#apt-get install rsnapshot

this will install rsnapshot in your machine

Configuring rsnapshot

Default configuration file is rotated at /etc/rsnapshot.conf
this is the file you need to do the changes for your backup requirements

Setup the rotation periods.
Setup the list of directories/files to backup.
Optionally exclude files from the backups.

The only thing to remember is that when setting up keys and values in the configuration file you must specify them as Tab-separated.

you'll need to do is uncomment the various rotation periods:

interval hourly 6
interval daily 7
interval weekly 4
interval monthly 6

If these are left commented out (Comments are lines beginning with the '#' character) then nothing will happen.

The numbers listed against the names will control how often the backups are rotated, so by default you'll receive:

6 hourly backups.
7 daily backups.
4 weekly backups.
6 monthly backups.

Once these have been uncommented you'll need to setup the directories to backup. How this is done depends on the nature of the directories, local vs. remote.

A local directory will look like this:

# LOCALHOST
backup /home/ localhost/
backup /etc/ localhost/
backup /usr/local/ localhost/

Note :- Remember that tabs are used to separate these values.

A remote system will instead look like this:

backup root@hostname:/home/ hostname/
backup root@hostname:/etc/ hostname/
backup root@hostname:/usr/local/bin/ hostname/

The difference between these two samples is the second section of the lines; for local systems it is just a directory name with a trailing "/" character. For remote hosts you should use "login@full.hostname.com:/path".

The last field in the samples is the backup directory to use upon the localhost - by default the backups will be stored beneath "/var/cache/rsnapshot". You can change this by setting:

#
# Change the location where backups are stored.
#
snapshot_root /mnt/nfs/backupstore

If you are setting up remote backups the system assumes the there is a password-less login setup between the local machine and the remote machine specified (root@hostname in this example).

If you've not setup key-based OpenSSH logins then now is a good time to do it.

Note that you don't need to use remote root logins unless the files you wish to backup are unreadable to ordinary users upon the machine you're backing up. (Although it's fair to say if you're backing up /etc you'll almost certainly wish to do so as root - as otherwise important files such as /etc/shadow will not be read).

Once you've configured your logins for remote machines, and setup the filepaths you wish to backup you only need to enable the cronjob used to run the backups.

To do that remove the "#" comment characters from the relevant lines in /etc/cron.d/rsnapshot file leaving you with :

# This is a sample cron file for rsnapshot.
# The values used correspond to the examples in /etc/rsnapshot.conf.
# There you can also set the backup points and many other things.
#
# To activate this cron file you have to uncomment the lines below.
# Feel free to adapt it to your needs.

0 */4 * * * root /usr/bin/rsnapshot hourly
30 3 * * * root /usr/bin/rsnapshot daily
0 3 * * 1 root /usr/bin/rsnapshot weekly
30 2 1 * * root /usr/bin/rsnapshot monthly

The names used here "hourly", "daily", etc, match those used in the rsnapshot.conf file - which is important.

Once you've enabled the cronjobs you should be ready to make your first backup - which will take a while.

To do so run:

rsnapshot hourly

If all goes well you'll receive your backup files beneath "backup_root"/hourly.0/hostname, and any errors will be reported in the file /var/log/rsnapshot.log.

After a few days you'll notice that you have several new files such as:

root@test01:/mnt/backup# ls -l
total 68
drwxr-xr-x 4 root root 4096 2005-08-16 04:00 daily.0
drwxr-xr-x 4 root root 4096 2005-08-15 04:00 daily.1
drwxr-xr-x 4 root root 4096 2005-08-14 04:00 daily.2
drwxr-xr-x 4 root root 4096 2005-08-13 04:01 daily.3
drwxr-xr-x 4 root root 4096 2005-08-12 04:00 daily.4
drwxr-xr-x 4 root root 4096 2005-08-11 04:00 daily.5
drwxr-xr-x 4 root root 4096 2005-08-10 04:01 daily.6
drwxr-xr-x 4 root root 4096 2005-08-17 20:01 hourly.0
drwxr-xr-x 4 root root 4096 2005-08-17 16:00 hourly.1
drwxr-xr-x 4 root root 4096 2005-08-17 12:00 hourly.2
drwxr-xr-x 4 root root 4096 2005-08-17 08:01 hourly.3
drwxr-xr-x 4 root root 4096 2005-08-17 04:00 hourly.4
drwxr-xr-x 4 root root 4096 2005-08-17 00:01 hourly.5

These are the rotated backups which we've saved, the initial backups will be the largest - the later ones will only contain changes made since the previous run.

To see this you can view the amount of disk space taken up by each backup with "rsnapshot du":

root@test01:/mnt/backup# rsnapshot du
8.1G /mnt/backup/hourly.0/
124M /mnt/backup/hourly.1/
164M /mnt/backup/hourly.2/
90M /mnt/backup/hourly.3/
90M /mnt/backup/hourly.4/
79M /mnt/backup/hourly.5/
194M /mnt/backup/daily.0/
199M /mnt/backup/daily.1/
216M /mnt/backup/daily.2/
189M /mnt/backup/daily.3/
229M /mnt/backup/daily.4/
224M /mnt/backup/daily.5/
324M /mnt/backup/daily.6/
11G total

As the output shows the initial backup consumes a significant amount of disk space, and later ones only show the small amount of changes since then.

To reduce the space of the backups you can exclude files you don't care about, such as Apache logfiles. Simply add the filenames, or patterns, to the configuration file:

exclude access.log
exclude access.log.*
exclude error.log
exclude error.log.*
exclude referer.log
exclude referer.log.*
exclude agent.log
exclude agent.log.*
exclude Mail/backup/*
exclude /home/qemu
exclude Cache
exclude history.dat
exclude .bash_history
exclude viminfo

Note that any filename which matches the patterns will be excluded - so don't be too permissive or you might accidentally include a filename you did care about.

Restore your backup

You want to do a bare metal restore takes a little more preparation.

First, lets assume that we are backing up the following directories on the target system:

/boot/
/etc/
/root/
/usr/local/
/home/
/lib/modules

Ok that covers any data that changes, for the core system files, we'll need a list of what is installed so we can reinstall later. To create this list automatically every night, create a simple cron job in /etc/cron.d/dpkg-listfiles:

#
# Create list of all distro installed packages for restore
#
00 1 * * * root dpkg -l | awk '{print $2}' > /root/.dpkg-filelist

Boot the corrupted machine to a knoppix or other bootable media that includes support for ssh.

Repartition and Reformat the drive as necessary. Mount the partitions with temporary mount points:

...
mkfs.ext2 /dev/hda1
mkfs.ext2 -j /dev/hda2
mkswap /dev/hda3
mkfs.ext2 -j /dev/hda5
mkdir /mnt/temproot
mount /dev/hda2 /mnt/temproot
mkdir /mnt/temproot/boot
mount /dev/hda1 /mnt/temproot/boot
mkdir /mnt/temproot/home
mount /dev/hda5 /mnt/temproot/home

Install base system:

#debootstrap --arch i386 sid /mnt/temproot/

Copy .dpkg-listfiles to the new system.

#scp [user]@[backupserver]:/path/to/backups/daily.0/root/.dpkg-listfil es /mnt/temproot/dpkg-listfiles

Chroot into the new environment and install all of the applications that we had.

#chroot /mnt/temproot /bin/su -

#cat /dpkg-listfiles | xargs apt-get install
...
Warning: You may have to run the install step a couple times to get past a few errors and/or package changes.

Exit the chroot and copy back our data from our backups:

#scp -r [user]@[backupserver]:/path/to/backups/daily.0/* /mnt/temproot/

Install grub (or lilo) to the boot sector of the hard drive:

grub-install /dev/hda
grub
root (hd1,0)
setup (hd1)
quit

Now you can reboot to the "new" system and it should be just like the old one.

rsnapshot tools

rsnapgraph

rsnapgraph is a script that generates graphs using GNUPlot that show the increase and decrease of the number of files in and disk space used by the snapshot directories created by rsnapshot. It can be used to monitor snapshot growth and to watch for very large increases or decreases.

Downloads and Documentation

http://denism.homeip.net/software/rsnapgraph.html