Tuesday, September 4, 2007

Linux backups powered by RSnapShot

For more linux backups alternatives, which was covered here and here,.

RSnapShot, as mentioned to be a future entry, is now here as an alternative backup tools in linux.

RSnapShot is a linux filesystem snapshot backup utility. One of the nicest thing about rnsnapshot backup utility is that rsnapshot can do incremental snapshots of local and remote file systems for unlimited number of machines as long as the destination storage capacity can handle the backup snapshot output size. Rsnapshot utilizes rsync package to capture a snapshot of a filesystem. Rsync even saves more disk space by using linux hardlinks when creating snapshots.
Rsync becomes more powerful combined with large capacity media and network storage device. Rnapshot can create an exact duplicate of data from partition or folder locally or remotely.

Rsnapshot makes use of /etc/rsnapshot.conf conf file on creating filesystems snapshot backup.

RSNAPSHOT INSTALLATION:
=======================

# yum -y install rsnapshot rsync

This program should work on any reasonably modern UNIX compatible OS. It has been tested successfully on the following operating systems:
- Debian: 3.0 (woody), 3.1 (sarge), unstable (sid)
- Redhat: 7.x, 8.0, Enterprise Linux 3.0 ES
- Fedora Core 1, 3
- CentOS 3, 4
- WhiteBox Enterprise Linux 3.0
- Slackware 9.0
- SuSE: 9.0
- FreeBSD 4.9-STABLE
- OpenBSD 3.x
- Solaris 8 (SPARC and x86)
- Mac OS X
- IRIX 6.5


BINARY EXECUTION
================

Once rsnapshot has been installed, you will need to configure rsnapshot default config file. But first it is highly advisable to backup the original config file before doing any changes. Back it up as usual with the linux copy file command

# cp /etc/rsnapshot.conf /etc/rsnapshot.conf.bak


RSNAPSHOT PARAMETERS
====================

From command line, rsnaphot can be executed like so

# rsnapshot -v -t [interval] -c /var/backup/rsnapshot.conf [number]

Legend:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-t for time interval parameter
interval can be hourly, daily, weekly, monthly backup

Optional arguments:
-v enabled verbosity mode
-c custom config file
-V more verbosity
-q silent mode
-D full blown diagnostic verbose mode
number numerical interval identification number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


RSNAPSHOT CONFIG FILE SETUP
===========================

Remember that variable and value inside rsnapshot.conf are separated by tab space. All folders are ended by / character.

By default, all snapshots would be stored under /.snapshots/ . For a different snapshot destination, you can edit the line that says

snapshot_root /.snapshots/

If you are backing up to a removable external media, it is advisable to enable this line

no_create_root 1

Now, for backup intervals
interval hourly 6
interval daily 7
interval weekly 4
interval monthly 12

From the above conf lines, hourly interval backups can have 6 snapshots before rotating the snapshot backup file. The daily interval has 7, this means that when rsnapshot is executed, rsnapshot would keep 7 daily snapshots before rotating the backup snapshot files.

For example

interval hourly 8

This means that every time "rsnapshot hourly" is run, it will make a new snapshot, rotate the old ones, and retain the most recent eight (hourly.0 - hourly.7) snapshots. This would be clearer when we combine rsnapshot with cron utility later on.

If you are specifying these intervals from command line, make sure you commented them out from rsnapshot.conf. However, global parameters are supposed to be on a centralized configuration file, that is why it is included from the rsnapshot.conf file as shown with the above sample.

For compatibility issues, leave this line uncommented

cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/bin/rsync
cmd_logger /usr/bin/logger
cmd_du /usr/bin/du
du_args -csh

If you have specific file glob patterns you can include them using this directive like so

include /home/ver/*.mp3

and excluding file blog patterns for example, like so

exclude /home/hisfolder/*.ISO

Here are the backup points that needs to be modified as an example

backup /home/ localhost/

/home/ is the snapshot destination folder under /.snapshot/ located from my current box. As you have noticed, folder locations are ended with / character and separated by tab key.

localhost would be the snapshot identification folder name that would be stored under the default snapshot destination folder, for this case is /.snapshot/ . For convenience of understanding, an hourly rsnapshot with the config sample shown above would be stored to

/.snapshots/hourly.0/localhost/home

Saving snapshot backup file to a remote host can also be specified from rsnapshot config file. This can be specifed as an example like so

backup user@backup-server2.com:/ backup-server2.com/

Passwordless and passphaseless ssh connection can be helpful here.

At this point, considering the setup above, rsync would create a local backup snapshot of /home and store the backup file to /.snapshots/ as its snapshot destination folder. Snapshots backup file includes /home/ver/*.mp3 files, /home/ partition folder and excluding /home/hisfolder/*.ISO files. Rsync would be run with default verbose logging dumped to /var/log/rsnapshot .

Here's a screenshot of rsnapshot in action considering the above configuration file together with rsnapshot log file:





Here's a rsnapshot disk usage of the above example.

# rsnapshot du localhost/home
~~~~~~~~~~~~~~~~~~
1.3G /.snapshots/hourly.0/localhost/home
1.3G total
~~~~~~~~~~~~~~~~~~

Now, compare it with using du (disk usage linux command) like so

# du -chs /home
~~~~~~~~~~~~~~~~~~
1.3G /home
1.3G total
~~~~~~~~~~~~~~~~~~


VERIFICATION OF RSNAPSHOT CONFIG FILE
======================================

For sanity checking of rsnapshot configuration file, this can be done from command line terminal like so

# rsnapshot configtest

If everything is fine, the below line should appear from executing the above command like so
~~~~~~~~~~~~~~~~
Syntax OK
~~~~~~~~


~~~~~~~~


RSNAPSHOT LOG MONITORING
~~~~~~~~~~~~~~~~~~~~~~~~

To monitor the latest rsnapshot log messages

# tailf /var/log/rsnapshot


RSNAPHOT ON CRONTAB UTILITY
===========================

Backup procedures are effective when done automatically without any user interactions.

Now, let us combine rsnapshot with crontab utility. Here's a sample crontab job with rsnapshot

00 00 * * * /usr/bin/rsnapshot daily
00 04 * * 6 /usr/bin/rsnapshot weekly
00 04 1 * * /usr/bin/rsnapshot monthly

This specifies a daily rsnapshot at midnight, a weekly snapshot on Saturdays at 4:00AM and a monthly rsnapshot at 4AM on the first day of each month.


Rsnapshot just created the first exact replica of /home . You are probably thinking that snapshots are actually exact data replica which just consumes your disk space. No, it is not.

Rsnapshot creates snapshots with differential and incremental algorithm in mind. Only changed contents of file and folder are saved into snapshots destination folders. Linux command du (disk usage) would report the same disk or folder size, which might confuse you later on.

Rsnapshot-diff to the rescue. Here is where rsnapshot-diff disk usage reporting tool comes in.

Try deleting some unimportant files or moving it to different folder location from the source backup location and compare the snapshot using rsnapshot-diff like so

# rsnapshot-diff /home /.snapshots/hourly.3/localhost/home/

which gives you a similar output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comparing /home to /.snapshots/hourly.3/localhost/home/
Between /home and /.snapshots/hourly.3/localhost/home/:
13081 were added, taking 1279034992 bytes;
13075 were removed, saving 1162911380 bytes;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After moving some file, and did the rdiff comparison, you will see the difference from there.

For more FAQs.

Final Note:

Backing up data is critical that it needs critical and detailed attention. Any single byte differences can probably make the backup copy unusable. Implementing proper backup policy, backup documentation and procedures is one good attitude towards attaning an efficient and effective backup and recovery do's and dont's.

Goodluck then. Happy black boxes kicking and happy reading too!

Related Posts:

Linux Backup using Tar
Linux Backup using RDiff

Bandwidth-Effificent and Encrypted Linux Backup

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy