How to Install Rsnapshot in Linux

To Install Rsnapshot in Linux

Rsnapshot is an open source local/remote file backup utility based on rsync. It is written in Perl language. It takes periodic snapshots of local machines and remote machines over ssh. The installation of Rsnapshot is discussed in this article.

Requirements

Ubuntu is the local system and its host name is linuxhelp
CentOS is the Remote system and its host name is linuxhelp2.

To install Rsnapshot Backup server

Run the following command to install rsnapshot, rsync in Ubuntu.

user1@linuxhelp ~$ sudo apt-get install rsnapshot rsync
[sudo] password for user1: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libavahi-client-dev libavahi-common-dev libavahi-compat-libdnssd1 libdbus-1-dev
  libntdb1 libruby2.1 libyaml-0-2 python-ntdb ruby2.1 rubygems-integration
.
.
.
Setting up liblchown-perl (1.01-3) ...
Setting up rsnapshot (1.4.0-1) ...

To install rsnapshot in CentOS

Install and enable EPEL in CentOS by executing the below command.

[root@linuxhelp2 ~]# yum install epel-release -y 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.mirror.net.in
 * extras: centos.mirror.net.in
 * updates: centos.mirror.net.in
Resolving Dependencies
-->  Running transaction check
--->  Package epel-release.noarch 0:7-6 will be installed
.
.
.
Installed:
  epel-release.noarch 0:7-6 


Run the following command to install rsnapshot and rsync package.

[root@ linuxhelp2 ~]# yum install rsync rsnapshot -y 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * epel: epel.mirror.net.in
 * extras: centos.webwerks.com
 * updates: centos.webwerks.com
Package rsync-3.0.9-17.el7.x86_64 already installed and latest version
Resolving Dependencies
-->  Running transaction check
--->  Package rsnapshot.noarch 0:1.3.1-13.el7 will be installed
.
.
.
Installed:
  rsnapshot.noarch 0:1.3.1-13.el7                                                        

Complete!              


Now create backup directory in the backup server.

user1@linuxhelp:~$ sudo mkdir /home/backup
user1@linuxhelp:~$ sudo mkdir /home/backup/local
user1@linuxhelp:~$ sudo mkdir /home/backup/remote

To configure

Open rsnapshot.conf file using your favourite editor.

user1@linuxhelp:~$ vim /etc/rsnapshot.conf
Edit the config file as follows.

snapshot_root   /home/backup
" cmd_ssh"  allows us to take remote backups over SSH.
cmd_ssh         /usr/bin/ssh
To set the backup location just edit the below parameter. 
#########################################
#     BACKUP LEVELS / INTERVALS         #
# Must be unique and in ascending order #
# e.g. alpha, beta, gamma, etc.         #
#########################################
interval        hourly          6
interval        daily           7
interval        weekly          4
Here you may add your remote and local backup directories that you need to backup.
Local Directories backup
The backup entry will be looks like below,
# LOCALHOST
backup  /home/          local/
backup  /etc/           local/
backup  /usr/local/     local/
Remote Directories backup
You have to mention the server and the remote directories what you need to take backup.
backup  root@192.168.5.190:/home/       remote/

To verify

Execute the below command to verify Rsnapshot configuration.

user1@linuxhelp:~$ sudo rsnapshot configtest
Syntax OK

To run Manually

Now run the following command to take backup manually. Here, we are taking a hourly backup.

user1@linuxhelp:~$ sudo rsnapshot hourly
root@192.168.5.190' s password:


Then check the backup file.

user1@linuxhelp:~$ sudo ls -l /home/backup
total 12
drwxr-xr-x 4 root root 4096 May 12 12:29 hourly.0
drwxr-xr-x 2 root root 4096 May 12 12:11 local
drwxr-xr-x 2 root root 4096 May 12 12:11 remote

To automate the process

First schedule the rsnapshot to be executed at certain intervals from Cron. By default, rsnapshot will be located under ' /etc/cron.d/rsnapshot' , if it does not exist create it and include the below lines.

 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

To restore the backup

If you want to restore a backup of local system, navigate to root backup directory.

user1@linuxhelp:~$ cd /home/backup
user1@linuxhelp:/home/backup$ ls
hourly.0  local  remote


Copy the picture folder from root backup directory to ' /home/user1/file' directory of local system

user1@linuxhelp:/home/backup$ sudo cp -r hourly.0/local/home/user1/Pictures/ /home/user1/file/


Verify whether the backup file exists or not.

user1@linuxhelp:/home/backup$ ls -l /home/user1/file/
total 4
drwxr-xr-x 2 root root 4096 May 12 12:34 Pictures


Now restore the backup to remote system

user1@linuxhelp:/home/backup$ sudo scp -r hourly.0/local/home/user1/Pictures/ root@192.168.5.190:/mnt/
root@192.168.5.190' s password:


Now verify the backup file exists in the remote system.

[root@linuxhelp2 /]# cd /mnt/
[root@linuxhelp2 mnt]# ls Pictures


We have successfully restored the backup to the remote system.

Tag : rsnapshot
FAQ
Q
While creating Partition, where to select for LVM partition type?
A
You can select them under create partition section and enable LVM radio button.
Q
Where can I find network configuration in command line on Centos 6.5?
A
You can find them under "/etc/sysconfig/network-scripts/ifcfg-interface-name"
Q
Reports dont delivered to my email work? Why is that so?
A
you must have sendmail or postfix installed on your server to send/receive mails
Q
Is they consume lots of disk space wile taking backups?
A
Try using hardlinks for that issue
Q
Is it same as disaster recovery backup solution ?
A
Yes rsnapshot works same as disaster recovery backup solution