Aug 26 2009
Remote backup with rsnapshot using ssh
Rsnapshot is a remote and local backup tool based on combination of rsync and cp -al. In this tutorial, I will show you how to backup data using this great free and open source backup software. Rsnapshot is the most efficient backup application when it comes to conserving disk space because it backups up only changed or new files and creates is hard links to the old ones. It runs on both Linux and Windows. You can backup Windows, Linux and pretty much anything that can run rsync. It is a lot faster than incremental or differential backups when restoring. You can read more about it at rsnapshot.org.
Compiling rsnapshot from sources:
We will download it to our home directory and install it in /opt on a server named backup-server and we will backup /etc/ and /var/www/html found on server mars. I am using Debian for this example but it should work on any Linux distribution.
On Venus, download rsnapshot.
wget http://rsnapshot.org/downloads/rsnapshot-1.3.1.tar.gz
and then extract it
tar -xzvf rsnapshot-1.3.1.tar.gz
We will tell configure script that we want to install it in /opt and that the configuration files would be in /etc
./configure --prefix=/opt --sysconfdir=/etc
(In fact, we do not even need –sysconfdir=/etc because we will specify the configuration file directly when we run it)
Now, we compile
make test
and then install it as root
sudo make install
or
su root make install
That’s it. Rsnapshot is now compiled and installed.
Configuring rsnapshot:
I prefer to have configuration files for all servers in one location so I create /etc/rsnapshot and put each server’s files there
Create a file
nano /etc/rsnapsnapshot/mars-daily.conf
and paste the following:
config_version 1.2 snapshot_root /var/backup/ cmd_cp /bin/cp cmd_rm /bin/rm cmd_rsync /usr/bin/rsync cmd_ssh /usr/bin/ssh cmd_logger /usr/bin/logger cmd_du /usr/bin/du cmd_rsnapshot_diff /opt/bin/rsnapshot-diff interval daily 120 verbose 3 loglevel 3 logfile /var/log/rsnapshot/mars-daily.log lockfile /var/run/rsnapshotmars-daily.pid exclude logs backup root@mars:/etc/ backup root@mars:/var/www/html/
I will explain what they all do. The first line shows configuration version. snapshot_root is where the backed up files will be placed. Next seven lines show the location of cp, rm, rsync, ssh, logger, du and rsnapshot_diff respectively. Interval daily 120 means that 120 backups will kept and daily is the name of the interval. We will use this when we run rnsapshot manually or from cron using this configuration file. Next two lines show how much information rsnapshot will spit out and how much will be logged. Then we have the log file location. I like to keep different logs for each server being backed up for monitoring purposes.
Exclude keyword is used to prevent any directories or files from being backed up. Here we do not want to backup logs directory inside to-be backed up directories which is specified next.
Next we specify what to backup. Here we are backing up /etc/ and /var/www/html/ directories
Now its time to test the configuration file for any errors
rsnapshot configtest
If you see any errors, check the file for any spaces in the file. You should have tabs instead of spaces.
Run the following to backup the specified directories from mars
/opt/bin/rsnapshot -c /etc/rsnapsnapshot/mars-daily.conf daily
where -c specifies which configuration file to use and daily is the internal name we set up in the configuration file above.
If you don not see any errors, everything is good.
Now backing up any new server would be a lot easier.
Say we have a new server, jupitor, to be backed up, copy the existing configuration file
cp /etc/rsnapsnapshot/mars-daily.conf /etc/rsnapsnapshot/jupitor-daily.conf
Next change the following in the new file, replacing mars with jupitor ,so we have separate pid and log files. Also exclude anything you want and specify backup directories .
logfile /var/log/rsnapshot/mars-daily.log
lockfile /var/run/rsnapshotmars-daily.pid
exclude logs
backup root@mars:/etc/
backup root@mars:/var/www/html/
Run the following to backup jupitor
/opt/bin/rsnapshot -c /etc/rsnapsnapshot/jupitor-daily.conf daily
In another tutorial I will show you how to automate the backup process
















