28.12.2020

How to Install and Configure Bacula with PostgreSQL on CentOS 8

We have already considered installing the Bacula client on the CentOS 8 and saving backups on a remote machine using it, did a general overview of Bacula and installed the Director on the Ubuntu 20.04 server. In this tutorial, we will install the main components of Bacula together with the PostgreSQL database on the CentOS 8 server.

Installing and configuring PostgreSQL

Bacula can work with the PostgreSQL database management system. Let’s install it, init and start.

# dnf install postgresql-server
# postgresql-setup initdb
# systemctl enable --now postgresql

Create a user for Bacula.

# sudo su - postgres
$ createuser bacula
$ psql
psql (10.14)
Type "help" for help.
postgres=# ALTER USER bacula PASSWORD 'bacula';
ALTER ROLE
postgres=# ALTER USER bacula LOGIN SUPERUSER CREATEDB CREATEROLE;
ALTER ROLE
postgres=# q
$ exit
logout

Uncomment the following setting in the /var/lib/pgsql/data/postgresql.conf file:

listen_addresses = 'localhost'

Change the connection configuration to the following format in the file /var/lib/pgsql/data/pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     peer
local   bacula          bacula                                  md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
...

Restart the service.

systemctl restart postgresql.service

Installing and configuring Bacula

First, install Bacula components.

dnf install bacula-director bacula-storage bacula-console bacula-client

The following scripts automate the process of preparing the database, tables, and privileges. You need to execute them on behalf of the newly created user Bacula.

cd /usr/libexec/bacula/
sudo -u bacula ./create_postgresql_database
sudo -u bacula ./make_postgresql_tables
sudo -u bacula ./grant_postgresql_privileges

Create any folder for storing backups and set bacula as its owner.

mkdir /opt/bacula
chown bacula:bacula /opt/bacula

Open the /etc/bacula/bacula-dir.conf file and find the FileSet section with the Full Set name. Here, in the Include section you can set required folders to be backuped. Add /opt/bacula in the Exclude section.

FileSet {
Name = "Full Set"
Include {
...
File = /home/user
File = /folder/to/backup
}
Exclude {
File = /opt/bacula

}}

After that open the /etc/bacula/bacula-sd.conf file and set Archive Device = /opt/bacula for both Devices.

Device {
...
Archive Device = /opt/bacula
...
}

Start the services.

systemctl enable --now bacula-dir.service
systemctl enable --now bacula-fd.service
systemctl enable --now bacula-sd.service

Now the folders specified in section Include of the FileSet will be backed up daily. To start the backup task now, go to the Bacula Management Console.

# bconsole

Enter the run command and follow the instructions. To restore files, use restore command. To view scheduled Jobs, enter status and then 1. To see all available commands, type help.