The Backup Pi

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

5 min read

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 quarantine gave me enough free time to go through some of my items in 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.

The Raspberry Pi is a credit card-sized computer which will be perfect for backing files once per day. It's also roughly the size of an 2.5 inch hard drive, which makes them perfect to stack on top of each other and form a nice looking "backup tower".

My Raspberry Pi is old. The B+ model was released in 2014 and it has a 700 MHz processor with 512 Mb of ram. It's too old and 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.

I did some research on the available backup solutions. 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)

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. Enter CPANMinus. It's a modern alternative to cpan which is aware of the available memory during module installation.

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

Then install the required 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.

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}

rsync is a great tool so I'll use it as a backup method. 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)

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.

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

Install hdparm to configure spinup/spindown time for HDDs.

/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

sudo service hdparm restart

Setup email by running

sudo apt install ssmtp

This replaces the default sendmail command with a easier to use alternative that only supports SMTP Create an account in sendinblue.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]
Back to Top