A Raspberry Pi and Bacula makes a great backup appliance for a small/home office, or a GeekLab. This is the first part covering an overview of Bacula, the hardware components and their assembly and initial installation of Bacula and some pre-requisites.

In my work life the importance of having a secure reliable and proven backup and restore capability comes up with every project. It's a sad fact of life that even the best maintained equipment will eventually fail, and when it comes to IT there are many and varied threats to the integrity of your data, from the accidental delete, the badly planned or ill-informed change through to deliberate attack and data destruction.

If all else fails having a backup is you last best chance to fix things. And yes, I've been caught out personally with the loss of months of irreplaceable photographs and had a couple of extremely close calls professionally where backups were not working properly nearly resulting in what would have been a career-limiting result. And I've also had several occasions where having a backup has saved the day and quite possibly other people's continued employment too.

So it's no surprise that I take backup seriously even in a home environment and since I have the GeekLab there's no excuse not to do it properly.

Bacula Pi

Ever since GeekLab v2 I've been using the community edition of the Bacula application, at first with a DAT-72 tape drive and now with a pair of removable USB HDDs that are used in rotation. Given that I'm mostly working from a home office these days, if something catastrophic enough to get the house and both backup disks and my archives occurs then I'm probably not going to care about getting anything back online again.

The Bacula Pi backup solution is based on:

  • Raspberry Pi 2B
  • Ubuntu 20.04 LTS
  • Bacula 9.4.2
  • Portable USB hard drives for backup data storage
  • A customised Bacula configuration managed in git
  • Client-side encryption of backup data
  • Client agents deployed via an Ansible role

I'm currently using two Transcend ruggedised portable USB disks for backup storage, which could be extended to as many as you feel is sensible. The disks are used for a week at a time and then swapped over, with the other one kept safe away from my home office. I keep a strict rule that both disks can never be in the same place at the same time. A separate backup of the master data encryption key is also maintained in a 3rd location.

I have been using Bacula since version 5 in a few different configurations. Bacula is implemented as two main services, a catalog database and then whatever agents you need installed on each thing you want to back up. I've settled on running both services and the database on the Raspberry Pi which does mean a lower performance for administration but also means I only have a single critical component to worry about.

Backup Strategy

The current set of backup targets are:

  • Samba AD database
  • Postfix mail server
  • Samba file shares
  • Syncthing shares
  • Nextcloud application, database and data
  • Mezzmo Database
  • Ubuntu and CentOS virtual machines
  • Mint laptops & PCs
  • A Windows PC

All the databases are scripted either to do an export or quiesce as part of their backup job (for example Test Nextcloud 26 Installation), and I still have the config for an Exchange server in my archives although that is now long since retired. Some filesystems also snapshotted (using btrfs or VSS) and the snapshot is used as the backup target to make sure the files remain consistent during backup too.

If you use the commercial edition of Bacula then you also gain access to agents for online backup of various databases. I don't see me needing the likes of SAP HANA for home use any time soon though.

The only thing I can't do a direct backup of is VMware ESXi itself or virtual machine images, neither of which I'm particularly fussed about. I'm using the free ESXi hypervisor which disables write access to all API's and blocks backup applications and while virtual machine images make for a simple restore you have to restore the whole image (unless you are using some very expensive enterprise backup solutions).

Example Backup Schedule
Frequency Retention Target
Annual 1 year

Offline export of VMs via ESXi console to enable quick restore.

6 months 1 year

Manual copy of latest full backups to Archive disk

Every 5 weeks 3 Months

Automatic copy of oldest Bacula jobs to Long Term pool of weekly backup disk

Weekly 6 weeks

Full backup of OS, database and file shares

Daily 6 weeks

Incremental backup of OS, database and file shares

With this rotation I should be able to restore any database or any file back to any given night in the previous six weeks, plus at approximately monthly intervals for upto 3 months.

If I should lose the entire ESXi server that would be a manual reinstall of ESXi and then reimport the VMs via the console then apply the latest weekly and incremental backups to bring them back up to date.

I'm currently using about half the capacity of each 2TB disks so I could extend the retention period significantly if I wanted to, assuming the amount of data in the backups stays at a similar volume.

I also periodically test the restore process just to make sure I could do so in the event of something interesting happening.

The backup data is encrypted (128 bit AES-CBC) on the target before being sent to the Bacula server, so even if somebody gets hold of the backup disks they're (supposedly) useless. Bacula uses public key cryptography and the the private keys required to decrypt the backup data are not held on the disks and not stored with them either.

Hardware

My BaculaPi is based on the following hardware

Qty Brand Part No Description Purpose
1 Raspberry Pi Pi 2B RPi 2B Host for Bacula
1 Raspberry Pi ? Black plastic case for RPi 2B Keep sticky fingers off the RPi
1 CPC? ? Set of self-adhesive heatsinks for RPi 2B Improve cooling, especially during the summer months when my office gets a bit warm
1 Transcend SSD370S 64 GB 2.5" SATA SSD Running Ubuntu 20.04 LTS, PostgreSQL database and Bacula
1 Transcend?   16 GB microSD Booting the RPi, mostly unused as you can't get 1GB cards any more.
1 Iitrust   2.5" SATA to USB adaptor Connects OS SSD to RPi
1 Anker A7515 7 port USB 3.0 data hub with 3 smart charging ports Powers the RPi and also connects data disks to RPi from a single mains adaptor. Runs as a USB2 device of course.
2 Transcend TS2TSJ25M3S 2TB ruggedised portable USB disk Store backup data
1     USB A to micro-B cable Connect RPi to a power port on the USB hub
1     Cat 5 UTP network cable Connect RPI to network

 

I don't have all the component details to hand but they're probably in emails somewhere and I'll update if I find them. To be honest you don't need the exact same components though.  The SSD and adapter were from April 2018 and USB hub from November 2018, and at time of writing the SSD and hub was still available. There's a few alternatives for the USB SSD adaptor too so that shouldn't be a problem. The Raspberry Pi 2B is scheduled to stay in production for several years yet as well. The network and USB cables were from my spares box but these are widely available.

I also have some sketches of nice box to put it all in that I will get around to making one day. A keyboard and monitor are useful for the initial setup and troubleshooting although routine support and operation is over SSH from another PC.

The first version of BaculaPi used the microSD card to run everything for several months which was a little slow but it still worked. Running a relational database on a MicroSD card is  definitely not recommended for long-term use, although maybe not as big a concern with the A1-rated cards that are now available. The first attempt to use an SSD, just for the database, was a disaster. It was a 64 GB Kingspec drive from Amazon that ran hot to the touch and corrupted data within an hour of each installation attempt. Amazon gave a full refund and it went in the recycling and I purchased the Transcend unit instead which has worked perfectly ever since. The USB to SATA adaptor can also be a bit sensitive to disturbance and doesn't like being plugged into a USB3 socket on my desktop PC which isn't an issue here but did cause a few issues during preparation.

The Raspberry Pi has limited power available for USB devices and definitely needs a powered USB hub for external HDDs which can draw nearly an amp each. The fun part was finding a powered USB hub that could connect devices to the Pi and also supply power to the Pi itself so I only need a single power supply for everything. I spent a lot of time reading through forums and reviews as apparently some hubs really don't like this configuration. The Anker hub has three separate USB charge-only connectors that can supply 2.1A which is enough to run the Raspberry Pi 2B and maybe the fact they're not "real" USB connectors is why it works.

The Pi is able to run an SSD (and the adaptor) direct from its own USB ports. While it would be nice to not have the USB hub, even today 2TB portable SSDs are still very expensive, I'm pretty sure they weren't even available at the time I first built this and I'm not convinced there's enough power capacity to let me plug a second SSD directly into the Raspberry Pi anyway, let alone a 3rd. Besides, the hub gives flexibility if want to use separate disks for different backup pools in future and of course it means I can connect the archive disk for the annual copies.

The Raspberry Pi 2B has been produced in at least 2 different versions,

  • Up to revision 1.1 it uses the BCM2836 chip which has four 32-bit Cortex A7 cores and needs the Ubuntu ARMHF architecture
  • From revision 1.2 it uses the BCM2837 chip which has four 64-bit Cortex A53 cores and supports the ARM-64 Ubuntu architecture, and I believe ARMHF too.

I have a Pi 2B rev. 1.1 device, and this configuration should work for any future Pi (and possibly the clones) although some differences are to be expected. The later editions are capable of booting directly from a USB device and don't need the MicroSD card as an example.

Note: The original Pi could not run Ubuntu. There was a custom build of Debian for them but I don't recall there being a port of Bacula available.

 

Bacula

The Bacula Project has been going since early 2000 (if not earlier) and is currently on release 13. Bacula is released in two versions, a free Community Edition - which I'm using here - and the paid Enterprise Edition which includes support and a whole bunch of additional agents and capabilities far in excess of what I need for my home office and GeekLab. If you're running multiple servers, enterprise applications and reasonably sized databases then it's a different story and you'll probably appreciate the additional capabilities.

Bacula is included in the standard Ubuntu repositories (except for 22.04 LTS for some bizarre reason that I don't think was ever fully explained) and since I'm using Ubuntu 20.04.6 LTS the supplied Bacula version is 9.4.2. Bacula also provide X86 .deb and RPM packages from their site, which are not much use on a Raspberry Pi of course. They make the source code available if you want to build it yourself and instructions on how to compile it but to be honest that's more that I want to deal with right now. As a service to the community Bacula Systems have made the installers for the Windows File agents freely available as well - just register to get them.

Bacula supports a wide variety of backup media. I'm currently using portable hard disks, having previously used a DAT 72 tape drive. A large number of different tape and media libraries are supported as well as some cloud storage services.

By my count there are five components to a Bacula installation:

  • Bacula Director - Controls the system and runs jobs according to a schedule
  • Bacula Storage Daemon(s) - Controls backup devices, reads and writes data from File Daemons / agents
  • Bacula File Daemon(s) and other agents - Read and write data from backup targets, typically running on the target host
  • Database - MySQL or PostgreSQL database with catalog data and runtime state
  • Configuration Files - Configuration of the Director and daemons and the job and target details

Bacula don't count the configuration files as a separate component even though they're essential. They also add the Console and Monitor as a component. I'm not going to argue though, it's their product and doco and the job configurations are technically part of the Director config but the way I've configured things they've got a semi-independent existence which I'll explain later.

You can run the Director and Storage daemons on separate hosts if you want to and the database can also be on a separate server too if you wish. The Director and all Storage Daemons it manages must all be the same version though, along with any File daemons installed on the same hosts as them. When I first started testing Bacula I had the Director and database on an Ubuntu X86 VM and just ran the Storage Daemon on the Raspberry Pi which mostly worked but whenever I had an issue there was always a question of whether this was a genuine bug or related to the differing architectures between these to components.

Any File daemons installed on other hosts can be the same or a lower version than the Directory & Storage Daemons, so you don't have to upgrade everything in one go. It may also be possible to run later versions of File daemons although that's at your own risk. Bacula recommend that you upgrade the Director and Storage Daemons first and then upgrade the File Daemons later. I still have some CentOS 7 hosts running the 5.2.13 File Daemon perfectly well.

There are three other components I use:

  • vChanger : Implements a virtual media changer for removable disks as standard Bacula doesn't handle this too well, at least not in this release.
  • Git : Manage the Bacula configuration files so I can track what's been changed or added and easily test changes and revert bad ones.
  • An Ansible Role for Bacula Client : Automates client deployment, including generation of the encryption keys and uploading an initial config file to the Bacula server as part of my standard VM deployment process.

I made a couple of adjustments to the vChanger config to make sure the backup HDDs were detected and mounted properly if the Pi rebooted while they were connected. Otherwise everything else is standard.

Construction & Installation

Please note this is being written some years after the event so may be a little bit vague in places. And I don't have screenshots.

Hardware Assembly

There's not a lot of assembly required. Everything fits just one way, the fun part is trying to make the cables tidy and make sure the USB SATA adaptor connects firmly and reliably with the SSD. I've been meaning to build a proper case for years but haven't quite got around to it yet. No doubt that will prove to be the biggest challenge of all.

BaculaPi Components
BaculaPi components

With some careful arrangement of cables, some ties and a couple of sticky pads this can be compacted down into a much smaller space - with more room taken up with cables than anything else. It's normal location is between two shelves and it occupies approximately 16 cm x 23 cm x 4 cm. If I ever get to building a case it'll probably end up half the width with the portable drive sat on top. While putting it back after taking this pic I found a better micro-B cable with a 90° adaptor for the Pi power connector. Continuous improvement in action.

Ubuntu Installation

I originally had this running on Ubuntu 18, possibly even 16. I've found notes referencing an upgrade from 19.10 which ended with "Blew it up..." and then a new doc for an Ubuntu 20.04 reinstall. The current version was installed from new and then the old Bacula Catalog database and config was restored from backup. Yes, I backup the backup solution.

Ubuntu was installed by downloading the ubuntu-20.04-preinstalled-server-armhf+raspi.img.xz image for Raspberry Pi 2B from the Ubuntu website, uncompressing it and then writing it to a MicroSD card using the USB Image Write application in Linux Mint. It was then started to allow the initial installation to complete.

I then reconfigured Ubuntu to use the MicroSD just for /boot and /boot/firmware and moved the root filesystem to the SSD. I don't have the detailed notes on that process and given BaculaPi is live recreating that experience for the sake of documentation is not exactly a priority right now.

BaculaPi Filesystem Layout
Media Device Type Size Mount Purpose
MicroSD /dev/mmcblk0p1 vfat 253 MB /boot/firmware RPi Firmware partition
/dev/mmcblk0p3 ext4 740 MB /boot RPi boot directory
SSD /dev/sda1 swap 2 GB   Swap partition
/dev/sda2 btrfs 16 GB / Root filesystem
/dev/sda3 xfs 16 GB /var/lib/posgresql Database partition
USB HDD

/dev/sdb1

/dev/sdc1

xfs 2 TB /mnt/vchanger/[UUID] Backup disk mount point

PostgreSQL has its own 16 GB XFS partition on the SSD since I used btrfs for the root filesystem. While it has a lot of advantages, btrfs performs really badly with databases. The drawback of XFS is that you cannot shrink it if you overallocate initially. There is also 32 GB of free space which helps to even out wear on the SSD and also means I've got room to expand in future. While I'm not expecting a massive growth in the OS size it's quite likely the database will grow.

The USB HDDs are automatically mounted to /mnt/vchanger/ by the vChanger application so don't need to be explicitly configured in fstab.

Administration is by remote access using SSH, and this is configured with a signed host key and with my UserCA also enabled.

Bacula Installation

Installing Bacula from the Ubuntu repository is simply a case of making sure you have internet access and then installing PostgreSQL (or MariaDB) and then the bacula-server metapackage via apt.

Postgres

I'm using the default version of PostgreSQL, which for Ubuntu 20.04 LTS is PostgreSQL 12.

As root

apt install postgresql
... Creating new PostgreSQL cluster 12/main ... /usr/lib/postgresql/12/bin/initdb -D /var/lib/postgresql/12/main --auth-local peer --auth-host md5 The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "C.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". ... Success. You can now start the database server using: pg_ctlcluster 12 main start

My notes from the time stop at this point which is a but surprising but possible. From memory the database config was handled by Bacula itself but I could be wrong.

Bacula Server

Install from the Ubuntu repositories

sudo apt install bacula-server

By default the configuration files are placed in /etc/bacula directory and owned by either the bacula user or root. This will install the Bacula Director, Bacula Storage Daemon and a Bacula File Daemon in one go which is everything you need to get started. Configuration will be covered in a future article as that's quite a big topic in its own right.

I believe the installer also detects a local PostgreSQL and prompts for database configuration automatically but my notes don't go into that level detail. When I get the time I'll do a recreation of the installation process and document it properly.

Bacula Admin Tool

This is an optional GUI application for managing a Bacula server, also known as Bat.

sudo apt install bacula-console-qt

This will bring in a lot of other packages for QT but this works very nicely over an SSH using ssh -X [hostname] -C bat

vChanger Installation (TODO)

Unlike the main Bacula applications which are supplied as Ubuntu packages, vChanger is a download from Sourceforge (https://sourceforge.net/projects/vchanger/) that you have to compile.

Copy the downloaded vchanger.tar file somewhere convenient and compile it

tar -xzf vchanger-1.0.3.tar.gzcd vchanger./configure
make

And then wait for it to compile. Once complete you need to become root and install it

sudo su - root
make install-strip

This will install the vchanger executable in /usr/local/bin, udev automount scripts in /usr/local/libexec/vchanger, and the documentation in /usr/local/share/doc/vchanger. The scripts will then need to be moved to /usr/libexec

There's a few steps to configuring vChanger and creating the volume and that's definitely a separate topic.

git installation

I can't recall if this needed to be installed from the Ubuntu repositories or if it came ready configured. If not it's simply a call to sudo apt install git to obtain it.

The git repository is created in /etc/bacula and the upstream is set to one of my servers under /srv/git/baculaconfig.git using SSH. Which means I have the current live Bacula configuration on the BaculaPi itself, the history in git, and backups of both in the weekly schedule.

The .gitignore file is configured to exclude a few items

#Files to exclude from Git control of Bacula config

#Local file daemon and key
/bacula-fd.conf
/bacula-fd.pem

# Old files and recent changes
*.bak
/jobdef/*.old

# Keys
/keys/*.pem

#Other root only files
/common_default_passwords

The main exclusion being the keys used for data encryption. These are backed up separately as without these a restore in impossible. The backups of the keys is also stored separately to to backup disks themselves.

Configuration

Once installation is complete and you have the services running it's time to configure. And that will be covered in the next few articles.

While the Bacula Director might be the most obvious place to start configuring, if I was to do this again I'd start with the removeable SSDs and the vChanger configuration to mount them and then work up through the stack as this means I can test each step in turn.

  • vChanger Configuration [link]
  • Bacula File Daemon Configuration [link]
  • Bacula Storage Daemon Configuration [link]
  • Bacula Director - Core [link]
  • Bacula Director - Jobs [link]

Links to all related articles will be collected here once I've finished them.