🦇Bacula - Install & configure (Conclusion)🦇#

1178 words | 16 min read


In the previous article, we configured the Bacula Director and the File Daemon on the Bacula server (server01), and ran a backup job to backup the Bacula server itself.

Now, we will configure Bacula to backup our other computers that are represented in this diagram.

The ws01 server runs a website using the Apache HTTP server. The website’s files are under /var/www/html. So, we will set up bacula to backup this directory, as well as Apache’s configuration files.

Similarly, the db01 server runs MariaDB. We will configure Bacula to generate an ASCCI dump of the mariaDB databases, and then backup that file.

This will require making configuration changes on each of the client computers (ws01 and db01) as well as the Bacula server (server01).

1. Install the File Daemon on each client computer#

Login to db01 and ws01, and run the following command on each computer

Install the Bacula File Daemon#
sudo apt install -y bacula-fd

2. Configure the File Daemon on each computer#

Open /etc/bacula/bacula-fd.conf in an editor on each computer.

2.1.1. Update the definition of the Bacula Director#

Find the definition for the “Director” (ws01-dir or db01-dir). Change the Name to “server01-dir”. This is because we want the server01-dir to connect to this File Daemon to initiate the backup. There is no Director service running on either db01 or ws01. So, it’s ok to rename the director. If you prefer, you can also define a new section for the server01-dir. Save the file after making your changes.

Update the Director definition (ws01)#
#
# List Directors who are permitted to contact this File daemon
#
Director {
  Name = server01-dir
  Password = "Dc9e8YJ5jB7OwXtTzs9v9KGk1EDEt-aBc"
}
Update the Director definition (db01)#
#
# List Directors who are permitted to contact this File daemon
#
Director {
  Name = server01-dir
  Password = "-5r2dZgIy9uXXOIvRjtSWl9hKHKCuJdKq"
}

Yes. They should look pretty much identical (except for the password). We will copy the password and use it in the Director configuration in a subsequent step.

2.1.2. Change the Listening IP address of the File Daemon#

By default, the File Daemon is configured to listen only on the loopback interface (127.0.0.1). This was fine on server01 (since the Director was running on the same machine).

However, we need to make the FileDaemon on db01 and ws01 reachable from server01. So, let’s change the “FDAddress”.

Update the FileDaemon definition (ws01)#
#
# "Global" File daemon configuration specifications
#
FileDaemon {                          # this is me
  Name = ws01-fd
  FDport = 9102                  # where we listen for the director
  WorkingDirectory = /var/lib/bacula
  Pid Directory = /run/bacula
  Maximum Concurrent Jobs = 20
  Plugin Directory = /usr/lib/bacula
  FDAddress = ws01.example.com
}
Update the FileDaemon definition (db01)#
#
# "Global" File daemon configuration specifications
#
FileDaemon {                          # this is me
  Name = db01-fd
  FDport = 9102                  # where we listen for the director
  WorkingDirectory = /var/lib/bacula
  Pid Directory = /run/bacula
  Maximum Concurrent Jobs = 20
  Plugin Directory = /usr/lib/bacula
  FDAddress = db01.example.com
}

2.1.3. Verify the configuration#

Verify the File Daemon Configuration#
sudo bacula-fd -t

This command should not report any errors.

2.1.4. Restart the File Daemon#

Restart the File Daemon#
sudo systemctl restart bacula-fd

3. Configure the Bacula Director#

Now, go to server01 and open the /etc/bacula/bacula-dir.conf file in an editor.

We will define the following new sections for db01 and ws01:

  • Client

  • Job

  • FileSet

We will also configure the Director to accept remote connections

3.1. Configure the Director to listen on the correct Network address#

In bacula-dir.conf, modify the “DirAddress” in the “Director” Section so that it’s no longer “127.0.0.1”.

Note

This is only needed if you intend to connect from a remote console, or if you intend to run any other Bacula tools (e.g. baculum or bacularis) on a different host.

Update the DirAddress for the Director#
Director {                            # define myself
  Name = server01-dir
  DIRport = 9101                # where we listen for UA connections
  QueryFile = "/etc/bacula/scripts/query.sql"
  WorkingDirectory = "/var/lib/bacula"
  PidDirectory = "/run/bacula"
  Maximum Concurrent Jobs = 20
  Password = "5Lisc5qPDwSL5UcRRmSO3vWzMYc08GhCi"         # Console password
  Messages = Daemon
  DirAddress = server01.example.com
}

3.2. Define the Bacula clients#

Next, add the client section similar to what’s shown below. You can copy/paste from an existing definition to make things easier.

Note

The Password specified in the “Client” section of bacula-dir.conf must match the password for the “Director” in bacula-fd.conf for each computer (client) that you want to backup.

Client Definition in /etc/bacula/bacula-dir.conf#
# Client (File Services) to backup
Client {
  Name = db01-fd
  Address = db01.example.com
  FDPort = 9102
  Catalog = MyCatalog
  Password = "-5r2dZgIy9uXXOIvRjtSWl9hKHKCuJdKq"       # password for FileDaemon
  File Retention = 30 days            # 30 days
  Job Retention = 3 months            # three months
  AutoPrune = yes                     # Prune expired Jobs/Files
}

# Client (File Services) to backup
Client {
  Name = ws01-fd
  Address = ws01.example.com
  FDPort = 9102
  Catalog = MyCatalog
  Password = "Dc9e8YJ5jB7OwXtTzs9v9KGk1EDEt-aBc"       # password for FileDaemon
  File Retention = 30 days            # 30 days
  Job Retention = 3 months            # three months
  AutoPrune = yes                     # Prune expired Jobs/Files
}

3.3. Define the backup jobs#

Let’s define the jobs section (in bacula-dir.conf) for each computer we want to backup.

Job Definition in /etc/bacula/bacula-dir.conf#
# Client (File Services) to backup
# Backup db01
Job {
  Name = "Daily db01"
  JobDefs = "WeeklyBackupJob"
  Client = db01-fd
  Schedule = "MyWeeklyCycle"
  FileSet = "db01 Set"
}

# Backup ws01
Job {
  Name = "Daily ws01"
  JobDefs = "WeeklyBackupJob"
  Client = ws01-fd
  Schedule = "MyWeeklyCycle"
  FileSet = "ws01 Set"
}

The Job inherits a number of parameters from the “JobDefs”. And then you override (or define additional) parameters for each job. For example, the Storage location (vchanger0) is inherited from the “WeeklyBackupJob” definition. if you wanted to backup ws01 to a different location - you would override the “Storage” parameter in the “Job” section.

And you can see that we are overriding the “Schedule” definition for our jobs.

You can also see how each “job” is connected with a “Client”, a “Schedule” and a FileSet.

3.4. Define the FileSets#

FileSet Definition in /etc/bacula/bacula-dir.conf#
# List of files to be backed up
FileSet {
  Name = "db01 Set"
  Include {
    Options {
      signature = MD5
    }
    # MariaDB Backup
    File = /opt/mariadb_backup
  }
}

# List of files to be backed up
FileSet {
  Name = "ws01 Set"
  Include {
    Options {
      signature = MD5
    }
    # Apache Config Dir
    File = /etc/apache2
    # Website files
    File = /var/www/html
  }
}

Note

We are backing up specific directories. So, there is no need to exclude any directories. If you backup the entire root directory (/), be sure to Exclude locations such as “/proc”, “/run”, “/tmp” etc.

3.5. Verify the configuration#

Verify the Director Configuration#
sudo bacula-dir -t

This command should not report any errors.

3.6. Restart the Director#

Restart the Director#
sudo systemctl restart bacula-dir

Now, if you launch bconsole and type “run”, you should see 2 more backup jobs in the list (“Daily db01” and “Daily ws01”).

You already know how to run a backup job, and to check its status. So, go ahead. Run both the jobs and ensure that they run successfully to completion.

This test is to mainly check the connectivity between the Director and the File Daemons and the Storage Daemon. We still need to back up the MariaDB database(s) properly. We will do that once this intial test is successful.

Tip

The log files under /var/log/bacula can be used to check the list of files that were backed up, as well as to debug any errors.

The details of the backup are also in the Catalog DB. So, you can also run SQL queries to obtain the information.

4. Set up Bacula to backup MariaDB#

4.1.1. Create the MariaDB dump script#

On db01, create “/usr/local/bin/bacula_pre_backup.sh” (or whatever you choose to call it), with contents similar to what’s below:

/usr/local/bin/bacula_pre_backup.sh#
#!/usr/bin/bash

/usr/bin/mariadb-dump --all-databases --lock-all-tables > /opt/mariadb_backup/mariadb_backup.sql

4.1.2. Create backup directory and set permissions#

Now, create the directory (/opt/mariadb_backup in our example) and make it writable by Bacula. Also make the “bacula_pre_backup.sh” executable

Create backup directory and set permissions#
mkdir -p /opt/mariadb_backup
chown bacula:tape /opt/mariadb_backup
chmod +x /usr/local/bin/bacula_pre_backup.sh

4.1.3. Run the script and test it#

Run /usr/local/bin/bacula_pre_backup.sh and verify that the file /opt/mariadb_backup/mariadb_backup.sql is created successfully.

5. Update the Bacula Director to run the pre-backup script#

Find the “Job” definition for the db01 job, and add the “Client Run Before Job” parameter. The Job section should now look similar to the one below:

Add the pre-backup script to the job#
# Backup db01
Job {
  Name = "Daily db01"
  JobDefs = "WeeklyBackupJob"
  Client = db01-fd
  Schedule = "MyWeeklyCycle"
  FileSet = "db01 Set"
  Client Run Before Job = "/usr/local/bin/bacula_pre_backup.sh"
}

Note

The pre-backup (and, if you wish, post-backup script too) is created on the client (db01), but defined in the server (bacula-dir.conf) because the Bacula Director initiates the remote backup job, including the execution of the pre-backup script.

5.1. Restart the Bacula Daemon#

Restart the Bacula Daemon#
sudo systemctl restart bacula-dir

6. Run the “Daily db01” job#

Run the “db01” job from bconsole and

  • Verify that it completed successfully

  • Verify that the /opt/mariadb_backup/mariadb_backup.sql file was created on the db01 computer

  • Check the bacula log files (or query the catalog) to make sure that mariadb_backup.sql was backed up

At this stage, the fully working configuration files should look similar to these: ws01 bacula-fd.conf db01 bacula-fd.conf bacula-dir.conf

Note

I used the Bacula version (9.6.7-7) that’s available for my OS.
You can also try to go for the latest Bacula version (13.0.3, as of this writing) by either downloading RPMs or DEBs directly from the Bacula website if they are available for your OS/architecture.
If you, however, decide to build from source, be sure to install the various pre-requisite packages. Also be prepared to compile the File Daemon for each client that runs a different OS/architecture. And be prepared to keep doing this every time a patch or a new version is released.

Recap and Conclusion#

To recap, we set up 2 additional clients (db01 and ws01) to be backed up.

  • We installed and configured bacula-fd on db01 and ws01

  • We updated bacula-dir.conf on server01 to add db01 and ws01

  • We created a new pre-backup script to backup the MariaDB database.

Be sure to also back up the Bacula Catalog. There is a job already defined for this. Adjust the timing schedule for this job as necessary - and ensure that this is a full backup every day.

If you need to add any more computers for Bacula to backup - you can just repeat the steps from this post (or more likely, copy/paste the required sections from your working config and modify them as needed).

And for safety, make a backup copy of your working configuration before making any changes. Speaking of backups, did you know that Bacula…Oh! Wait!