The Backup Pi

Backup your important files to a Raspberry Pi and a couple of hard drives

6 min read

The problem

A backup system has always been something I've neglected, even though I suffered a big data loss due to hard-drive failure a few years ago, I didn't bother to look into getting one. The COVID-19 quarantine gave me enough free time to go through a couple of items on my TODO list and a backup system looked like a low hanging fruit, so I gave it a shot.

There are a ton of cloud-based options with varying degrees of privacy and data reliability, however me being as I am, I took a more DIY approach. I had an old Raspberry Pi and two 500GB hard drives laying around, so I used them for this project.

My Raspberry Pi is old. I have the B+ model which was released in 2014 and has a 700MHz processor with 512Mb of ram. It's too slow to run a full desktop environment, but it's perfect for a headless Linux server. I flashed it with Raspbian, a version of Debian Linux specifically made for the Raspberry Pi.

Requirements

Having the old Raspberry Pi's limitations in mind, I looked for a suitable software to perform the backups. The most important criteria for me was:

  • Open source
  • Able to backup multiple PCs
  • Has a Web interface
  • Incremental backups
  • Ability to browse and restore specific files (as opposed to whole backups)

Fortunately BackupPC has all these features and more.

Installing BackupPC

Raspbian has an old version of BackupPC so I grabbed the latest release from the Github page.

# Grab the latest release of BackupPC from https://github.com/backuppc/backuppc/releases/latest
# At the time of writing it's at version 4.3.2
wget https://github.com/backuppc/backuppc/releases/download/4.3.2/BackupPC-4.3.2.tar.gz
# Extract the source
tar -xf BackupPC-4.3.2.tar.gz
cd BackupPC-4.3.2
# Run the configuration procedure
perl configure.pl

The configuration procedure does a couple of dependency checks and noted that I needed to install the perl module BackupPC::XS. Naturally, it wasn't that easy. cpan was throwing out of memory errors and couldn't install the module due to the RPI's small ram. Enter CPANMinus. It's a modern alternative to cpan which is aware of the available system memory during module installation.

You can install CPANMinus with the following commands:

curl -L https://cpanmin.us/ -o cpanm
sudo mv cpanm /usr/local/bin/
sudo chmod +x /usr/local/bin/cpanm

Then install the "BackupPC:XS" module by running:

sudo cpanm --verbose install "BackupPC::XS"

Use the --verbose flag because it seems cpanm doesn't handle module dependencies and you have to install them yourself. It warns you that you're missing dependencies and then goes ahead and continues to build the module, which unsurprisingly fails. Weird.

I needed to install a few more perl modules - SCGI and inc::latest before BackupPC worked.

I enjoy using nginx so this was my HTTP server of choice for the project. Following BackupPC's documentation, I created the config file in /etc/nginx/sites-available/backuppc.lan and symlinked it to /etc/nginx/sites-enabled/backuppc.lan.

Securing the web interface

Generate a password with htpasswd and place it in /etc/nginx/conf.d/backuppc.users like so:

username:generated_password

Be sure to match the scgi_pass directive's port to the config variable $Conf{SCGIServerPort}

Using rsync for file transfers

rsync is a great tool so I'll use it as the transfer method for BackupPC. I set $Conf{XferMethod} to rsync and downloaded a special build of rsync, called rsync-bpc, that was made specifically for BackupPC. rsync-bpc is fully compatible with rsync so it needs to be installed only on the backup server. Clients can use the regular version of rsync.

# Grab the latest release
wget https://github.com/backuppc/rsync-bpc/releases/download/3.1.2.1/rsync-bpc-3.1.2.1.tar.gz
tar -xf rsync-bpc-3.1.2.1.tar.gz
cd rsync-bpc-3.1.2.1
./configure
make
make install

Naturally, make fails.

lib/sysacls.c:2761:2: error: #error No ACL functions defined for this platform!

This indicates that you have to install the ACL library and it's devel package:

sudo apt install libacl1 libacl1-dev
# Don't forget to re-run the configuration step!
./configure

Don't forget to set $Conf{RsyncBackupPCPath} to the new installed binary (/usr/local/bin/rsync_bpc).

One thing to note is that if you select rsync as a backup method, you'll need to create ssh keys and give access to the backup server to each PC you'll be backing up.

  1. Check and enable sshd on the client machine
  2. When configuring the transfer opts (xfer tab) in BackupPC, set RsyncSshArgs to the correct user (usually not root)

Edit $Conf{RsyncSshArgs} to use the correct user if you're not using root!

The BackupPC config has a global section located in /etc/BackupPC/config.pl and a per-host config file in /etc/BackupPC/pc/hostname.pl. Both configuration options can be edited via the admin panel or via the config files directly.

Configuring HDD spindown time

Install hdparm to configure spinup/spindown time for HDDs. Open /etc/hdparm.conf and add the following configuration for persistence:

/dev/sda {
write_cache = on
spindown_time = 250
}

250 is 5 hours based on http://www.howtoeverything.net/linux/hardware/list-timeout-values-hdparm-s

An alternative way for persisting the configuration is via udev rules.

Setup email notifications

A good idea is to set up email notifications in case something happens to the system, e.g. a hard drive fails.

Setup sending email by smtp by running:

sudo apt install ssmtp

This replaces the default sendmail command with a easier to use alternative that only supports SMTP Create a free account in brevo.com (AND VERIFY IT!). Add credentials in /etc/ssmtp/ssmtp.conf and try sending an email by running

echo "Test 1 from $(hostname -f)"|mail -s "Test 1 $(hostname -f)" [email protected]

Test BackupPC emails by running

/usr/local/BackupPC/bin/BackupPC_sendEmail -u [email protected]

Connecting the drives

Connecting SATA drives via a SATA-to-USB cable is easy and straightforward, but has a little caveat. You need to connect a USB powered hub to the RPi otherwise the drives would pull power directly from the RPi and cause all kinds of trouble.

Backup redundancy

It's always a good idea to add at least a second hard drive and setup a RAID 1 mirroring, so the data is available on two drives instead of only one.

Finishing up

This was a fun little weekend project which is actually useful. A nice way to organize the drives is this module 3D printed rack which can grow along with the number of drives as you add them.

:wq
Back to Top