Disaster Recovery using bareos

Bareos is the fork of the Bakula project, and thay are almost the same. I have no idea why I chose one instead of the other, but I have bareos installed and it make a good backup. I even made a successful recovery and think that have a good backup solution.

But what is my plan if I lose the backup server itself? Or will I need to transfer it to another platform, version, etc.? This note will cover DRP from having only backup media.

Installing software

This time I chose CentOS 7 for installation. Bareos does not require much from hardware. I have only one storage channel (backup to disk), so only one job runs at a time. Thus, a VM with 2CPU and 4GRAM will be more than enough.

This instruction assumes a minimal installation of CentOS7.

Install postgresql

# yum install postgresql-server.x86_64
# postgresql-setup initdb
# systemctl start postgresql.service
# systemctl status postgresql.service
# systemctl enable postgresql.service

Configure passwordless local connections:

# su - postgres
$ vi data/pg_hba.conf
$ egrep -v "^$|^#"  data/pg_hba.conf
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             localhost               trust
$ psql
psql (9.2.23)
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

Restart services to pick up changes:

# service postgresql restart

Install bareos

The "latest" current release is 16.2, which is a good and stable version, but does not work with VmWare 6.5. Therefore, I will install a release candidate v17.2.

Set its repository definitions and install the bareos directly from the Internet.

# yum install -y wget rsync
# wget -O /etc/yum.repos.d/bareos.repo http://download.bareos.org/bareos/release/latest/CentOS_7/bareos.repo
# yum install bareos bareos-database-postgresql bareos-webui
# systemctl enable httpd.service

When webui is running on a selinux-enabled system, you should apply the following policy to allow the httpd open socket to the local system:

# setsebool -P httpd_can_network_connect on
# rpm -e firewalld
# systemctl restart httpd.service

Initialize DB

Run postgresql scripts to initialize bareos database and schema:

# su - postgres
$ /usr/lib/bareos/scripts/create_bareos_database
$ /usr/lib/bareos/scripts/make_bareos_tables
$ /usr/lib/bareos/scripts/grant_bareos_privileges

In fact, the installation of the new bareos system is complete, and you can start to configure and use it. Probably, you will want to install VmWare plugin too.

Installing vmware plugin

New vmware plugin is based on vmware sdk that also should be installed. The good news that all required RPMs are exists in EPEL repository:

# yum install -y epel-release
# yum install bareos-vmware-plugin

The following command will print SHA fingerprint (could be used in connection configuration):

echo -n | openssl s_client -connect 192.168.80.21:443 2>/dev/null | openssl x509 -noout -fingerprint -sha1 | sed -e 's/://g'

Restore Catalog

To restore all other systems, we need to restore information about all performed backups first.

Getting bootstrap info

If you have a so-called bootstrap information, which usually drops into a spam box, you can skip this step.

Find the latest "Full-" volume. If your previous backup system was configured well, this volume will include the "BackupCatalog" job. It should be run after all night backups to save the summary information. I have it working at 10:00 the next day.

The "bls" tool scans the volume for jobs. Inspect the scan results and find the last run of the "BackupCatalog" job then get "SessId" and "SessTime" values.

# bls -j -V Full-0157 FileStorage
bls: butil.c:273-0 Using device: "FileStorage" for reading.
21-Nov 20:54 bls JobId 0: Ready to read from volume "Full-0157" on device "FileStorage" (/var/lib/bareos/storage).
Volume Record: File:blk=0:200 SessId=15 SessTime=1510947894 JobId=1 DataLen=165
End Job Session Record: File:blk=8:1530288849 SessId=15 SessTime=1510947894 JobId=2896
   Date=18-Nov-2017 07:59:18 Level=F Type=B Files=2 Bytes=60,324,050,132 Errors=0 Status=T
Begin Job Session Record: File:blk=8:1530353361 SessId=29 SessTime=1510947894 JobId=2910
   Job=BackupCatalog.2017-11-19_10.00.00_21 Date=19-Nov-2017 10:00:03 Level=F Type=B
End Job Session Record: File:blk=8:1542212665 SessId=29 SessTime=1510947894 JobId=2910
   Date=19-Nov-2017 10:00:03 Level=F Type=B Files=78 Bytes=11,912,582 Errors=0 Status=T
Begin Job Session Record: File:blk=8:1542277177 SessId=43 SessTime=1510947894 JobId=2924
   Job=BackupCatalog.2017-11-20_10.00.00_35 Date=20-Nov-2017 10:00:03 Level=F Type=B
End Job Session Record: File:blk=8:1554256618 SessId=43 SessTime=1510947894 JobId=2924
   Date=20-Nov-2017 10:00:03 Level=F Type=B Files=78 Bytes=12,032,623 Errors=0 Status=T
Begin Job Session Record: File:blk=8:1554321130 SessId=57 SessTime=1510947894 JobId=2938
   Job=BackupCatalog.2017-11-21_10.00.00_49 Date=21-Nov-2017 10:00:03 Level=F Type=B
End Job Session Record: File:blk=8:1566390609 SessId=57 SessTime=1510947894 JobId=2938
   Date=21-Nov-2017 10:00:03 Level=F Type=B Files=78 Bytes=12,122,589 Errors=0 Status=T
21-Nov 20:57 bls JobId 0: End of Volume at file 8 on device "FileStorage" (/var/lib/bareos/storage), Volume "Full-0157"
21-Nov 20:57 bls JobId 0: End of all volumes.

Then create your own BSR file "/tmp/my.bsr" using the values found:

Volume="Full-0157"
VolSessionId=57
VolSessionTime=1510947894

Restore info using bootstrap file

You have a BSR file created manually as described above, or what you've found in your spam box. The latter include a few more data:

# 21-Nov-2017 10:00:03 - BackupCatalog.2017-11-21_10.00.00_49 - Full
Volume="Full-0157"
MediaType="File"
VolSessionId=57
VolSessionTime=1510947894
VolAddr=35913994987-35926128977
FileIndex=1-78

Now restore files using "bextract" tool:

# bextract -b /tmp/my.bsr FileStorage /tmp

You have successfully restored the configuration directory "/etc/bareos" and the DB dump "/var/lib/bareos/bareos.sql". Copy the configuration files to their place.

# rsync -av /tmp/etc/bareos/ /etc/bareos/

Load database data. If you exactly followed me as in this article, you still have no any bareos processes running. If you have them running, then stop them before loading the contents of the database.

# service bareos-dir stop
# chmod -R o+rx /tmp/var/
# su - postgres
$ psql bareos bareos -f /tmp/var/lib/bareos/bareos.sql

Now, it is the time to start bareos services:

# systemctl enable bareos-fd.service
# systemctl enable bareos-sd.service
# systemctl enable bareos-dir.service
# systemctl start bareos-fd.service
# systemctl start bareos-sd.service
# systemctl start bareos-dir.service

Check restored data:

# echo "list jobs" | bconsole
# echo "list media" | bconsole

Updated on Tue Nov 21 23:20:38 IST 2017 More documentations here