Bacula Disks Bacula is an open-source, enterprise-level computer backup system for heterogeneous networks. Bacula is by far the most popular Open Source backup program. It is designed to automate backup tasks that had often required intervention from a systems administrator or computer operator. Bacula supports Linux, UNIX, Windows, and macOS backup clients, and a range of professional backup devices including tape libraries.

This post covers auto-mounting USB devices under FreeBSD to make available to Bacula. This is done with autofs. I will also look at formatting and labeling these devices under FreeBSD so as to provide a clean device for Bacula to work with. Finally we need to label this media via the bconsole program so that these devices can be allocated to the Bacula Storage Pools that we setup in a previous post.

Preparing Media for Bacula

I will cover automounting, formatting and labeling of removable media in this section.

Setup AutoFS

To make backups as seamless as possible we want to automount our removable media when it is plugged in. FreeBSD uses autofs(5) to achieve this. We need to alter two files as below to enable & configure autofs.

/etc/rc.conf requires to have the autofs service enabled.

echo 'autofs_enable="YES"' >> /etc/rc.conf

/etc/auto_master needs to have the following line uncommented.

#/media		-media		-nosuid,noatime,autoro

Reboot for changes to take effect.

In this post we will be labeling our media as bacula. Autofs, will mount this under the /media/ directory. This file system, /media/bacula will be transparently mounted on the first access to the device.

Unmounting Automountd Devices

To interactively unmount the USB device, issue the following command:

automount -u

Normally backup jobs will run unattended, and to interactively unmount the device is not feasible. Not to worry, the autounmountd daemon, part of autofs, will automatically unmount the device after 10 minutes. If the device is busy, automountd will wait a further 10 minutes and try again, repeating this until the device is unmounted.

Format Removable Media

With the disk unmounted, we need to wipe the start of the disk to remove any existing partitions. You will need the device name from the console output, in my case it is /dev/da0. Wipe the start of the drive with:

dd if=/dev/zero of=/dev/da0 bs=1m count=128

This command will write zero’d (blank) data to the first 128MB of the device /dev/da0.

Next we are ready to format the disk for FreeBSD’s use, using the UFS2 filesystem. We will label the disk as bacula so it will be mounted as /media/bacula which is where the bacula-dir.conf file expects to find it. Format with the following command:

newfs -L bacula -O2 -U -m 1 /dev/da0

The -m directive, takes a percentage as its argument and is how much space is reserved for the system to complete system tasks. The default is 8%, however this is out-dated and nowadays should be changed. A rule of thumb is that 100MB should be made available. As most all drives are at least a minimum of 8GB nowadays, the lowest percentage we can use is 1%.

Setting Permissions on Removable Media

We need to set the permissions on the media for Bacula to have write access.

Listing the mountpoint will cause the media to be automounted, then it is just a matter of setting the ownership permissions.

root@bacula:~ # ll /media/bacula
root@bacula:~ # chown -R bacula:bacula /media/bacula

Label the Media for Bacula

Before we label the media, we first have to create the bconsole.conf file. This sits along side the three main configuration files (bacula-dir, bacula-sd & bacula-fd) and not in the Includes directory. The file should be as follows:

#
# Bacula User Agent (or Console) Configuration File
#
# Copyright (C) 2000-2020 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

Director {
  Name = bacula.pbdigital.org-dir
  DIRport = 9101
  address = bacula.pbdigital.org
  Password = "secret"
}

With the console now configured, I use echo to pipe the command to bconsole, rather than entering the bconsole program as this does not interrupt our workflow.

The following command will label the device as DAILY-0001 in the DAILY pool. You will want to do this on all your backup media, whilst substituting the volume & pool arguments to reflect which device you are labeling.

echo "label storage=bacula.pbdigital.org-sd-usb volume=DAILY-0001 pool=DAILY" |bconsole

A successful output of this command will be as follows:

Connecting to Director localhost:9101
1000 OK: 103 bacula.pbdigital.org-dir Version: 9.4.3 (02 May 2019)
Enter a period to cancel a command.
label storage=bacula.pbdigital.org-sd-usb volume=DAILY-0001 pool=DAILY
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Connecting to Storage daemon bacula.pbdigital.org-sd-usb at bacula.pbdigital.org:9103 ...
Sending label command for Volume "DAILY-0001" Slot 0 ...
3000 OK label. VolBytes=240 VolABytes=0 VolType=1 Volume="DAILY-0001" Device="usb-storage" (/media/bacula)
Catalog record for Volume "DAILY-0001", Slot 0  successfully created.
Requesting to mount usb-storage ...
3002 Device ""usb-storage" (/media/bacula)" is mounted.

Tada! That’s all there is to it. Go ahead and unmount the media with the automount -u command and repeat for following volumes.

automount -u

Wrapping Up

I am pleased that we should now have a working Bacula installation that will take care of our backups as per our schedule. You will want to add more clients and customize the FileSets for your own environment.

I hope the information I have provided here has got you to this stage and I am also pleased, there is now one more Bacula Sysadmin out there to spread the word of what a fantastic product it is.

If you have any comments or questions, please let me know, I would be very appreciative of your ideas or if there is anyway I can help!

ENJOY!