The following Rsnapshot Ubuntu guide walks you through the process of setting up a fully automated Ubuntu backup solution that meets the following requirements:
- Secure – Data is transfered securely using encryption
- Automated – Runs each day without any user interaction
You can think of Rsnapshot like Apple Time Machine, but on the command line, syncing only what has changed each day and creating snapshots and uses hard links to the old unchanged files to minimize disk space consumption (kind of like a poor mans netaps).
Another advantage of rsnapshot is that it logs into remote servers and pulls the data back over SSH, which means the backup server can sit behind a firewall with no ports forwarded in, this is very important as the server is going to be authenticating to other servers via ssh keys without passphrases.
For more info check out Rsnapshot
Rsnapshot Ubuntu install guide
The following guide walks you through the process of installing Rsnapshot on Ubuntu Linux.
Login as root (or sudo -s if you’re on Ubuntu)
This will install Rsnapshot and pull down any packages it depends on. Open up the file “/etc/rsnapshot.conf” with you’re chosen text editor (I use vi), lets take a look at the first section “snapshot_root” this is the location where Rsnapshot stores it’s backups. By default it places them in the root directory, but I have changed mine to “/backup/snapshots/”.
1 2 3
Next I uncommented “no_create_root 1” this stops rsnapshot creating the snapshot_root dir, (meaning you have to create it yourself). The benefit of this being, if your backing up to a USB drive and you forget to connect it rsnapshot will not backup to the mount point filling your drive space up and possibly causing a server crash (if you have partitioned incorrectly).
1 2 3 4 5
We are using Linux, so uncomment the “cmd_cp” line.
1 2 3 4 5 6
Next uncomment “cmd_ssh” and give it the correct path to the ssh binary.
1 2 3
I uncommented the du option as well, cool little tool that shows you the size of each of your snapshots. (remember if you just did a “du -sh *” in the snapshot dir it would read wrong due to the hard linking).
1 2 3 4 5
This brings us onto Backup Intervals, as you can see I have kept the defaults, so rsnapshot will keep 6 copies of my hourly backup before it starts over writing my old one, 7 copies of my daily backups, 4 of my weekly and 3 monthly backups! Worth noting that rsnapshot will not create the daily.0 backup until hourly.5 has been created in the snapshot_root, the same with weekly and monthly.
1 2 3 4 5 6 7 8 9 10
The defaults for these are normally fine, however I wanted to a bit more verbosity until I am happy the backup system is working. I changed the setting to 4 instead of 3, 4 displays the commands on the command line as if you were entering them by hand, this was good enough for me!
1 2 3 4 5 6 7 8
“logfile”, I uncommented this as logs are always handy for finding out what went wrong :)
1 2 3 4
“exclude” After running my first backup it became apparent that I had a bunch of VMWare disk image files in my home dir, so I excluded them with:
1 2 3 4 5 6 7 8 9
The next thing I configured was the backup points, what I wanted backed up from each of my machines, starting with the localhost.
1 2 3 4 5 6 7 8 9 10 11 12
Now I want to backup my email server “the-death-star”, so I configured my backup server to pull it’s data in over SSH (kinda of like when that Star Destroyer pulled in the Millennium Falcon with it’s tractor beam, yeah… Kind of…).
This is the end of the config file editing, now it’s time to give your config a test with:
This should come back and say “Syntax OK” unless you messed something up, in which case it will tell you the line it errors on, so go back and fix it!
Ubuntu SSH Keys Setup
It’s all great pulling in the data over SSH but we need to be able to login automatically to our remote servers.
I use remote root logins for my servers, as I am backing up files in locations like /etc/passwd which are only readable by root, yes there are ways around this, but I do not want this document to get to complex.
We need to setup SSH keys without passphrases, otherwise we are going to get prompted each time the backup runs for the pass phrase.
Creating SSH keys for key based authentication
Create the key pair, this will create the public and private keys (never give your private key out!).
Accept all the default, just push enter when it asks you for a passphrase
1 2 3 4 5 6
You should now have a set of keys in /root/.ssh/ now we need to copy them to the remote machine we want to login to, in this case the-death-star.techspotting.org so this would be the command:
You will then get prompted for the password for your account on the remote host, go ahead and enter it, ssh-copy-id will then copy the key to the correct dir and sort out the correct file system permissions, cool huh?
Give it a test and make sure it’s working:
If you look in “/etc/cron.d/rsnapshot” you should see a file that looks like this:
1 2 3 4 5 6 7 8 9 10 11
Providing you are happy with the default cron config (which I was) remove the comments so it looks like this:
1 2 3 4 5 6 7 8 9 10 11
Now you have enabled cron to backup your files using rsnapshot, you had better make sure it is going to work!
Check everything looks sane and nothing nasty is going to happen and repeat for daily, weekly, monthly.
Now it’s time for your first backup!
If you have verbosity set to 4 like me (optional), you will be able to see all the files your backing up flying up the screen! The first backup has to move all the file the snapshot_root so this is going to take some time, depending on the speed of your machine / connection, might be a good time to grab another coffee.
You should start to see files in your snapshot_root, after a few weeks you should see a bunch of hourly., daily., weekly.*
Here is what my snapshot_root looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
That concludes LinuxMOZ’s Rsnapshot Ubuntu install guide, don’t forget to subscribe to our RSS on the right for more Linux Guides updates.