How to install Bacula Server on Ubuntu 14.04

Introduction

Bacula is an open source network backup solution that allows you to create backups and perform data recovery of computer systems. It is very flexible and powerful, which makes it a little cumbersome to configure and suitable for backup in many situations. The backup system is an important component in most server infrastructures, because recovering from data loss is usually a critical part of a disaster recovery plan.

In this tutorial, we will show you how to install and configure the server components of Bacula on an Ubuntu 14.04 server. We will configure Bacula to perform weekly jobs and create local backups (ie backups of its own host). This in itself is not a particularly compelling use for Bacula, but it will provide you with a good starting point for creating backups of other servers (ie, backup clients). The next tutorial in this series will introduce how to create backups of other remote servers by installing and configuring the Bacula client and configuring the Bacula server.

Preparation

An Ubuntu** server** with a non-root account that can use the sudo command has been set up, and the firewall has been turned on. Students who don’t have a server can buy it from here, but I personally recommend you to use the free Tencent Cloud Developer Lab for experimentation, and then purchase server.

We will configure Bacula to use the private FQDN of our server, such as bacula.private.example.com. If you do not have DNS settings, please use the corresponding IP address instead. If you have not enabled the private network, please replace all the network connection information in this tutorial with a network address accessible by the relevant server (for example, a public IP address or V** tunnel).

Let us first look at an overview of the Bacula components.

Overview of Bacula Components

Although Bacula consists of several software components, it follows the server-client backup model; to simplify the discussion, we will focus more on backup server and **backup client, rather than a single Bacula component. Nevertheless, a rough understanding of the various Bacula components is still important, so we will discuss them now.

Bacula Server, which we also call "Backup Server", has the following components:

Note: Bacula server components do not need to run on the same server, but they work together to provide backup server functionality.

Bacula Client, the server to be backed up, runs File Daemon (FD) component. The file daemon is a piece of software that provides the Bacula server (especially the Director) with access to the data to be backed up. We also refer to these servers as "backup clients" or "clients."

As we mentioned in the introduction, we will configure the backup server to create a backup of its own file system. This means that the backup server will also be the backup client and will run the file daemon component.

Let's start the installation.

Install MySQL

Bacula uses a SQL database (such as MySQL or PostreSQL) to manage its backup directory. We will use MySQL in this tutorial.

First, update apt-get:

sudo apt-get update

Now install MySQL Server using apt-get:

sudo apt-get install mysql-server

You will be prompted to enter the password of the MySQL database management user root. Enter the password, and then confirm.

Remember this password because it will be used during the Bacula installation process.

Install Bacula

Use apt-get to install the Bacula server and client components:

sudo apt-get install bacula-server bacula-client

You will be prompted to enter some information that will be used to configure Postfix, which Bacula uses:

Next, you will be prompted to enter the information that will be used to set up the Bacula database:

The final step of the installation is to update the permissions of the scripts Bacula uses in its catalog backup jobs:

sudo chmod 755/etc/bacula/scripts/delete_catalog_backup

The Bacula server (and client) components are now installed. Let's create a backup and restore directory.

Create backup and restore directories

Bacula needs a backup directory-for storing backup archives-and a restore directory-where the restored files will be placed. If your system has multiple partitions, make sure to create the directory on a directory with enough space.

Let's create new directories for these two purposes:

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

We need to change the file permissions so that only the bacula process (and super user) can access these locations:

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

Now we are ready to configure Bacula Director.

Configure Bacula Director

Bacula has several components that must be configured independently in order to function properly. Configuration files can be found in the /etc/bacula directory.

We will start with Director Bacula.

Open the Bacula Director configuration file in your favorite text editor. We will use vi:

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

Configure local jobs

Bacula jobs are used to perform backup and restore operations. The job resource defines the detailed information of the operation that a specific job will perform, including the name of the client, the FileSet to be backed up or restored, etc.

Here, we will configure the job that will be used to perform a local file system backup.

In the Director configuration, find the Job resource named "BackupClient1" (search for "BackupClient1"). Change the Name value to "BackupLocalFiles", so it looks like this:

Job {
 Name ="BackupLocalFiles"
 JobDefs ="DefaultJob"}

Next, find the job resource named "RestoreFiles" (search for "RestoreFiles"). In this work, you want to change two things: update the Name value to "RestoreLocalFiles", and update the Where value to "/bacula/restore". It should look like this:

Job {
 Name ="RestoreLocalFiles"
 Type = Restore
 Client=BackupServer-fd
 FileSet="Full Set"
 Storage = File
 Pool = Default
 Messages = Standard
 Where =/bacula/restore
}

This will configure the RestoreLocalFiles job to restore the /bacula/restore files to the directory we created earlier.

Configuration file set

Bacula FileSet defines a set of files or directories to include or exclude files in the backup selection and used by the job.

Find the FileSet resource named "Full Set" (it is in the comment, "#List of files to be backed up"). Here we will make three changes: (1) add the option to compress our backup using gzip, (2) change the included file from /usr/sbin to /, and (3) change the second excluded file Change to /bacula. After deleting the comment, it should look like this:

FileSet {
 Name ="Full Set"
 Include {
 Options {
  signature = MD5
  compression = GZIP
    }    
File =/}
 Exclude {
 File =/var/lib/bacula
 File =/bacula
 File =/proc
 File =/tmp
 File =/.journal
 File =/.fsck
  }}

Let's review the changes we made to the "Full Set" file set. First, we enabled gzip compression when creating the backup archive. Second, we want to include the / backup, the root partition. Third, we exclude /bacula because we don't want to redundantly backup our Bacula backup and restore files.

Note: If you have partitions mounted in / and want to include these partitions in the FileSet, you need to add additional file records for each partition.

Keep in mind that if a wide set of files (such as a "full set") is always used in a backup job, the backup will require more disk space than the more specific disk space of the backup selection. For example, only a FileSet containing custom configuration files and databases may be sufficient to meet your needs. If you have a clear recovery plan, specify in detail to install the required software packages and place the recovered files in the appropriate location, and only use one A small portion of the disk space for the backup archive.

Configure storage daemon connection

In the Bacula Director configuration file, the Storage resource defines the Storage Daemon that the Director should connect to. We will configure the actual storage daemon in a short time.

Find the storage resource and replace the value of Address with the dedicated FQDN (or dedicated IP address) of the localhost backup server. It should look like this (replace the phrase after Address=):

Storage {
 Name = File
# Do not use "localhost" here
 Address = backup_server_private_FQDN                # N.B. Use a fully qualified name here
 SDPort =9103
 Password ="ITXAsuVLi1LZaSfihQ6Q6yUCYMUssdmu_"
 Device = FileStorage
 Media Type = File
}

This is necessary because we want to configure the storage daemon to listen on a dedicated network interface so that remote clients can connect to it.

Configure Pool

The Pool resource defines the save set used by Bacula to write backups. We will use files as our storage volume, we just need to update the label so that our local backups are properly labeled.

Find the pool resource named "File" (it is located under the comment "#File Pool definition") and add a line to specify the label format. It should look like this when you are done:

# File Pool definition
Pool {
 Name = File
 Pool Type = Backup
 Label Format = Local-
 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
}

Save and exit. You have finally completed the configuration of the Bacula Director.

**Check Director configuration: **

Let us verify that there are no syntax errors in your Director configuration file:

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

If there is no error message, your bacula-dir.conf file has no syntax errors.

Next, we will configure the storage daemon.

Configure storage daemon

Our Bacula server is almost set up, but we still need to configure the storage daemon, so Bacula knows where to store backups.

Open the SD configuration in your favorite text editor. We will use vi:

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

Configure storage resources

Find storage resources. This defines where the SD process listens for connections. Add the SDAddress parameter and assign it to the dedicated FQDN (or dedicated IP address) of the backup server:

Storage {                             # definition of myself
 Name = BackupServer-sd
 SDPort =9103                  # Director's port
 WorkingDirectory ="/var/lib/bacula"
 Pid Directory ="/var/run/bacula"
 Maximum Concurrent Jobs =20
 SDAddress = backup_server_private_FQDN
}

Configure storage device

Next, find the Device resource named "FileStorage" (search for "FileStorage"), and update the value of Archive Device to match the backup directory:

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 exit.

Verify storage daemon configuration

Let us verify if there is a syntax error in your Storage Daemon configuration file:

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

If there is no error message, your bacula-sd.conf file has no syntax errors.

We have completed the Bacula configuration. We are ready to restart the Bacula server component.

Restart Bacula Director and Storage Daemon

To make the configuration changes you make take effect, restart the Bacula Director and Storage Daemon with the following commands:

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

Now that both services have been restarted, let's test whether it is working properly by running a backup job.

Test backup job

We will use the Bacula console to run our first backup job. If it runs without any problems, we will know that Bacula is configured correctly.

Now use the following command to enter the console:

sudo bconsole

This will take you to the Bacula Console prompt, indicated by the * prompt.

Create label

First issue the label command:

label

You will be prompted to enter the volume name. Enter any name you want:

MyVolume

Then select the pool that the backup should use. We will use the previously configured "file" pool, enter "2":

2

Run a backup job manually

Bacula now knows how we write data for the backup. We can now run our backup to test if it is working:

run

You will be prompted to select the job to run. We want to run the "BackupLocalFiles" job, so enter "1" at the prompt:

1

At the "Run Backup Job" confirmation prompt, review the details, and then enter "Yes" to run the job:

yes

Check messages and status

After completing a job, Bacula will tell you that you have news. The message is the output generated by running the job.

Type the following to check the mail:

messages

The message should say "The previous full backup job record could not be found" and the backup job has started. If there is any error, it is wrong and they should give you a hint that the job is not running.

Another way to check the status of the job is to check the status of the Director. To do this, enter the following command at the bconsole prompt:

status director

If everything is ok, you should see your work is running. Something like this:

Running Jobs:
Console connected at 09-Apr-1512:16
 JobId Level   Name                       Status
======================================================================3 Full    BackupLocalFiles.2015-04-09_12.31.41_06 is running
====

When your work is completed, it will be moved to the "Ended Jobs" section of the status report as shown below:

Terminated Jobs:
 JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================3 Full    161,124877.5 M  OK       09-Apr-1512:34 BackupLocalFiles

The "OK" status means that the backup job runs without any problems. Congratulations! You have a "Full Set" backup of the Bacula server.

The next step is to test the restore job.

Test restore job

Now that the backup has been created, it is important to check whether it can be restored correctly. The restore command will allow us to restore the files that have been backed up.

Run restore all jobs

To demonstrate, we will restore all files from the last backup:

restore all

A selection menu will appear with many different options to identify the backup set from which to restore. Since we only have one backup, let's "select the latest backup"-choose option 5:

5

Because there is only one client, the Bacula server, it will automatically be selected.

The next prompt will ask you which FileSet you want to use. Select "Full Set", it should be 2:

2

This will take you to a virtual file tree that contains the entire directory structure you backed up. This shell-like interface allows simple commands to mark and unmark the files to be restored.

Because we specified to "restore all", every backup file has been marked for restoration. The marked file is represented by the leading * character.

If you want to fine-tune your choices, you can use the "ls" and "cd" commands to navigate and list the files, use "mark" to mark the files to be restored, and use "unmark" to unmark the files. By typing "help" in the console, you can get a complete list of commands.

After completing the recovery selection, type the following:

done

Confirm that you want to run the restore job:

yes

Check messages and status

As with the backup job, you should check the message and Director status after running the restore job.

Type the following to check the mail:

messages

There should be a message stating that the restore job has been started or terminated and has a "restore normal" status. If there is any error, it is wrong and they should give you a hint that the job is not running.

Similarly, checking the Director status is a good way to view the status of the restore job:

status director

After the restoration is complete, type exit to exit the Bacula console:

exit

Verify restore

To verify that the restore job actually restored the selected files, you can view the /bacula/restore directory (defined in the "RestoreLocalFiles" job in the Director configuration):

sudo ls -la /bacula/restore

You should see a copy of the restored files in the root file system, excluding the files and directories listed in the "Exclude" section of the "RestoreLocalFiles" job. If you are trying to recover from data loss, you can copy the restored files to an appropriate location.

Delete restored files

You may want to delete the restored files to free up disk space. To do this, use the following command:

sudo -u root bash -c "rm -rf /bacula/restore/*"

Please note that you must run this rm command as root, because many restored files are owned by root.

in conclusion

You now have a basic Bacula setup to back up and restore the local file system. The next step is to add other servers as backup clients to restore them in case of data loss.

For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.

Reference: "How To Install Bacula Server on Ubuntu 14.04"

Recommended Posts

How to install Bacula Server on Ubuntu 14.04
How to install Zabbix on Ubuntu 16.04 Server
How to install Squid proxy server on Ubuntu 18.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to install MySQL on Ubuntu 18.04 (linux)
How to use Samba server on Ubuntu 16.04