Automated Data backup of Ubuntu Linux using Remote Backup software rsnapshot in Debian
rsnapshot is a software written in Perl to make backup of local and remote file system. The well proven rsync is behind this utility. rsnapshot does not need root user intervention to restore the data of a normal user. It does not take much space in your Backup server. It can be easily automated (scheduled) to make life easier. Just setup once and forget it configuration. Basically it takes snapshot of file system (or a part of) in regular interval such as hourly, daily, weekly and monthly. This can be configured easily through a simple text based configuration file.
The above task can be setup in a few easy steps in a few minutes. Two major tasks are configuring rsnapshot and openssh automatic login. To make the backup automatically, we need to automate the remote login in a secured way. This can be done through openssh tools. This scenario depicts backup of desktop (assuming that IP address is 192.168.0.100) data to a backup server. My desktop runs on Ubuntu 10.04 and backup server runs on Debian Squeeze.
Step-1. Install secure shell package (assuming that default installtion of Ubuntu installs openssh-client):
$ sudo apt-get install openssh-server
Step-2. List down the users who needs backup, directories to be back up and directories/files to be excluded from backup. In this case here is the plan:
User: blackgod – To backup: /home/blackgod – To exclude: /home/blackgod/DownloadsUser: udhaya – To backup: /home/udhaya – To exclude: none
Step-3. Login as above user and create a SSH key pair using “ssh-keygen -t rsa” command. Don’t enter any passphrase when it is prompted. This is to enabled automatic remote login from backup server. Accept the default paths to store the keys. This process to be repeated for all above users.
$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/home/blackgod/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/blackgod/.ssh/id_rsa.Your public key has been saved in /home/blackgod/.ssh/id_rsa.pub.
Backup server configuration:
Login as root user.
Step-1. Install rsnapshot and secure shell client packages.
# apt-get install rsnapshot openssh-client
Step-2. Now update the server with Public key generated in desktop. This process to be repeated for all users in desktop who needs backup. This can be done with following command running from server.
# ssh-copy-id -i ~/.ssh/id_rsa.pub email@example.com
The above command will prompt for blackgod’s password, enter the same. This will fetch the public key and store it under /root/.ssh/ directory.
Step-3. Now it is time to configure rsnapshot. You can find /etc/rsnapshot.conf file which is a simple text configuration file with good default values. The following are most important and useful configuration lines in my setup – this is for your reference. You can enable these lines and change according to your need. You are warned that this configuration file takes only tab as field seperator.
1. I am setting where to backup my data in server. Ensure that this path (file system) has enough space to accomodate data backup.
2. Here I set backup interval as once in 4 hours (6 backups in a day), 7 daily backups in a week, 4 weekly backups and 3 monthly backups.
interval hourly 6interval daily 7interval weekly 4interval monthly 3
3. The below log configuration is much handy during initial setup. So let’s do it.
verbose 2loglevel 3logfile /var/log/rsnapshot.log
4. To avoid two instances of rsnapshot which may mess up the file.
5. To exclude “Downloads” directory from backup.
6. The most important is to configure the data to be backup.
backup firstname.lastname@example.org:/home/blackgod/ laptopbackup email@example.com:/home/udhaya/ laptop
You can download my /etc/rsnapshot.conf for your reference in the below link.
/etc/rsnapshot.conf (7.3 KiB, 769 hits)
Step-4. Now we have to configure cron to make backup automatically. There is a default configuration file called /etc/cron.d/rsnapshot as below. Here is my configuration.
0 */4 * * * root /usr/bin/rsnapshot hourly30 3 * * * root /usr/bin/rsnapshot daily0 3 * * 1 root /usr/bin/rsnapshot weekly30 2 1 * * root /usr/bin/rsnapshot monthly
You can download my /etc/cron.d/rsnapshot for your reference in the below link.
/etc/cron.d/rsnapshot (470 bytes, 575 hits)
Refer here if you want to play with this scheduler configuration file.
Step-5. Initiating the first backup. Just start a manual hourly backup to kick start backup. This may take a long time depending on your data size, hardisk performance, network speed, etc.
# rsnaphot hourly