Rsnapshot – Rsync based utility to take backup in Linux and Unix

Rsnapshot - Rsync based utility to take backup in Linux and Unix

Rsnapshot - Rsync based utility to take backup - Introduction

Rsnapshot is an rsync based untility in Linux and Unix which is used to backup your remote and local files. Rsnapshot uses rsync and hard links to take full and incremental backup of your Linux machine. Remote backup is possible by using rsync over ssh. However, for remote backup with Windows you have install application on Windows to act as Rsync on Windows. Rsnapshot is a free software under GPL terms and can run on almost all UNIX based system. Rsnapshot uses only configured number of snapshots, so that the disk space won't grow after the certain limit is reached. Rsnapshot also reduces the disk space required for backup as rsnapshot uses hard links extensively.

Also see tutorial Rsync exclude directory example to exclude files and directories while executing the backup task with rsync.

Install rsnapshot

The following installation is performed on CentOS 7. There will be a little difference in installing and configuring rsnapshot on other distribution of Linux and UNIX.

You can either install rsnapshot directly on your system or you can download the archive file from the net, extract it and then install it. In this tutorial you will see both way of installing rsnapshot.

Installing rsnapshot directly

The below command will install rsnapshot directly on the system.

# yum -y install rsnapshot

Download rsnapshot

Change the directory to opt and download rsnapshot. See the below example.

# cd /etc/opt
# wget

To download other version of Rsnapshot go to archive and copy the link location.
Also See: wget command example  in Linux

# tar xvfz rsnapshot-1.2.3.tar.gz
# cd rsnapshot-1.2.3


# ./configure –sysconfdir=/etc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make sets $(MAKE)... (cached) yes
checking for perl... /usr/bin/perl
checking for rsync... /usr/bin/rsync
checking for cp... /usr/bin/cp
checking for rm... /usr/bin/rm
checking for ssh... /usr/bin/ssh
checking for lvcreate... /usr/sbin/lvcreate
checking for lvremove... /usr/sbin/lvremove
checking for mount... /usr/bin/mount
checking for umount... /usr/bin/umount
checking for logger... /usr/bin/logger
checking for du... /usr/bin/du
configure: creating ./config.status
config.status: creating Makefile
config.status: creating rsnapshot
config.status: creating rsnapshot-diff
config.status: creating rsnapshot.conf.default
config.status: creating t/link-dest_-t_when_only_one_snapshot/link-dest_-t_when_only_one_snapshot.t
config.status: creating t/link-dest_-t_when_only_one_snapshot/conf/link-dest_-t_when_only_one_snapshot.conf
config.status: creating t/relative_delete_bugfix/relative_delete_bugfix.t
config.status: creating t/relative_delete_bugfix/conf/relative_delete_bugfix.conf
config.status: creating t/snapshot_root_with_space/snapshot_root_with_space.t
config.status: creating t/snapshot_root_with_space/conf/snapshot_root_with_space.conf
config.status: creating t/cmd-post_pre-exec/cmd-post_pre-exec.t
config.status: creating t/cmd-post_pre-exec/conf/pre-false-post-true.conf
config.status: creating t/cmd-post_pre-exec/conf/pre-true-post-true.conf
config.status: creating t/cmd-post_pre-exec/conf/pre-true-post-false.conf
config.status: creating t/cmd-post_pre-exec/conf/pre-false-post-false.conf
config.status: creating t/
config.status: creating t/backup_exec/conf/backup_exec_fail.conf
config.status: creating t/backup_exec/conf/backup_exec.conf
config.status: creating t/backup_exec/backup_exec.t
config.status: creating t/rsync-exitcode/rsync-exitcode.t
config.status: creating t/rsync-exitcode/conf/rsync-exitcode-good.conf
config.status: creating t/rsync-exitcode/conf/rsync-exitcode-bad.conf
config.status: creating t/configtest/configtest.t
config.status: creating t/configtest/conf/configtest.conf
config.status: creating t/rsync/rsync.t
config.status: creating t/rsync/conf/rsync.conf
config.status: creating t/gnu_cp/gnu_cp.t
config.status: creating t/gnu_cp/conf/gnu_cp.conf
config.status: creating t/ssh_args/conf/ssh_args.conf
config.status: creating t/ssh_args/ssh_args.t
# make install

Configure rsnapshot

Copy your rsnapshot.conf.default file. If default file is not exist, create a file and name it 'rsnapshot.conf.default' and copy your rsnapshot.conf file to default.
I am considering here that rsnapshot default file exist in your system. Now execute the below command.

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

To use rsnapshot you need to edit the configuration file. Open 'rsnapshot.conf' file and uncomment the following lines.

# vi /etc/rsnapshot.conf
cmd_cp /usr/bin/cp
cmd_rsync /usr/bin/rsync
cmd_ssh /usr/bin/ssh
cmd_logger /usr/bin/logger
cmd_du /usr/bin/du
logfile /var/log/rsnapshot

Functionality of the above uncommented lines.

It makes recursive copies of directories. It must be enabled. If you are using it on Linux uncomment it, however if you are using it in IRIX, Solaries, BSD or some other UNIX system, you should leave the line commented out.

This line must be commented out for the program to work.

If ssh is installed and enabled in your system, uncomment this line to take remote ssh backup over rsync. But if you have a plan to take backup of your localsystem, then leave this line commented out.

Uncomment this line to enable syslog support in rsnapshot.

Uncommenting this line makes rsnapshot enabled to generate actual reports of disk usage with the help of DU tool.

Uncomment this line to specify how you plan to take your backups, hourly, daily, weekly or monthly. You can uncomment the line top specify the interval according to your needs.

By uncommenting it you will enable the file to write log data to it. Rsnapshot will use the specified file to write its log data.

Configure Backup path

Assign source backup directory and destination backup. By default there is already a backup script. You can change the source path of the backup according to your needs. However all your backup will be stored in a directory /.snapshots. you can edit where you want to take your backup by editting the following line.

# vi /etc/rsnapshot.conf
snapshot_root  /backup_mail/

Change the source directory which you want to take backup by editing following line.

# vi /etc/rsnapshot.conf
backup  /etc/   localhost/

Test Configuration

# rsnapshot configtest
Syntax OK

Verify rsnapshot backup configuration

You can configure backup intervals in rsnapshot by uncommenting intervals in 'rsnapshot.conf' file. The intervals are hourly, daily, weekly and monthly. Verify the configuration by using the following command.

Verify hourly backup configuration

# rsnapshot -t hourly

echo 19367 > /var/run/ 
/usr/bin/cp -al /.snapshots/hourly.0 /.snapshots/hourly.1 
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
 /root/Maildir/ /.snapshots/hourly.0/backup_maildir/ 
touch /.snapshots/hourly.0/

Verify daily backup configuration

# rsnapshot -t daily

echo 19379 > /var/run/ 
/.snapshots/hourly.5 not present (yet), nothing to copy

Verify weekly backup configuration

# rsnapshot -t weekly

echo 19391 > /var/run/ 
/.snapshots/daily.6 not present (yet), nothing to copy
Verify monthly backup configuration
By default monthly interval is disabled. So you will get the error.
# rsnapshot -t monthly

echo 19479 > /var/run/ 
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot -t monthly 
ERROR: Interval "monthly" unknown, check /etc/rsnapshot.conf

Verify rsnapshot job

By default the backup taken by rsnapshot is stored in the directory /.snapshots. Before automating the task you can check it manually if rsnapshot is working or not. Run the below command.

# /usr/local/bin/rsnapshot hourly

Now check the directory for backups. It should so the below output.

# ls -al /.snapshots/
total 4
drwxr-xr-x 3 root root 4096 Sep 12 02:54 hourly.0

Automate the task

You can automate the task by making the cron job entry into crontab. See the below example.

# crontab -e
0 */6 * * * /usr/local/bin/rsnapshot hourly
10 02 * * * /usr/local/bin/rsnapshot daily
05 03 * * * /usr/local/bin/rsnapshot weekly

To confirm your crontab is set properly, type the below command. It will show the list of crontab process running on your computer.
Also see how to use : crontab & simple cron job for Linux admin

# crontab -l

For more detail and options with rsnapshot, see the man page of rsnapshot.

# man rsnapshot

This is it with the tutorial Rsnapshot-Rsync based tutorial to take backups. See Rsync exclude-from tutorial to exclude folders and files while taking backup.

You may also like

Rsync passwordless ssh login in Linux and UNIX

Download Our Free eBook now

Linux and UNIX Shell scripting ebook

Be the first to comment

Leave a Reply

Your email address will not be published.