Skip to main content

Raspberry Pi as an rSnapshot-based backup appliance

"rsnapshot" is a file system backup utility based on rsync. It makes snapshots of your file system(s) at different points in time, which are stored as a time series, giving you multiple restore points. rsnapshot creates the illusion of multiple full backups while only taking up the space of one full backup plus changes, by using hard links to reference files that already exist on disk. When coupled with SSH and key-based authentication, remote file systems can be backed up securely as well.

I built an automatic backup appliance for my webservers using a Raspberry Pi 4 and the excellent Argon One M.2 case. This case allows installation of an M.2 SATA SSD, giving vastly faster, larger and more reliable storage compared to a microSD card. The case is metal and acts as a passive heat sink, making contact with the processor via a thermal pad. After configuring the target machines and desired backup and rotation frequency, use the Pi's crontab to schedule running of the rsnapshot script.

I came across three Pi-specific problems while setting this up:

  1. rsnapshot jobs must be scheduled using the root user crontab (not the pi user), so use sudo crontab -e to set up the jobs.
  2. When a scheduled rsnapshot job tries to login to remote machines over SSH, it will also do so as root, which by default doesn't have any keys and will fail. You probably can set up keys for the root user, but the approach I used was to specify that SSH login should use the pi identity and keys, which I had already set up.
sudo nano /etc/ssh/ssh_config

...

#Add Hosts below
Host tuskfish.biz
HostName tuskfish.biz
User XXXXX
Port XXXXX
IdentityFile /home/pi/.ssh/XXXXX

#Add more hosts as required
  1. If you are using a custom SSH port, you need to specify this in the rsnapshot configuration file (/etc/rsnapshot.conf). There is a global option to do this but I could not get it working. So I ended up specifying it manually for each backup point, as per the example below.
#Backup point for a webserver where XXXXX is your custom SSH port.
backup    [email protected]:/home/user/path/to/remote/files/    localdirectory/    ssh_args=-pXXXXX

Now you don't need an SSD to do this of course but microSD cards are not the most reliable storage medium. And you should never depend on a single backup mechanism, eg. I also run rsnapshot on a separate NAS box and maintain an offline backup on an external hard disk.

I expect that a Pi 3 would also have sufficient resources to run rsnapshot, although I have not tested it. If you try it out let me know.

Copyright, all rights reserved.