Ubuntu Server backup with rsnapshot

I was looking for simple backup software to backup the user data on my Ubuntu NAS. When looking for solutions on Google I came across rsnapshot.  This backup solution uses rsync to sync files to a destination. In my case I attached an external USB drive as backup destination.

Install rsnapshot by running

sudo apt-get install rsnapshot

Next up is the destination folder. I made a new folder on my external harddrive running this command:

sudo mkdir /media/usb0/snapshots

Now for the tricky part: the rsnapshot configuration.. The .conf file is located at /etc/rsnapshot.conf . Please note that if there’s only rsnapshot.conf.default you need to run the following command to get a default configuration file.

sudo cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf

Now edit this file with nano or vi to make some changes. Please make sure to use tabs to seperate your configuration items!

sudo nano /etc/rsnapshot.conf

Set the following items:

  • snapshot_root is the destination folder of your backups. Set it to the folder you created earlier in this post, for example: /media/usb0/snapshots
  • retain alpha, beta, gamma, delta are the backup intervals. You can use alpha as the number of daily backups you want to keep, beta as weekly, gamma as monthly and delta as the number of yearly backups you want to retain.

To specify the folders to back up skip to the BACKUP POINTS / SCRIPTS section of the conf file.

If you want your home directory to be backupped enter the follow line:

backup /home/<yourusername>

Each line, starting with the word backup, can be a source folder for the backup. You can specify as many folders/items as you want.

Now it’s time to test your configuration and run your first backup, execute the following commands:

rsnapshot configtest

rsnapshot alpha

To schedule your backups we need the crontab. There is a useful crontab tool to generate the lines , because the syntax is a little cryptic. Open the link, enter rsnapshot alpha in the command box and select the daily time you want to run the backup. Do the same for rsnapshot beta gamma and delta. To add the backup lines to your crontab do the following:

sudo su

crontab -e

0 23 * * * rsnapshot alpha >/dev/null 2>&1
0 6 1 * * * rsnapshot beta >/dev/null 2>&1
….

That’s it! Backups are configured to run automagically.