Setting up your Bareos backup on a container

Created by Michelle Ritzema at 27-10-2017 16:13:31 +0200

This how to will help you set up a backup system for your cloud environment. It lets you back up one or more containers. The open source software Bareos will be used.

IMPORTANT
In this tutorial you will often find commands that include words surrounded with angle brackets. You need to replace these words, including the brackets themselves, with your own values.

For example, the command:

ssh <user>@<your_ip_address>

will become:

ssh root@192.168.20.1

if your user is 'root' and your IP address is '192.168.20.1'.

Steps

1. Create a backup server container
2. Setup the backup server container
    2.1 General steps
    2.2 Install and configure postgresql
    2.3 Install and configure Bareos
    2.4 Add custom configuration
3. Install Bareos client on each container
    3.1 Install Bareos client
    3.2 Configure Bareos client
4. Add client container to backup server

1. Create a backup server container

First of all, a container should be created on cloudcontainers.net to run the Bareos server software. We recommend setting up a container with an Ubuntu operating system. Choosing a different OS is possible, but some of the commands below are written specifically for Ubuntu and will have to be altered to your platform accordingly.
Continue once the container has been created successfully.

2. Setup the backup server container

2.1 General steps

Log in with SSH
Log in to your new container with the SSH protocol via the command line. When creating a new LX container, the username will always be 'root'. If you have a KVM container, the username you need to log in with will be 'ubuntu'.

ssh <user>@<your_ip_address>

Update and upgrade
It is important with a new container to always update and upgrade before doing anything else. If prompted to continue, type 'y' or 'yes' and press enter.

apt-get update
apt-get upgrade

IMPORTANT

Hostname
Before continuing with the following steps, make sure to set the hostname and reboot the zone. If this is not done correctly, you will end op with the error "director seems to be down or blocking our request" later down the line, when trying to log into the Bareos WebUI.

hostname <hostname>
reboot

2.2 Install and configure Postgresql

Postgresql is used by Bareos as the default database. If prompted to continue, type 'y' or 'yes' and press enter.

apt-get install postgresql

After Postgresql has been successfully installed, you need to configure it to allow Bareos to use it. Open the 'pg_hba.conf' file with the command below. Notice that you need to specify the postgresql version you are using. If you are not sure, you can run "psql --version".

vim /etc/postgresql/<postgresql_version>/main/pg_hba.conf

Navigate to the bottom of the file, and add the following line at the bottom:

local   all             bareos                                  peer


2.3 Install and configure Bareos

Add the Bareos release key
Start by adding the Bareos release key. Make sure you enter the correct operating system and version number.

wget -q http://download.bareos.org/bareos/release/latest/<operating_system>_<version>/Release.key -O- | apt-key add -

Add the Aptitude repository link
Add the link to the correct repository. Make sure you enter the correct operating system and version number.

echo "deb http://download.bareos.org/bareos/release/latest/<operating_system>_<version> /" >> /etc/apt/sources.list

Update container
Update your container again to make sure you will download the correct Bareos version.

apt-get update

Install Bareos
Install the complete Bareos package. If prompted to continue, type 'y' or 'yes' and press enter.

apt-get install bareos

You will see a configuration screen for Postfix. Choose the default option: Internet Site. After this, you can choose your system mail name, this can be any value you like. Next, Bareos will ask you if you want the database configured. You can choose 'yes' for this. Select "localhost" as the host name of the PostgreSQL database. Finally, leave the password field blank to allow for ident authentication.

Install Bareos-WebUI
For the interactive web interface, we need to install the Bareos-WebUI package next. If prompted to continue, type 'y' or 'yes' and press enter.

apt-get install bareos-webui

Start all services
Now it's time to start all necessary services. Bareos consists of three parts, the director daemon (the central control program), storage daemon (for storing file attributes and data to physical media) and file daemon (for sending files to the storage daemon). Apache is used by the Bareos-WebUI and must therefore be restarted for the changes to take effect.

service bareos-dir start
service bareos-sd start
service bareos-fd start
service apache2 restart

Create a Bareos WebUI user
To use the Bareos WebUI in your web browser, you have to create a new user. First, start up the Bareos console.

bconsole

Next, create a new user with the following command. Make sure to store the username and password in a secure location.

configure add console name=<username> password=<password> profile=webui-admin

After this, you can log in to your Bareos container via your browser. Enter your container's domain name (or alternatively your IP address), and add "/bareos-webui" behind it.

2.4 Add custom configuration

Bareos definitions
Job = A single task the Bareos director executes, like backing up one of your containers
Jobdef = A definition that can set defaults for jobs (can be overruled in the job resource itself)
Schedule = A plan that determines when to start certain jobs
Fileset = A plan of what data should or shouldn't be backed up
Volume
= A single file on which Bareos will write the backup data for one or more days
Pool = Groups together volumes with the same configuration

To make sure your backup server is performing optimally, the following configuration changes are recommended. Feel free to change these configurations to your needs if you require a different setup.

Settings used in the configurations below
Used pools Full, Incremental
Maximum volumes (amount of volumes Bareos can create in a pool) Full: 5, Incremental: 35
Volume retention (amount of time to keep a volume) Full: 30 days, Incremental: 30 days
Volume Use Duration (amount of time to use a particular volume) Full: 5 days, Incremental: 1 day
Recycling old volumes yes
Autoprune (marking an expired volume as reusable) yes
Maximum Volume Jobs (amount of jobs Bareos can store on one volume) 0 (unlimited)


IMPORTANT

After changing any configuration in Bareos, it is important to reload for the changes to take effect. Most of the time, simply reloading configuration in the Bareos console is enough.

echo "reload" | bconsole

If this is not enough, the Bareos services can be restarted with the following commands.

service bareos-dir restart
service bareos-sd restart
service bareos-fd restart


Define pools
Pools are placed in the 'pool/' directory, each pool has its own .conf file. We use only the Full and Incremental pools for backup. Volumes belonging to the Full pool will be used for five consecutive days, whilst volumes from the Incremental pool will be used for one day only. There will be a total of 5 Full volumes and 35 Incremental volumes. Because recycling is set, expired volumes will be overwritten with new data. This ensures that your backup container will not eventually overflow with stored data and run out of memory.

Alter the existing pool files to resemble the settings below:

vim /etc/bareos/bareos-dir.d/pool/Full.conf

Full.conf

Pool {
  Name = Full
  Pool Type = Backup
  Recycle = yes                         # Bareos can automatically recycle volumes
  Recycle Oldest Volume = yes           # Recycle the oldest volume if none are free
  AutoPrune = yes                       # Prune expired volumes
  Volume Retention = 30 days          # Amount of time the backups should be kept
  Maximum Volume Jobs = 0                       # Amount of jobs on a volume, 0 = unlimited
  Maximum Volumes = 5                              # Limit the number of volumes in the pool
  Volume Use Duration = 5d              # Amount of time a volume can be used
  Label Format = "Full-"
}
vim /etc/bareos/bareos-dir.d/pool/Incremental.conf

Incremental.conf

Pool {
  Name = Incremental
  Pool Type = Backup
  Recycle = yes                         # Bareos can automatically recycle volumes
  Recycle Oldest Volume = yes           # Recycle the oldest volume if none are free
  AutoPrune = yes                       # Prune expired volumes
  Volume Retention = 30 days          # Amount of time the backups should be kept
  Maximum Volume Jobs = 0                       # Amount of jobs on a volume, 0 = unlimited
  Maximum Volumes = 35                            # Limit the number of volumes in the pool
  Volume Use Duration = 23h             # Amount of time a volume can be used
  Label Format = "Incremental-"
}


Define filesets
For every specific fileset there should be a configuration file. Think for example about specifying a fileset for every operating system one or more of your containers use. It is smart to use compression to minimize the amount of space the backups take up. For Linux systems 'GZIP' is recommended, and for Windows 'LZ4HC'.

vim /etc/bareos/bareos-dir.d/fileset/LinuxAll.conf

LinuxAll.conf

FileSet {
  Name = "LinuxAll"
  Description = "Backup all regular filesystems, determined by filesystem type."
  Include {
    Options {
      Signature = MD5       # Calculate md5 checksum per file
      Compression = GZIP
      One FS = No           # Change into other filessytems
      FS Type = btrfs
      FS Type = ext2        # Filesystems of given types will be backed up
      FS Type = ext3        # others will be ignored
      FS Type = ext4
      FS Type = reiserfs
      FS Type = jfs
      FS Type = xfs
      FS Type = zfs
    }
    File = /
  }
  # Things that usually have to be excluded
  # You have to exclude /var/lib/bareos/storage on your bareos server
  Exclude {
    File = /var/lib/bareos
    File = /var/lib/bareos/storage
    File = /proc
    File = /tmp
    File = /var/tmp
    File = /.journal
    File = /.fsck
  }
}


vim /etc/bareos/bareos-dir.d/fileset/WindowsAll.conf

WindowsAll.conf

FileSet {
  Name = "WindowsAll"
  Enable VSS = yes
  Include {
    Options {
      Signature = MD5
      Compression = LZ4HC
      Drive Type = fixed
      IgnoreCase = yes
      WildFile = "[A-Z]:/pagefile.sys"
      WildDir = "[A-Z]:/RECYCLER"
      WildDir = "[A-Z]:/$RECYCLE.BIN"
      WildDir = "[A-Z]:/System Volume Information"
      Exclude = yes
    }
    File = /
  }
}


Define schedules
New schedules will be placed in the 'schedule/' directory, each schedule has its own .conf file. Our schedule will run a full backup once a week, and an incremental backup for all the other days.

vim /etc/bareos/bareos-dir.d/schedule/WeeklyCycle.conf

WeeklyCycle.conf

Schedule {
  Name = "WeeklyCycle"
  Run = Full Sat at 00:01
  Run = Incremental Sun-Fri at 01:00
}
vim /etc/bareos/bareos-dir.d/schedule/WeeklyCycleAfterBackup.conf

WeeklyCycleAfterBackup.conf

Schedule {
  Name = "WeeklyCycleAfterBackup"
  Run = Full Sat at 08:00
  Run = Incremental Sun-Fri at 06:00
}


Define jobdefs

New job definitions will be placed in the 'jobdefs/' directory, each job definition has its own .conf file.

vim /etc/bareos/bareos-dir.d/jobdefs/StandardLinuxBackup.conf

StandardLinuxBackup.conf

JobDefs {
  Name = "StandardLinuxBackup"
  Type = Backup
  Level = Incremental
  Client = bareos-fd
  FileSet = "LinuxAll"
  Schedule = "WeeklyCycle"
  Storage = File
  Messages = Standard
  Pool = Full
  Priority = 10
  Write Bootstrap = "/var/lib/bareos/%c.bsr"
  Full Backup Pool = Full
  Incremental Backup Pool = Incremental
}


vim /etc/bareos/bareos-dir.d/jobdefs/StandardWindowsBackup.conf

StandardWindowsBackup.conf

JobDefs {
  Name = "StandardWindowsBackup"
  Type = Backup
  Level = Incremental
  Client = bareos-fd
  FileSet = "WindowsAllDrives"
  Schedule = "WeeklyCycle"
  Storage = File
  Messages = Standard
  Pool = Full
  Priority = 10
  Write Bootstrap = "/var/lib/bareos/%c.bsr"
  Full Backup Pool = Full
  Incremental Backup Pool = Incremental
}


3. Install Bareos client on each container

3.1 Install Bareos client

We now need to install the Bareos client on every container that we want to back up. To do that, we log in to each of the containers and execute the following steps.

Add the Bareos release key
Start by adding the Bareos release key. Make sure you enter the correct operating system and version number.

wget -q http://download.bareos.org/bareos/release/latest/<operating_system>_<version>/Release.key -O- | apt-key add -

Add the Aptitude repository link
Add the link to the correct repository. Make sure you enter the correct operating system and version number.

echo "deb http://download.bareos.org/bareos/release/latest/<operating_system>_<version> /" >> /etc/apt/sources.list

Update container
Update your container again to make sure you will download the correct Bareos version.

apt-get update

Install Bareos-client
Install the Bareos client (also called file daemon). If prompted to continue, type 'y' or 'yes' and press enter.

apt-get install bareos-client

3.2 Configure Bareos client

Update configuration
Next we want to configure the client settings, by editing the 'bareos-fd.conf' file. Give the client a recognizable name and a relatively difficult password. The password doesn't have to be stored in a secure place, but it does need to be added in the Bareos server container in the next part, so keep it at hand. Also note that different containers should not have the same names nor passwords.

vim /etc/bareos/bareos-fd.conf

bareos-fd.conf

Director {
  Name = bareos-dir
  Password = ""
}
FileDaemon {
  Name = -fd
  Maximum Concurrent Jobs = 20
}
Messages {
  Name = Standard
  director = backuphost = all, !skipped, !restored
}


Restart Bareos client
To use the new configuration, the Bareos file daemon should be restarted.

service bareos-fd restart

Add IP address
The client container must be able to connect to the server container. Add the backup IP in the hosts file.

vim /etc/hosts

4. Add client container to backup server

The final step is to add the container to the backup container. You need to specify a client and job for all the containers you want to back up.

Add IP address
Add the container's IP address to the backup container's host file.

vim /etc/hosts

Add client configuration
Create a new client file and add the configuration. The name and password should be exactly the same as the ones you entered during the previous step.

vim /etc/bareos/bareos-dir.d/client/<name>.conf

<name>.conf

Client {
  Name = 
  Address = 
  Password = ""
  File Retention = 35 days
  Job Retention = 35 days
  AutoPrune = yes
}


Add job configuration
Create a new job file and add the configuration. The name should be exactly the same as the ones you entered during the previous step.
The jobdef value should be on of the jobdefs you created during step 2 of this tutorial.

vim /etc/bareos/bareos-dir.d/job/<name>.conf

<name>.conf

Job {
  Name = ""
  Client = 
  JobDefs = 
  Allow Duplicate Jobs = no
  Cancel Queued Duplicates = yes
  Enabled = yes
}


Load configuration
Reload the bconsole to use the new configuration.

echo "reload" | bconsole

Conclusion

Congratulations! You have succeeded setting up your very own backup system. Good luck with exploring all the other handy features Bareos has to offer.

Comments

Comments are turned off.