Bareos on Centos 7 – powerful backup tool

Today I met with backup problem. I nee to find and set up solution for backup and possible restore of files in windows or linux. I heard about bacula, but after som searching and reading, I choose a new fork of bacula – bareos.

Installing Bareos itself

So I install it on new, clean vm centos 7. At first define a hostname:

hostnamectl set-hostname bareos-ba

Next, add a bareos repository:

cd /etc/yum.repos.d/
yum install bareos -y

Next, we can use MariaDB-server for backend od bareos:

yum install mariadb-server -y
systemctl start mariadb.service
systemctl enable mariadb.servic

Now, we create and mount a file-storage, when bareos will save the data:

fdisk /dev/vda
mkfs.xfs /dev/vda1
mkdir /var/backups
mount /dev/vda1 /var/backups/
chown bareos:bareos -R /var/backups/
df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/vda1                    32G   33M   32G   1% /var/backups

Edit /etc/fstab to make this mount permanent.
Now, we can create a new bareos database with pre-defined scripts:

Creating mysql database
Creating of bareos database succeeded.
[root@bareos-ba]# /usr/lib/bareos/scripts/make_bareos_tables
Making mysql tables
Creation of Bareos MySQL tables succeeded.
[root@bareos-ba]# /usr/lib/bareos/scripts/grant_bareos_privileges
Granting mysql tables
Privileges for user bareos granted ON database bareos.

Now, we can check our default configuration with:

su bareos -s /bin/sh -c "/usr/sbin/bareos-dir -t"
su bareos -s /bin/sh -c "/usr/sbin/bareos-sd -t"
bareos-fd -t

If you are using firewall, for bareos server open this ports:

firewall-cmd --zone=public --add-port=9101/tcp --permanent
firewall-cmd --zone=public --add-port=9102/tcp --permanent
firewall-cmd --zone=public --add-port=9103/tcp --permanent
#http only if you want web-gui for baores
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
firewall-cmd --list-all
#public (active)
# - services: http ssh
# - ports: 5666/tcp 9103/tcp 9101/tcp 161/udp 9102/tcp

This step is only for bareos WebUI. If you don’t need this, skip it.

yum install bareos-webui -y
setsebool -P httpd_can_network_connect on
systemctl start httpd.service
systemctl enable httpd.service

Edit conf file and set FQDN for this host:

vim /etc/bareos-webui/directors.ini
- diraddress = ""

Copy example admin console config:

cp /etc/bareos/bareos-dir.d/console/admin.conf.example /etc/bareos/bareos-dir.d/console/admin.conf
chown bareos:bareos /etc/bareos/bareos-dir.d/console/admin.conf

Setting up a storage for bareos director

At first, we must add our previously created and mounted disk to our bareos-storage daemon and then add it to bareos-director daemon for using it and working.

cp /etc/bareos/bareos-sd.d/device/FileStorage.conf /etc/bareos/bareos-sd.d/device/backups.conf
chown bareos:bareos /etc/bareos/bareos-sd.d/device/backups.conf
vim /etc/bareos/bareos-sd.d/device/backups.conf
 - change archive device and the name:
Archive Device = /var/backups
Name = Backups
cp /etc/bareos/bareos-dir.d/storage/File.conf /etc/bareos/bareos-dir.d/storage/backups.conf
chown bareos:bareos /etc/bareos/bareos-dir.d/storage/backups.conf
vim /etc/bareos/bareos-dir.d/storage/backups.conf
 - change Name and Device. Name must be the same as above:
Name = Backups
Device = Backups

Now we edit job definitions:

vim /etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf
 - change Storage variable to ours above mentioned:
Storage = Backups

Now again check bareos config files for error:

su bareos -s /bin/sh -c "/usr/sbin/bareos-dir -t"
su bareos -s /bin/sh -c "/usr/sbin/bareos-sd -t"
bareos-fd -t

and restart (start) bareos:

service bareos-dir restart
service bareos-sd restart
service bareos-fd restart
systemctl enable bareos-dir.service
systemctl enable bareos-sd.service
systemctl enable bareos-fd.service

Using bconsole and WEBui

Our webui is on address bellow. Default login nad pass is: admin/admin

Our bareos console is avalaible via command bconsole:

[root@bareos-ba ~]# bconsole
Connecting to Director localhost:9101
1000 OK: bareos-dir Version: 16.2.4 (01 July 2016)
Enter a period to cancel a command.

bconsole is marked at the beginning with asterisk *
Some useful commands:

list storages
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
| StorageId | Name    | AutoChanger |
|         1 | File    |           0 |
|         2 | Backups |           0 |
list pools
show jobdefs
show filesets
status dir
status client=bareos-fd

Now we can start our first job – Selftest. So, run bconsole and continue:

- select job resource 3: backup-bareos-fs
- yes => Job queued. JobId=1
*wait jobid=1

In messages we can see, that bareos backup almost 44MB of files. In our fileset of this Selftest, we can see bareos backup folder /usb/sbin:

cat /etc/bareos/bareos-dir.d/fileset/SelfTest.conf

Now, we can restore this files. By default job of restore, it will be restored to /tmp/bareos-restores:

 cat /etc/bareos/bareos-dir.d/job/RestoreFiles.conf

Run bconsole:

*restore all client=bareos-fd
- select 5 for most recent backup
- done
- yes
Job queued. JobId=2
*wait jobid=2

We can see our restored files in /tmp/bareos-restores/.

Total Page Visits: 6390 - Today Page Visits: 1