Bacula Tapes 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.

In this post, I will install and configure Bacula with PostgreSQL. PostgreSQL is the default database for Bacula on FreeBSD. Using MySQL requires installing Bacula from ports and setting make options, which I will not be covering in this post.

Bacula PostgreSQL Setup

First and foremost we install, initialise and then start our Postgresql server.

pkg install postgresql11-server
echo 'postgresql_enable="YES"' >> /etc/rc.conf 
service postgresql initdb
service postgresql start

To help us with setting up the databases and tables in PostgreSQL, Bacula has 3 scripts to set everything up for us. Now is a good time to install and enable Bacula.

pkg install bacula9-server
cat  << EOF >>  /etc/rc.conf
bacula_dir_enable="YES"
bacula_fd_enable="YES"
bacula_sd_enable="YES"
EOF

Next we log into the PostgreSQL server and add the bacula user. First we su into the user postgres that was created when we installed PostgresSQL. Then it is just a matter of running the 3 scripts as follows. First we start with creating the Bacula database.

root@freebsd12-master:/usr/local/share/bacula # su - postgres
$ /usr/local/share/bacula/create_bacula_database
Creating postgresql database
CREATE DATABASE
ALTER DATABASE
Creation of bacula database succeeded.
Database encoding OK

Verify all went well.

$ psql -l
                             List of databases
   Name    |  Owner   | Encoding  | Collate | Ctype |   Access privileges   
-----------+----------+-----------+---------+-------+-----------------------
 bacula    | postgres | SQL_ASCII | C       | C     | 
 postgres  | postgres | UTF8      | C       | C     | 
 template0 | postgres | UTF8      | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8      | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
(4 rows)

After verifying that all went well with the psql -l command we move onto making the Bacula tables.

$ /usr/local/share/bacula/make_bacula_tables
Making postgresql tables
CREATE TABLE
ALTER TABLE
...
INSERT 0 1
Creation of Bacula PostgreSQL tables succeeded.

Finaly we install our bacula user for PostgreSQL.

$ /usr/local/share/bacula/grant_bacula_privileges 
Granting postgresql privileges
CREATE ROLE
ALTER DATABASE
GRANT
...
...
GRANT
Privileges for user bacula granted on database bacula.

Let’s see what that did, first by displaying the PostgreSQL users.

$ psql
psql (11.5)
Type "help" for help.
postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 bacula    |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

Then listing the PostgreSQL databases.

postgres-# \l
                             List of databases
   Name    |  Owner   | Encoding  | Collate | Ctype |   Access privileges   
-----------+----------+-----------+---------+-------+-----------------------
 bacula    | bacula   | SQL_ASCII | C       | C     | 
 postgres  | postgres | UTF8      | C       | C     | 
 template0 | postgres | UTF8      | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8      | C       | C     | =c/postgres          +
           |          |           |         |       | postgres=CTc/postgres
(4 rows)

And finally switching to the bacula database.

postgres=# \c bacula
You are now connected to database "bacula" as user "postgres".

From here, there is still one more step to complete. That is, setting the password for the bacula user.

bacula=# alter user bacula with password 'secret';
ALTER ROLE
bacula=# \q
$ ^D

Exit with the \q command.

Starting Bacula

With the Bacula directives set in /etc/rc.conf it is just a matter now to start the Bacula services to complete this post.

service bacula-dir start
service bacula-sd start
service bacula-fd start

Wrapping Up

That’s all folks! Bacula is ready for taking your first steps. A good place to start is with the Breif Tutorial from the Bacula Main Document. You can follow this up with my series of post on Bacula, that goes into quite some detail.