We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

Installing and Configuring Bacula on an Ubuntu 12.04 VPS

Posted Jul 5, 2013 66.1k views Backups MySQL Ubuntu

What the Red Means

The lines that the user needs to enter or customize will be in red in this tutorial! The rest should mostly be copy-and-pastable.


Bacula is a sophisticated backup solution that can handle local and remote backups by leveraging a client-server model. It has very flexible configuration options that provide complete control over the backup environment.

In this guide, we will be backing up the entire root filesystem of our Ubuntu 12.04 VPS.

An updated version of this guide can be found here: How To Install Bacula Server on Ubuntu 14.04.

Installing MySQL

Bacula uses an SQL database to manage its information. We will be using MySQL for this tutorial.

For an Ubuntu 12.04 VPS, this setup must be installed in advance, or else the following error will occur during installation of the bacula suite:

An error occurred while installing the database:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 

To avoid this situation, we can simply install MySQL prior to installing the bacula components:

sudo apt-get update
sudo apt-get install mysql-server

You will be prompted to provide and confirm a database administrator password. Enter a password to continue.

Installing Bacula

Next, we will install the bacula components:

sudo apt-get install bacula-server bacula-client

You will be prompted to set up a database for bacula. Select "yes" to allow dbconfig-common to automatically configure the database.

When prompted, enter the database administrator password that you selected when installing MySQL. It will then ask for an application password for bacula-director-mysql. Press "Enter" or "Return" to generate a random password.

Filesystem Configuration

Next, we need to create some directories to act as our backup and restore points.

Using the "-p" flag with the "mkdir" command creates any necessary parent directories along with the target directory:

sudo mkdir -p /bacula/backup /bacula/restore

We need to change the file permissions so that only the bacula process can access these locations.

sudo chown -R bacula:bacula /bacula
sudo chmod -R 700 /bacula

Configuring Bacula

Bacula has several components that must be configured independently in order to function correctly. The configuration files can all be found in the /etc/bacula/ directory.

Configuring bacula-dir.conf

Start by editing the bacula-dir.conf file:

sudo nano /etc/bacula/bacula-dir.conf

A few different sections must be modified for the backups that we will be performing in this guide.

First, search for the "Standard Restore template" section. Under the "Job" settings, change the Where parameter to point to the restore point we created:

Job {
  Name = "RestoreFiles"
  Type = Restore
  FileSet="Full Set"
  Storage = File
  Pool = Default
  Messages = Standard
  Where = /bacula/restore

Next, search for the "List of files to be backed up" section. Under the "FileSet" settings, we will add an option to use gzip to compress our archives.

We will then specify exactly what we would like to backup with the "File =" parameter. You can have multiple "File =" declarations in this section, each with a different path.

For this guide, we will be backing up the entire root (/) file system. Change the parameters to reflect that:

Include {
    Options {
      signature = MD5
      compression = GZIP
#  Put your list of files here, preceded by 'File =', one per line
#    or include an external list with:
#    File = file-name
#  Note: / backs up everything on the root partition.
#    if you have other partitions such as /usr or /home
#    you will probably want to add them too.
#  By default this is defined to point to the Bacula binary
#    directory to give a reasonable FileSet to backup to
#    disk storage during initial testing.
    File = /

Finally, add file paths to be excluded from the backup. This is done in the Exclude section of the FileSet directory by using the same "File =" syntax that we used in the Include section.

The defaults are generally good here, but we need to change the path to the archive directory. We do not want to backup the backup folder. Change the second "File =" to reflect our root bacula file path:

Exclude {
    File = /var/lib/bacula
    File = /bacula
    File = /proc
    File = /tmp
    File = /.journal
    File = /.fsck

Save and close the file.

Configuring bacula-sd.conf

The next file we need to edit is the bacula-sd.conf file. This will define the area where bacula stores its backups.

Open the bacula-sd.conf file with sudo privileges:

sudo nano /etc/bacula/bacula-sd.conf

Under the "Devices supported by this Storage daemon" section, in the "Device" configuration, change the Archive Device to reflect the backup location we set up earlier:

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;

Save and close the file.

Checking Configuration Syntax

Before continuing, check that the configuration options that we used are recognized by bacula. We can use bacula's internal testing utilities to ensure that there are no syntax errors in the files we modified.

First, check the bacula director configuration:

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

If the command executes without returning any output, the configuration file is syntactically correct. Next, check the bacula storage configuration:

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

Again, no output signifies that our configuration file is valid.

At this time, restart the bacula services we modified to make the changes propagate:

sudo service bacula-sd restart
sudo service bacula-director restart

We are now ready to test our backups.

Testing the Backup

We will be interacting with bacula through its internal console. This can be accessed with the "bconsole" command:

sudo bconsole

You will be dropped into a bacula console with an asterisk (*) for a prompt. Begin by issuing the "label" command. You will be prompted to enter a name for the archive file that will be created:

Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
Automatically selected Storage: File
Enter new Volume name: MyArchiveName

Select the kind of storage "pool" for the backup. Since our backup will be stored as a file, select #2:

2: File

Bacula now knows how we want to write the data for our backup. We can now run our backup to test that it works correctly:

A job name must be specified.
The defined Job resources are:
     1: BackupClient1
     2: BackupCatalog
     3: RestoreFiles
Select Job resource (1-3):

Select #1 to choose the backup that we configured.

1: BackupClient1

At the prompt, type "yes" to perform the backup:


Bacula will tell you that you have messages. The messages will be the output generated by the backup. Check the messages for errors by typing:


You will see some output lines. Check again until you see a summary showing the results of the backup. It might take a few minutes. It should say "Termination: Backup OK". Check that no errors were generated.

Testing the Restore

Now that a backup has been created, it is important to check that it can be restored properly. In the bacula console, type:

restore all

A selection menu will appear with many different options. We would like to restore the most recent backup, so select Option 5:

5: Select the most recent backup for a client

This will drop you into a virtual file tree with the entire directory structure that you backed up. This interface allows for simple commands to mark and unmark files to be restored.

Because we specified that we wanted to "restore all", every backed up file is pre-selected for restoration.

If you would like to fine-tune your selection, you can navigate and list files with the "ls" and "cd" commands, mark files for restoration with "mark", and unmark files with "unmark". A full list of commands is available by typing "help" into the console.


When you are finished, exit the file selection by typing:


Confirm that you would like to restore:


Again, check the messages for errors when the restoration is complete.


The summary should have a line that reads "Termination: Restore OK". When you are finished, type "exit" to leave the bacula console:


Checking the Filesystem

To check that the backup was completed as expected, list the contents of the backup directory. You will need to use sudo since the directory structure is owned by the "bacula" user:

sudo ls /bacula/backup

You should see a file with the archive name you chose.

Next, we should check our restore point. List the contents of the restore point directory:

sudo ls /bacula/restore

You should see a mirror of the root file structure, excluding the files and directories that were listed in the "Exclude" section of the bacula-dir.conf file.

You now have a basic bacula setup that can backup your local filesystem. Bacula is also a powerful solution for remote backups. Click here to learn how to configure remote backups using bacula.

By Justin Ellingwood


Creative Commons License