Tutorial

Installing and Configuring Bacula on an Ubuntu 12.04 VPS

Published on July 5, 2013
Installing and Configuring Bacula on an Ubuntu 12.04 VPS

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

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.

Introduction

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
  Client=Blank-fd
  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:

label
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:

run
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:

yes

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:

messages

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.

help

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

done

Confirm that you would like to restore:

yes

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

messages

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

exit

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

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products


Tutorial Series: How to Leverage Bacula to Back Up your Ubuntu 12.04 Servers

Bacula is sophisticated backup solution that can be used to back up servers over a network. In this series, we will cover how to install and configure Bacula on Ubuntu 12.04 servers. We will then demonstrate how to configure remote backups in order to set up a system to keep safe copies of any computer in your infrastructure.

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
6 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
June 26, 2014

@chittukuruvii: What options did you uses with rsync? Unless you’re telling it to delete files in the destination directory that don’t exist in the source directory, it won’t change much if all you did was install curl. Of course be extremely careful with that if you are rsyning to your root directory!

I think you’d be much better off restoring specific directories rather than the entire root file system.

Can you explain a bit more? Let’s say I made backup “bk1”. After the backup I install “curl” on my ubuntu and now I want to roll back ubuntu to the state where I don’t have curl installed i.e., bk1. How can I do that?

if I restore from bk1 then all the new modified files?? goes under “/bacula/restore”. I tried to rscyn /bacula/restore to my root / but didn’t change anything.

coool backup took 10min and restoring took only 2sec :D

wow thanks for this tutorial, bacula is amazing :D:D

Justin Ellingwood
DigitalOcean Employee
DigitalOcean Employee badge
November 12, 2013

Thanks for the catch Phil! I’ve updated the link.

good stuff…

However, the how to configure remote backups using bacula link is a 404

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more