🦇Bacula - Install & configure (Part-1)🦇#
1341 words | 18 min read
We looked at some Bacula concepts and terminology in the previous article. We also laid out our plan for installing the various components of Bacula in the Bacula Schematic Diagram. We will continue to refer to it as we go along.
To be able to execute the installation and configuration steps below, we are assuming that
You have a recent version of Ubuntu server running on a computer
There is at least 1 GB of RAM
There are at least a couple of GB of free disk space.
The Ubuntu computer is connected to the internal LAN with a valid IP address
The Ubuntu server can connect to the internet (to download installation packages)
You can SSH to this server as a non-root user
The non-root user can run
sudo
to escalate privileges to rootYou are familiar with using
apt
to install packages
Let us login to the “purple” box (which, in my case will be server01
) and do the the following on it:
1. Install PostgresQL Server#
sudo apt install postgresql
1.1. Check the status of the Postgresql server to make sure it’s running#
sudo systemctl status postgresql
You should see something similar to (code=exited, status=0/SUCCESS)
in the output of the command.
2. Install Bacula Director#
sudo apt install bacula-director
This will install the bacula director and other required dependencies.
Note
Once the installation starts, it will ask about configuring the postfix SMTP server. This is not relevant right now. So, you can choose “No configuration” and continue.
2.1. Configuring the Bacula Catalog#
The installer will prompt you about configuring the database for the Bacula Catalog. Choose
Yes
(this is easier than configuring the DB manually - which is still an option if you so choose)Choose
localhost
as the server nameEnter a password (and remember it - or use a Password Manager)
Make sure the installation completes without errors
2.2. Check that the bacula-dir daemon started without error#
sudo systemctl status bacula-dir
You should see something similar to ExecStartPre=/usr/sbin/bacula-dir -t -c $CONFIG (code=exited, status=0/SUCCESS)
in the output.
3. Install Bacula File Daemon#
sudo apt install bacula-fd
Check that bacula-fd started successfully.
4. Install Bacula Storage Daemon#
sudo apt install bacula-sd
Check that bacula-sd started successfully.
5. Install the Bacula Console#
sudo apt install bacula-console
sudo chown bacula:bacula /etc/bacula/bconsole.conf
6. Build and Install vchanger#
6.1. Download vchanger#
Download vchanger to a directory where you have permissions to write, and sufficient space to build the binary.
wget --output-document vchanger-1.0.3.tar.gz https://sourceforge.net/projects/vchanger/files/vchanger/1.0.3/vchanger-1.0.3.tar.gz/download
Be sure to also have the vchanger How-To handy.
6.2. Install Ubuntu build & libraries#
sudo apt install build-essential libudev-dev uuid-dev libblkid-dev
6.3. Extract the files from the tar.gz#
tar zxvf vchanger-1.0.3.tar.gz
The files should be extracted to a subdirectory called “vchanger”
6.4. Configure and build vchanger#
cd vchanger
./configure
make
6.5. Install vchanger#
sudo make install-strip
This will install the vchanger executable in /usr/local/bin, udev automount scripts in /usr/local/libexec/vchanger, and the documentation in /usr/local/share/doc/vchanger-1.0.3.
7. Prepare the USB disk#
7.1. Connect the USB disk to the PC#
7.2. Check the device name assigned in the system#
sudo fdisk -l
Note
In the examples below, I will use /dev/sda and /dev/sda1 etc. for my USB disk. You need to use the correct device name for your disk.
7.3. Unmount the disk/partition (if it’s already mounted)#
sudo umount /dev/sda1
Caution
The changes being made below are irreversible. So, be REALLY sure that you’re operating on the correct device.
7.4. Examine and Delete any existing partitions#
Run fdisk
, and use options
m - print the help
p - Print the partition table
d - delete a partition
n - create a new partition
w - write the partition table
sudo fdisk /dev/sda
p
d
w
7.5. Create a new partition that spans the entire disk#
Run fdisk
and choose “n” to create a new partition.
Then choose “p” to create the primary partition, Accept the default partition number (1).
Accept defaults for the first sector and last sector too.
sudo fdisk /dev/sda
n
p
<ENTER>
<ENTER>
<ENTER>
w
7.6. Format the new partition and label it#
You have a few choices of the filesystem type that you could use. ext4
tends to be a popular choice. btrfs
is another one.
I will be using btrfs
. But you can go with ext4
if you prefer.
sudo mkfs -t btrfs /dev/sda1
$sudo btrfs filesystem label /dev/sda1 "bacula_disk"
8. Set up the USB disk in vchanger#
8.1. Find the UUID of the USB disk#
sudo blkid /dev/sda1
The output will be something like this. We are interested in the highlighted part:
/dev/sda1: LABEL=“bacula_disk” UUID=“538dec6e-f355-4b6e-8045-c4841c967d97
” UUID_SUB=“9309f4cf-c0e4-42a5-8b7e-195069728dd7” BLOCK_SIZE=“4096” TYPE=“btrfs” PARTUUID=“99e4d81a-01”
8.2. Create the vchanger configuration file#
Remember that each USB disk configured under vchanger is a virtual tape autochanger. There can be multiple autochangers - each with a unique name. In our case, we are going to configure vchanger0
(you could call it pretty much anything you want).
In the example below, be sure to substitute the UUID of your disk when running the commands.
sudo mkdir -p /etc/vchanger
Next, paste the following into /etc/vchanger/vchanger0.conf using a text editor like vi or emacs or nano (you will need root privileges)
bconsole = /usr/sbin/bconsole
bconsole config = /etc/bacula/bconsole.conf
Storage Resource = vchanger0
User = bacula
Group = tape
Magazine = UUID:538dec6e-f355-4b6e-8045-c4841c967d97
Logfile = /var/log/bacula/vchanger0.log
Log Level = 7 # Reduce this after the setup and any debugging
#EOF
8.3. Generate udev rules to automatically mount and unmount the disk#
Important
The vchanger udev scripts reference
/usr/libexec/vchanger/vchanger-launch-mount.sh
and/usr/libexec/vchanger/vchanger-launch-umount.sh
. However, the actual scripts get installed into /usr/local/libexec/vchanger.
To overcome this, create a symbolic link as shown below before running vchanger-genudevrules.
sudo sudo ln -s /usr/local/libexec/vchanger /usr/libexec/vchanger
sudo sh -c 'vchanger-genudevrules > /etc/udev/rules.d/90-vchanger.rules'
sudo udevadm control --reload-rules
Note
You need to generate the udev rules any time you make any changes to the disk setup in vchanger0.conf
8.4. Create the mount point and set permissions#
sudo mkdir -p /mnt/vchanger
sudo chown bacula:tape /mnt/vchanger
sudo chmod 750 /mnt/vchanger
sudo mkdir -p /etc/sysconfig
sudo sh -c "echo 'MOUNT_DIR=/mnt/vchanger' > /etc/sysconfig/vchanger"
sudo sh -c "echo 'MOUNT_OPTIONS=' >> /etc/sysconfig/vchanger"
8.5. Attach the USB disk#
If the disk is already plugged in, unplug it first, and then plug it back in to trigger the vchanger udev rule to mount the disk.
Note
The vchanger mount scripts use at
to run commands in the background. So, be sure that it’s available. Otherwise, install it (sudo apt install at)
9. Configure Bacula to use vchanger#
9.1. Configure the Bacula Storage Daemon#
In the configuration file of the Storage Daemon (/etc/bacula/bacula-sd.conf), delete the definitions of sample autochangers that are present. Then, add the definition of the vchanger0 autochanger and the devices in the autochanger. In the setup shown below, we are configuring the autochanger with 5 virtual devices
# vchanger Autochanger vchanger0 with 5 virtual devices
Autochanger {
Name = usb-vchanger0
Device = usb-vchanger0-drive-0
Device = usb-vchanger0-drive-1
Device = usb-vchanger0-drive-2
Device = usb-vchanger0-drive-3
Device = usb-vchanger0-drive-4
Changer Command = "/usr/local/bin/vchanger %c %o %S %a %d"
Changer Device = "/etc/vchanger/vchanger0.conf"
}
# Define The Virtual Devices For vchanger0
Device {
Name = usb-vchanger0-drive-0
Drive Index = 0
Autochanger = yes;
Device Type = File
Media Type = File
Automatic Mount = yes;
Always Open = yes;
Automatic Mount = yes;
Always Open = yes;
Removable Media = yes;
Random Access = yes;
Label media = yes;
Maximum Concurrent Jobs = 1
Volume Poll Interval = 15
Archive Device = "/usr/local/var/spool/vchanger/vchanger0/0"
Alert Command = "sh -c 'smartctl -H -l error %c'"
# Alert Command = "/etc/bacula/scripts/tapealert %1; sh -c 'smartctl -H -l error %c'"
}
Device {
Name = usb-vchanger0-drive-1
Drive Index = 1
Autochanger = yes;
Device Type = File
Media Type = File
Automatic Mount = yes;
Always Open = yes;
Automatic Mount = yes;
Always Open = yes;
Removable Media = yes;
Random Access = yes;
Label media = yes;
Maximum Concurrent Jobs = 1
Volume Poll Interval = 15
Archive Device = "/usr/local/var/spool/vchanger/vchanger0/1"
Alert Command = "sh -c 'smartctl -H -l error %c'"
# Alert Command = "/etc/bacula/scripts/tapealert %1; sh -c 'smartctl -H -l error %c'"
}
Device {
Name = usb-vchanger0-drive-2
Drive Index = 2
Autochanger = yes;
Device Type = File
Media Type = File
Automatic Mount = yes;
Always Open = yes;
Automatic Mount = yes;
Always Open = yes;
Removable Media = yes;
Random Access = yes;
Label media = yes;
Maximum Concurrent Jobs = 1
Volume Poll Interval = 15
Archive Device = "/usr/local/var/spool/vchanger/vchanger0/2"
Alert Command = "sh -c 'smartctl -H -l error %c'"
# Alert Command = "/etc/bacula/scripts/tapealert %1; sh -c 'smartctl -H -l error %c'"
}
Device {
Name = usb-vchanger0-drive-3
Drive Index = 3
Autochanger = yes;
Device Type = File
Media Type = File
Automatic Mount = yes;
Always Open = yes;
Automatic Mount = yes;
Always Open = yes;
Removable Media = yes;
Random Access = yes;
Label media = yes;
Maximum Concurrent Jobs = 1
Volume Poll Interval = 15
Archive Device = "/usr/local/var/spool/vchanger/vchanger0/3"
Alert Command = "sh -c 'smartctl -H -l error %c'"
# Alert Command = "/etc/bacula/scripts/tapealert %1; sh -c 'smartctl -H -l error %c'"
}
Device {
Name = usb-vchanger0-drive-4
Drive Index = 4
Autochanger = yes;
Device Type = File
Media Type = File
Automatic Mount = yes;
Always Open = yes;
Automatic Mount = yes;
Always Open = yes;
Removable Media = yes;
Random Access = yes;
Label media = yes;
Maximum Concurrent Jobs = 1
Volume Poll Interval = 15
Archive Device = "/usr/local/var/spool/vchanger/vchanger0/4"
Alert Command = "sh -c 'smartctl -H -l error %c'"
# Alert Command = "/etc/bacula/scripts/tapealert %1; sh -c 'smartctl -H -l error %c'"
}
9.1.1. Change the IP address that the Storage Daemon listens on#
Storage { # definition of myself
Name = server01-sd
SDPort = 9103 # Director's port
WorkingDirectory = "/var/lib/bacula"
Pid Directory = "/run/bacula"
Plugin Directory = "/usr/lib/bacula"
Maximum Concurrent Jobs = 20
SDAddress = server01.example.com # Change this from 127.0.0.1
}
9.2. Create the directory for use by the archive devices#
sudo mkdir -p /usr/local/var/spool/vchanger/vchanger0
sudo chown -R bacula:tape /usr/local/var/spool/vchanger
9.3. Configure the Bacula Director#
9.3.1. Define the Autochanger Resource#
Open /etc/bacula/bacula-dir.conf in a text editor (with root privileges), find the existing Autochanger definitions, and add a new one similar to what’’s shown below.
Tip
You can use /dev/urandom to generate the password(s) below. For example, to generate a 16-character password:
tr -dc A-Za-z0-9_ < /dev/urandom | head -c 16 | xargs
# vchanger autochanger vchanger0
Autochanger {
Name = vchanger0
Address = server01.example.com
SDPort = 9103
Password = "<PASSWORD_MUST_MATCH_STORAGE_DAEMON>"
Device = usb-vchanger0
Media Type = File
Maximum Concurrent Jobs = 2
}
9.3.2. Define the vchanger Storage Pool#
In /etc/bacula/bacula-dir.conf, find existing definitions of storage pools. Add the following after the last pool definition (you can add it anywhere in the file, but grouping them together works better for me).
# vchanger Pool definition
Pool {
Name = vchanger0-pool
Pool Type = Backup
Recycle = yes # Bacula can automatically recycle Volumes
AutoPrune = yes # Prune expired volumes
Volume Retention = 7 days # one Week
Maximum Volume Bytes = 5G # Limit Volume size to something reasonable
Maximum Volumes = 100 # Limit number of Volumes in Pool
Recycle Pool = Scratch # Recycle Pool
}
Note
I have used a “Maximum Volume Bytes” of 5G because I am only using a 100GB USB disk. If you have a bigger disk, you could set “Maximum Volume Bytes” to 20G or even 50G easily.
The selected size needs to be a balance between the number of files that get created, and the ability to recycle them periodically
9.3.3 Enter Catalog DB connection parameters#
In /etc/bacula/bacula-dir.conf, find the “Catalog” section with sample DB connection parameters. Modify it for your setup. Enter the parameters (including password) that you defined
# Generic catalog service
Catalog {
Name = MyCatalog
dbname = "bacula"; DB Address = "localhost"; DB Port = "5432" ; dbuser = <USERID>; dbpassword = <PASSWORD>
}
10. Verify the configuration#
sudo bacula-sd -t
sudo bacula-dir -t
11. Restart the Bacula Daemons#
sudo systemctl restart bacula-sd
sudo systemctl restart bacula-dir
12. Create vchanger volumes#
At this point, the installation and initial configuration is done. We can create the vchanger volumes (virtual tapes) that we will use for backing up our data to. We’ll create 10 for now. More can always be added as needed.
sudo vchanger /etc/vchanger/vchanger0.conf createvols 0 10
You should see output like below
creating label 'vchanger0_0000_0000'
creating label 'vchanger0_0000_0001'
creating label 'vchanger0_0000_0002'
creating label 'vchanger0_0000_0003'
creating label 'vchanger0_0000_0004'
creating label 'vchanger0_0000_0005'
creating label 'vchanger0_0000_0006'
creating label 'vchanger0_0000_0007'
creating label 'vchanger0_0000_0008'
creating label 'vchanger0_0000_0009'
Created 10 volume files on magazine 0
If you look under /mnt/vchanger/<YOUR_DISK_UUID>, you should see 10 files (only a few bytes in size each). These are all ready to store your data.
Your configuration files should now look similar to these:
Tip
If you encountered errors, you can check the server log (/var/log/syslog or /var/log/messages), as well as bacula logs under /var/log/bacula.
If you reached this point successfully, Congratulations!
You completed most of the groundwork for backing up files with Bacula. Next, we will configure the Bacula client(s), as well as the director to define the computers that need to be backed up, the files to be backed up, the backup schedule, the type of backup (full, incremental) etc.
Comments
Comments powered by giscus, use a GitHub account to comment.