How to setup Bacula in RHEL-9.5

Bacula is an open-source network backup solution designed for creating backups
and recovering data on computer systems. While it can be a bit tricky to configure,
its flexibility and robustness make it a reliable choice for various backup needs. A
backup system is a vital part of most server infrastructures, as data recovery often
plays a critical role in disaster recovery plans.

Here are the key features of Bacula in simple terms:

  1. Backup and Recovery: Bacula helps you back up and restore data for servers,
    desktops, and other devices.
  2. Cross-Platform: It works on various operating systems like Linux, Windows,
    and macOS.
  3. Scalability: Bacula is designed to handle small setups and large, complex
    networks with many devices.
  4. Modular Design: It has several components (Director, Storage Daemon, File
    Daemon, etc.) that work together, making it flexible to configure.
  5. Automation: You can schedule backups, so they run automatically without
    manual intervention.
  6. Security: Supports encryption for secure backups and transmissions.
  7. Customizable: Offers many options for tailoring backups to specific needs,
    like incremental or full backups.
  8. Open Source: Free to use and customize, with a large community for support.

Bacula Component Overview

Bacula is a robust, enterprise-grade backup and recovery system. It is composed of
several key components that work together to ensure data is backed up, stored, and restored efficiently. Here’s an overview of its main components:

  1. Director (Dir)
    The Director is the central management component of Bacula.
    It controls the entire backup, recovery, and verification process.
    It communicates with all other Bacula components, ensuring tasks are
    scheduled and executed properly.
  2. File Daemon (FD)
    The File Daemon is installed on every system you want to back up.
    It handles the actual data transfer, reading the files from the client
    system and sending them to the storage destination.
  3. Storage Daemon (SD)
    The Storage Daemon manages the storage media where backups are
    saved.
    It handles the writing and reading of data to/from backup devices, such
    as tapes, disks, or cloud storage.
  4. Catalog (Database)
    The Catalog is a database that keeps track of all backup metadata,
    including file indexes, backup schedules, and storage locations.
    Supported databases include MySQL, PostgreSQL, and SQLite.
  5. Console
    The Console is the interface used by system administrators to interact
    with the Bacula system.
    It can be command-line-based (bconsole), graphical (Bacula GUI), or
    web-based (Bacula Web).
  6. Backup Media
    This is the physical or virtual storage where backup data is saved, such as
    tape libraries, disk arrays, or cloud storage solutions.

How It Works Together

  • The Director initiates and manages backup or restore jobs.
  • The File Daemon on the client system sends the requested data to the
  • Storage Daemon.
  • The Storage Daemon writes the data to the specified backup media.
  • The Catalog stores all metadata about the backups, enabling quick and easy
  • restoration when needed.
  • The Console allows administrators to monitor and control the system.

The Bacula File Daemon (FD) is a component installed on servers that need to be
backed up, often referred to as “backup clients” or simply “clients.” This daemon
allows the Bacula Director (the backup server) to access and back up the server’s
data.

Interestingly, the backup server itself will also act as a backup client, as it will be
configured to back up its own filesystem. To enable this, the backup server will run
the File Daemon component as well.

Install Bacula and MySQL

# yum install bacula-director bacula-storage bacula-console bacula-client mysql-server
# systemctl start mysqld.service
# systemctl status mysqld.service
# systemctl enable mysqld.service

Set Bacula to Use MySQL Library

By default, Bacula is set to use the PostgreSQL library. Because we are using MySQL,
we need to set it to use the MySQL library instead.

# alternatives --config libbaccats.so

Create Backup and Restore Directories

# mkdir -p /bacula/backup /bacula/restore
# chown -R bacula:bacula /bacula/
# chmod -R 700 /bacula/

Connect to MySQL

# mysql -u root -p

Create a database and user for Bacula.

# mysql> create database bacula;
# mysql> create user bacula@localhost identified by 'Ak123!@#';
# mysql> grant all privileges on bacula.* to bacula@'localhost';
# mysql> flush privileges;
# exit;

Run this script to create the table structure.

# /usr/libexec/bacula/make_mysql_tables -p

Configure Bacula Director

# vim /etc/bacula/bacula-dir.conf
 Director { # define myself
 Name = bacula-dir
 DIRport = 9101 # where we listen for UA connections
 QueryFile = "/etc/bacula/query.sql"
 WorkingDirectory = "/var/spool/bacula"
 PidDirectory = "/var/run"
 Maximum Concurrent Jobs = 20
 Password = "@@DIR_PASSWORD@@" # Console password
 Messages = Daemon
 DirAddress = 127.0.0.1
}

Configure Local Jobs

# vim /etc/bacula/bacula-dir.conf
Job {
 Name = "BackupLocalFiles"
 JobDefs = "DefaultJob"
}

Set up Restore Files

# vim /etc/bacula/bacula-dir.conf
Job {
 Name = "RestoreLocalFiles"
 Type = Restore
 Client=bacula-fd
 Storage = File1
# The FileSet and Pool directives are not used by Restore Jobs
# but must not be removed
 FileSet="Full Set"
 Pool = File
 Messages = Standard
 Where = /bacula/restore
}

Configure File Set

# vim /etc/bacula/bacula-dir.conf
FileSet {
 Name = "Full Set"
 Include {
 Options {
 signature = MD5
 compression = GZIP
 }
File = /
 File = /usr/sbin
 }
 Exclude {
 File = /var/spool/bacula
 File = /tmp
 File = /proc
 File = /tmp
 File = /sys
 File = /.journal
 File = /.fsck
 File = /bacula
}
}

Add Configure Storage Daemon Connection

# vim /etc/bacula/bacula-dir.conf
Storage {
 Name = File
# Do not use "localhost" here
 Address = backup_server_private_FQDN # N.B. Use a fully qualified name here
 SDPort = 9103
 Password = "@@SD_PASSWORD@@"
 Device = FileStorage
 Media Type = File
}

Configure Catalog Connection

# vim /etc/bacula/bacula-dir.conf
# Generic catalog service
Catalog {
 Name = MyCatalog
 dbname = "bacula"; dbuser = "bacula"; dbpassword = "Ak123!@#"
}

Configure Pool

# vim /etc/bacula/bacula-dir.conf
# File Pool definition
Pool {
 Name = File
 Pool Type = Backup
 Recycle = yes # Bacula can
automatically recycle Volumes
 AutoPrune = yes # Prune expired volumes
 Volume Retention = 365 days # one year
 Maximum Volume Bytes = 50G # Limit Volume size to
something reasonable
 Maximum Volumes = 100 # Limit number of Volumes
in Pool
 Label Format = "Local-" # Auto label
}

Check Director Configuration

# bacula-dir -tc /etc/bacula/bacula-dir.conf

Configure Storage Resource

# vim /etc/bacula/bacula-sd.conf
Storage { # definition of myself
 Name = bacula-sd
 SDPort = 9103 # Director's port
 WorkingDirectory = "/var/spool/bacula"
 Pid Directory = "/var/run"
 Plugin Directory = "/usr/lib64/bacula"
 Maximum Concurrent Jobs = 20
 SDAddress = backup_server_private_FQDN
}

Add Configure Storage Device

# vim /etc/bacula/bacula-sd.conf
Device {
 Name = FileStorage
 Media Type = File
 Archive Device = /bacula/backup
 LabelMedia = yes; # lets Bacula label unlabeled media
 Random Access = Yes;
 AutomaticMount = yes; # when device opened, read it
 RemovableMedia = no;
 AlwaysOpen = no;
}

Verify Storage Daemon Configuration

# bacula-sd -tc /etc/bacula/bacula-sd.conf

Set Bacula Component Passwords

# DIR_PASSWORD=`date +%s | sha256sum | base64 | head -c 33`
# sudo sed -i "s/@@DIR_PASSWORD@@/${DIR_PASSWORD}/" /etc/bacula/bacula-dir.conf
# sudo sed -i "s/@@DIR_PASSWORD@@/${DIR_PASSWORD}/" /etc/bacula/bconsole.conf
# SD_PASSWORD=`date +%s | sha256sum | base64 | head -c 33` 
# sudo sed -i "s/@@SD_PASSWORD@@/${SD_PASSWORD}/" /etc/bacula/bacula-sd.conf
# sudo sed -i "s/@@SD_PASSWORD@@/${SD_PASSWORD}/" /etc/bacula/bacula-dir.conf
# FD_PASSWORD=`date +%s | sha256sum | base64 | head -c 33` 
# sudo sed -i "s/@@FD_PASSWORD@@/${FD_PASSWORD}/" /etc/bacula/bacula-dir.conf 
# sudo sed -i "s/@@FD_PASSWORD@@/${FD_PASSWORD}/" /etc/bacula/bacula-fd.conf

Start Bacula Components

# systemctl start bacula-dir.service
# systemctl start bacula-sd.service
# systemctl start bacula-fd.service
# systemctl enable bacula-dir.service
# systemctl enable bacula-sd.service
# systemctl enable bacula-fd.service
# systemctl status bacula-dir.service
# systemctl status bacula-sd.service
# systemctl status bacula-fd.service

Test Backup from Bacula

[root@baculaserver bacula]# bconsole
Connecting to Director localhost:9101
1000 OK: 10002 bacula-dir Version: 11.0.1 (05 February 2020)
Enter a period to cancel a command.
*label
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
The defined Storage resources are:
 1: File1
 2: File2
Select Storage resource (1-2): 1
Connecting to Storage daemon File1 at
baculaserver.localhost.com:9103 ...
Enter new Volume name: Vol-Server-20251101
Defined Pools:or Enter for none):
 1: Default
 2: File
 3: Scratch
Select the Pool (1-3): 2
Connecting to Storage daemon File1 at
baculaserver.localhost.com:9103 ...
Sending label command for Volume "Vol-Server-20251101" Slot 0
...
3000 OK label. VolBytes=248 VolABytes=0 VolType=1 Volume="VolServer-20251101" Device="FileChgr1-Dev1" (/tmp)
Catalog record for Volume "Vol-Server-20251101", Slot 0 
successfully created.
Requesting to mount FileChgr1 ...
3906 File device ""FileChgr1-Dev1" (/tmp)" is always mounted.
*run
A job name must be specified.
The defined Job resources are:
 1: BackupClient1
 2: node01-BackupClient
 3: BackupCatalog
 4: RestoreFiles
Select Job resource (1-4): 1
Run Backup job
JobName: BackupClient1
Level: Incremental
Client: bacula-fd
FileSet: Full Set
Pool: File (From Job resource)
Storage: File1 (From Job resource)
When: 2025-01-11 11:48:36
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=13
You have messages.

Check Log through messages command

*messages
11-Jan 11:48 bacula-dir JobId 13: The FileSet "Full Set" was
modified on 2025-01-11 11:48:40, this is after the last
successful backup on 2025-01-10 17:58:35.
11-Jan 11:48 bacula-dir JobId 13: No prior or suitable Full
backup found in catalog for the current FileSet. Doing FULL
backup.
11-Jan 11:48 bacula-dir JobId 13: Start Backup JobId 13,
Job=BackupClient1.2025-01-11_11.48.39_03
11-Jan 11:48 bacula-dir JobId 13: Using Device "FileChgr1-Dev1"
to write.
11-Jan 11:48 bacula-sd JobId 13: Wrote label to prelabeled
Volume "Vol-Server-20251101" on File device "FileChgr1-Dev1"
(/tmp)
11-Jan 11:48 bacula-fd JobId 13: /boot is a different
filesystem. Will not descend from / into it.
11-Jan 11:48 bacula-fd JobId 13: /dev is a different
filesystem. Will not descend from / into it.
11-Jan 11:48 bacula-fd JobId 13: /run is a different
filesystem. Will not descend from / into it.

Check Status of backup file

*status director
bacula-dir Version: 11.0.1 (05 February 2020) x86_64-redhatlinux-gnu redhat Beta
Daemon started 11-Jan-25 11:47, conf reloaded 11-Jan-2025
11:47:02
Jobs: run=0, running=1 mode=0,0
Crypto: fips=N/A crypto=OpenSSL
Heap: heap=536,576 smbytes=453,336 max_bytes=453,409 bufs=451
max_bufs=452
Res: njobs=4 nclients=2 nstores=2 npools=3 ncats=1 nfsets=3
nscheds=2
Scheduled Jobs:
Level Type Pri Scheduled Job Name 
Volume
===============================================================
====================
Incremental Backup 10 11-Jan-25 23:05 BackupClient1 
Vol-1
Incremental Backup 10 11-Jan-25 23:05 node01-
BackupClient Vol-1
Full Backup 11 11-Jan-25 23:10 BackupCatalog 
Vol-1
====
Running Jobs:
Console connected at 11-Jan-25 11:47
JobId Type Level Files Bytes Name 
Status
===============================================================
=======
 13 Back Full 9,642 282.2 M BackupClient1 is
running
====
Terminated Jobs:
JobId Level Files Bytes Status Finished 
Name
===============================================================
=====
 1 Full 3 0 OK 10-Jan-25 17:58
BackupClient1
 2 Restore 3 0 OK 10-Jan-25 18:21
RestoreFiles
 3 Restore 3 0 OK 10-Jan-25 18:31
RestoreFiles
 4 Restore 3 0 OK 10-Jan-25 18:39
RestoreFiles
 5 Incr 1 0 OK 10-Jan-25 18:43
BackupClient1
 6 Restore 1 0 OK 10-Jan-25 18:48
RestoreFiles
 7 Incr 0 0 OK 10-Jan-25 18:51
BackupClient1
 9 Incr 0 0 OK 10-Jan-25 19:03
BackupClient1
 11 Full 0 0 Error 11-Jan-25 11:27
node01-BackupClient
 12 Full 0 0 Error 11-Jan-25 11:37
node01-BackupClient
====
*exit

Check the backup file location

# cd /tmp

Restore the file

[root@baculaserver tmp]# bconsole
Connecting to Director localhost:9101
1000 OK: 10002 bacula-dir Version: 11.0.1 (05 February 2020)
Enter a period to cancel a command.
*restore
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.
To select the JobIds, you have the following choices:
 1: List last 20 Jobs run
 2: List Jobs where a given File is saved
 3: Enter list of comma separated JobIds to select
 4: Enter SQL list command
 5: Select the most recent backup for a client
 6: Select backup for a client before a specified time
 7: Enter a list of files to restore
 8: Enter a list of files to restore before a specified
time
 9: Find the JobIds of the most recent backup for a client
 10: Find the JobIds for a backup for a client before a
specified time
 11: Enter a list of directories to restore for found JobIds
 12: Select full restore to a specified Job date
 13: Cancel
Select item: (1-13): 5
Defined Clients:
 1: bacula-fd
 2: node01
Select the Client (1-2): 1
Automatically selected FileSet: Full Set
+-------+-------+----------+-------------+---------------------
+---------------------+
| JobId | Level | JobFiles | JobBytes | StartTime 
| VolumeName |
+-------+-------+----------+-------------+---------------------
+---------------------+
| 13 | F | 42,626 | 985,377,171 | 2025-01-11 11:48:42
| Vol-Server-20251101 |
+-------+-------+----------+-------------+---------------------
+---------------------+
You have selected the following JobId: 13
Building directory tree for JobId(s) 13 ...
+++++++++++++++++++++++++++++++++++++++++++
37,437 files inserted into the tree.
cwd is: /
$ ls
bacula/
$ mark
$ bacula/
mark bacula/
3 files marked.
$ lsmark
*bacula/
 *backup
 *restore
$ done
Bootstrap records written to /var/spool/bacula/baculadir.restore.2.bsr
The Job will require the following (*=>InChanger):
 Volume(s) Storage(s) SD
Device(s)
===============================================================
============
 vol-20250110 File1 
FileChgr1 
Volumes marked with "*" are in the Autochanger.
3 files selected to be restored.
Using Catalog "MyCatalog"
Run Restore job
JobName: RestoreFiles
Bootstrap: /var/spool/bacula/bacula-dir.restore.2.bsr
Where: /tmp/bacula-restores
Replace: Always
FileSet: Full Set
Backup Client: bacula-fd
Restore Client: bacula-fd
Storage: File1
When: 2025-01-10 18:28:59
Catalog: MyCatalog
Priority: 10
Plugin Options: *None*
OK to run? (yes/mod/no): yes
*messages
10-Jan 18:21 bacula-dir JobId 2: Start Restore Job
RestoreFiles.2025-01-10_ 
18.21.54_07
10-Jan 18:21 bacula-dir JobId 2: Restoring files from JobId(s)
1
10-Jan 18:21 bacula-dir JobId 2: Using Device "FileChgr1-Dev2"
to read.
10-Jan 18:21 bacula-sd JobId 2: Ready to read from volume "vol20250110" on 
File device "FileChgr1-Dev2" (/tmp).
10-Jan 18:21 bacula-sd JobId 2: Forward spacing Volume "vol20250110" to ad 
dr=241
10-Jan 18:21 bacula-sd JobId 2: End of Volume "vol-20250110" at
addr=914 on 
device "FileChgr1-Dev2" (/tmp).
10-Jan 18:21 bacula-sd JobId 2: Elapsed time=00:00:01, Transfer
rate=237 B 
ytes/second
10-Jan 18:21 bacula-dir JobId 2: Bacula bacula-dir 11.0.1
(05Feb20):
 Build OS: x86_64-redhat-linux-gnu redhat Beta
 JobId: 2
 Job: RestoreFiles.2025-01-10_18.21.54_07
 Restore Client: bacula-fd
 Where: /tmp/bacula-restores
 Replace: Always
 Start time: 10-Jan-2025 18:21:56
 End time: 10-Jan-2025 18:21:56
 Elapsed time: 1 sec
 Files Expected: 3
 Files Restored: 3
 Bytes Restored: 0 (0 B)
 Rate: 0.0 KB/s
 FD Errors: 0
FD termination status: OK
 SD termination status: OK
 Termination: Restore OK
10-Jan 18:21 bacula-dir JobId 2: Begin pruning Jobs older than
6 months .
10-Jan 18:21 bacula-dir JobId 2: No Jobs found to prune.
10-Jan 18:21 bacula-dir JobId 2: Begin pruning Files.
10-Jan 18:21 bacula-dir JobId 2: No Files found to prune.
10-Jan 18:21 bacula-dir JobId 2: End auto prune.
10-Jan 18:31 bacula-dir JobId 3: Start Restore Job
RestoreFiles.2025-01-10_ 
18.31.39_12
10-Jan 18:31 bacula-dir JobId 3: Restoring files from JobId(s)
1
10-Jan 18:31 bacula-dir JobId 3: Using Device "FileChgr1-Dev1"
to read.
10-Jan 18:31 bacula-sd JobId 3: Ready to read from volume "vol20250110" on 
File device "FileChgr1-Dev1" (/tmp).
10-Jan 18:31 bacula-sd JobId 3: Forward spacing Volume "vol20250110" to ad 
dr=241
10-Jan 18:31 bacula-sd JobId 3: End of Volume "vol-20250110" at
addr=914 on 
device "FileChgr1-Dev1" (/tmp).
10-Jan 18:31 bacula-sd JobId 3: Elapsed time=00:00:01, Transfer
rate=237 B 
ytes/second
10-Jan 18:31 bacula-dir JobId 3: Bacula bacula-dir 11.0.1
(05Feb20):
 Build OS: x86_64-redhat-linux-gnu redhat Beta
 JobId: 3
 Job: RestoreFiles.2025-01-10_18.31.39_12
 Restore Client: bacula-fd
 Where: /tmp/bacula-restores
Replace: Always
 Start time: 10-Jan-2025 18:31:41
 End time: 10-Jan-2025 18:31:42
 Elapsed time: 1 sec
 Files Expected: 3
 Files Restored: 3
 Bytes Restored: 0 (0 B)
 Rate: 0.0 KB/s
 FD Errors: 0
 FD termination status: OK
 SD termination status: OK
 Termination: Restore OK
10-Jan 18:31 bacula-dir JobId 3: Begin pruning Jobs older than
6 months .
10-Jan 18:31 bacula-dir JobId 3: No Jobs found to prune.
10-Jan 18:31 bacula-dir JobId 3: Begin pruning Files.
10-Jan 18:31 bacula-dir JobId 3: No Files found to prune.
10-Jan 18:31 bacula-dir JobId 3: End auto prune.
*exit
[root@baculaserver /]# cd tmp/
[root@baculaserver tmp]# ls
bacula-restores 
systemd-private-f78d2b458c3749a7b83be3242908f52d-kdump.serviceItqJZ0
systemd-private-f78d2b458c3749a7b83be3242908f52dchronyd.service-6oHkbV systemd-privatef78d2b458c3749a7b83be3242908f52d-mariadb.service-72vU0n
systemd-private-f78d2b458c3749a7b83be3242908f52d-dbusbroker.service-YkAzSN systemd-privatef78d2b458c3749a7b83be3242908f52d-systemd-logind.service-Qqe4fH
systemd-private-f78d2b458c3749a7b83be3242908f52dirqbalance.service-7aFs0T vol-20250110
[root@baculaserver tmp]# cd bacula-restores/
[root@baculaserver bacula-restores]# ls
bacula
[root@baculaserver bacula-restores]# cd bacula/
[root@baculaserver bacula]# ls
backup restore
[root@baculaserver bacula]#

Leave a Reply

Your email address will not be published. Required fields are marked *