Bacula is an open source back up tool, used to backup files from different servers into a back-up server where the bacula is running. For setting up this backup tool across network, we need to install ‘Bacula Server’ package on the backup-server and then we need to install baclua-client on the servers which we want to back up.

You can get more information about Bacula here: “http://www.bacula.com/en/”

Before starting, we need to first know few terms:

1. Director-Daemon : This daemon co-ordinates all aspects of the backup process. This daemon is installed on the ‘Bacula-Server’.It is the most complex part of the system. It keeps track of all clients and files to be backed up. This daemon talks to the clients and to the storage devices.

2.File-Daemon : This daemon works in all clients from which we want to backup data. Director-Daemon connects to this daemon after authentication and backs up the files from the client.

3.Storage-Daemon : This daemon’s work is to store the backup data received from the client to the hard-disk or any other backup device of the backup-server. Usually Storage-Daemon and Director-Daemon work in the same backup server. Director works as intermediate between the File-Daemon and Storage-Daemon.

4.Console : This is a terminal to control all works.This console connects to director daemon and using this console we can define and monitor a backup process. Commandline console as well as GNOME GUI console and wx-console are availabe for bacula.

5.Catalogue Database : This database is used for storing all information related to the backup, including the file indexing.Commonly used database for bacula is Mysql.

Daemon inter-communication:

The Daemons talk to each other on specific ports as specified in their config files. They also use shared passwords. Each Client has a password that the Director knows. These passwords must match. On the Director, the password appears in the Client statement. On the Client, the password appears in the Director statement.

You don’t normally have to worry about these passwords. They are contained within the configuration files. You do not need to type them, but you should ensure that the password files are not world-readable. Bacula uses CRAM-MD5 authentication to avoid having to exchange passwords over the network.

All communication is over the network. This means each component may reside on a different machine. The ability to have multiple storage devices on multiple machines is a very nifty feature. Any single backup cannot write to multiple storage devices simultaneously, but Bacula can write different job streams to multiple storage devices simultaneously.

Similarly, the console can be installed on any machine. It can connect to the Director, which could be on the same machine or on another machine. If your needs demand it, you can install multiple Directors and have them backup to the same or different storage devices. A given Client can be backed up by multiple Directors.

Installation:

Background: Two servers are there, one backup server and one client. On the backup server Director-Daemon and Storage-daemon will be installed. On the client server File-Daemon will be installed.

On the backup server:

Install all prerequisites.

yum -y install libxml2-devel zlib-devel pango-devel atk-devel libtermcap-devel gtk2-devel libgnomeui-devel ORBit2-devel libart_lgpl-devel libbonobo-devel libbonoboui-devel GConf2-devel freetype-devel mysql-devel autoconf automake e2fsprogs-devel gcc-c++ glibc-devel glibc-headers krb5-devel libacl-devel libgomp libstdc++-devel libtermcap-devel m4 make mysql mysql-server ncurses ncurses-devel openssl-devel perl-DBI php qt4 qt4-devel readline-devel redhat-rpm-config rpm-build

* mysql header files must be installed, so may be you will need to remove ‘mysql*’ from yum’s exclude list.
* if perl-DBI is not installed, install it from source:

wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.616.tar.gz
tar -zxvf DBI-1.616.tar.gz
cd DBI-1.616
perl Makefile.PL
make
make test
make install

perl(Logwatch) module needs to installed too.

wget http://mirror.centos.org/centos/5/os/i386/CentOS/logwatch-7.3-8.el5.noarch.rpm
rpm -Uvh logwatch-7.3-8.el5.noarch.rpm

To build the wxconsole, you must install additional packages. If you do not need wxconsole, you can skip this step. In this case, you must set “build_wxconsole 0” when performing the rpmbuild command. Install the epel repo

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

Install the additional packages:

yum install qwt qwt-devel wxGTK

We will be using src.rpms to build the required rpm packages.

Download the following src rpms.

wget http://downloads.sourceforge.net/project/bacula/rpms/5.0.3/bacula-bat-5.0.3-2.src.rpm
wget http://downloads.sourceforge.net/project/bacula/rpms/5.0.3/bacula-mtx-5.0.3-1.src.rpm
wget http://downloads.sourceforge.net/project/bacula/rpms/5.0.3/bacula-docs-5.0.3-1.src.rpm
wget http://downloads.sourceforge.net/project/bacula/rpms/5.0.3/bacula-5.0.3-1.src.rpm

Setup rpm_build environment.

As a non-root user, setup your private rpm_build environment; simply copy over the default rpm-build structure.

cp -r /usr/src/redhat ~/rpm_build

Now create a ‘.rpmmacros’ file in your home directory and add these contents:

%_topdir    %(echo ${HOME}/rpm_build)
%_tmppath   %{_topdir}/tmp
%packager   <Your_Firstname> <Your_LastName> <Your_Email_Address>

Build the rpms (as a non-root user):

rpmbuild --rebuild --define "build_centos5 1" --define "build_mysql 1" --define "build_bat 1" --define "build_wxconsole 1" bacula-5.0.3-1.src.rpm
rpmbuild --rebuild --define "build_centos5 1" --define "build_mysql 1" --define "build_bat 1" --define "build_wxconsole 1" bacula-bat-5.0.3-2.src.rpm
rpmbuild --rebuild --define "build_centos5 1" --define "build_mysql 1" --define "build_bat 1" --define "build_wxconsole 1" bacula-mtx-5.0.3-1.src.rpm
rpmbuild --rebuild --define "build_centos5 1" --define "build_mysql 1" --define "build_bat 1" --define "build_wxconsole 1" bacula-docs-5.0.3-1.src.rpm

You might get errors related to libmysqlclient while building. My build wa failing as it could not find find ‘libmysqlclient_r.so’ in ‘/usr/lib64/mysql/’ directory. Linking solved the issue:

ln -s /usr/lib64/libmysqlclient_r.so /usr/lib64/mysql/libmysqlclient_r.so

Now switch to root.

Install the rpms on the server.

The rpms will be created in ~/rpm_build/RPMS/x86_64/ , depending on the architecture.

rpm -Uvh bacula-libs-5.0.3-1.x86_64.rpm
rpm -Uvh bacula-mysql-5.0.3-1.x86_64.rpm
rpm -Uvh bacula-bat-5.0.3-2.x86_64.rpm
chown bacula:bacula  /usr/lib64/libbac-5.0.3.so

Create Databases:

Change the bacula mysql configuration files as per requirements. If there in no mysql password, remove the ‘-p’ flag from these files, else keep those. Edit the following files.

/usr/lib64/bacula/grant_mysql_privileges
/usr/lib64/bacula/create_mysql_database
/usr/lib64/bacula/make_mysql_tables

Grant mysql privileges:

/usr/lib64/bacula/grant_mysql_privileges     --> will prompt for password if -p flag is there.
Privileges for bacula granted on bacula.

Create databases:

/usr/lib64/bacula/create_mysql_database
Creation of bacula database succeeded.

Create tables:

/usr/lib64/bacula/make_mysql_tables
Creation of Bacula MySQL tables succeeded.

Set bacula’s password:

Type these command at mysql prompt:

set password for bacula=password('bacula password');
set password for bacula@localhost=password('bacula password');

Verify database settings:

mysql> select user,host,password from mysql.user where user='bacula';
+--------+-----------+-------------------------------------------+
| user   | host      | password                                  |
+--------+-----------+-------------------------------------------+
| bacula | localhost | ***************************************** |
| bacula | %         | ***************************************** |
+--------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
mysql> use bacula
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+------------------+
| Tables_in_bacula |
+------------------+
| BaseFiles        |
| CDImages         |
| Client           |
| Counters         |
| Device           |
| File             |
| FileSet          |
| Filename         |
| Job              |
| JobHisto         |
| JobMedia         |
| Location         |
| LocationLog      |
| Log              |
| Media            |
| MediaType        |
| Path             |
| PathHierarchy    |
| PathVisibility   |
| Pool             |
| Status           |
| Storage          |
| UnsavedFiles     |
| Version          |
+------------------+
24 rows in set (0.00 sec)

Configure Bacula Server:

Secure the configuration files:

chmod 600 /etc/bacula/bacula-dir.conf     --> Director-Daemon's config file
chmod 600 /etc/bacula/bacula-sd.conf      --> Storage-Daemon's config file

Edit Director-Daemon’s Configuration

Backup first:

cp /etc/bacula/bacula-dir.conf /etc/bacula/bacula-dir.conf.orig

Now edit the following sections:

Director {
Name = dir_name    --> Director-Daemon's name
DIRport = 9101         --> Director-Daemon's port
QueryFile = "/usr/lib64/bacula/query.sql"
WorkingDirectory = "/var/lib/bacula"
PidDirectory = "/var/run"
Maximum Concurrent Jobs = 1
Password= "dir_pass"    --> Specify a password for the Director-Daemon
Messages = Daemon
}

JobDefs {
Name = "DefaultJob"  --> Define a job name.
Type = Backup
Level = Incremental
Client = fd_name   --> File-Daemon's name. Make sure that this matches with the name in Client-Server.
FileSet = "Full Set"
Schedule = "WeeklyCycle"
Storage = sd_name  --> Storage-daemon's name.
Messages = Standard
Pool = File
Priority = 10
Write Bootstrap = "/var/lib/bacula/%c.bsr"
}

Job {
Name = "BackupClient1"
JobDefs = "DefaultJob"  --> Should be same as JobDefs-->Name.
}
Job {
Name = "BackupCatalog"
JobDefs = "DefaultJob"  --> Should be same as JobDefs-->Name.
Level = Full
FileSet="Catalogue"
Schedule = "WeeklyCycleAfterBackup"
RunBeforeJob = "/usr/lib64/bacula/make_catalog_backup.pl MyCatalog"
# This deletes the copy of the catalog
RunAfterJob  = "/usr/lib64/bacula/delete_catalog_backup"
Write Bootstrap = "/var/lib/bacula/%n.bsr"
Priority = 11                   # run after main backup
}

Job {
Name = "RestoreFiles"
Type = Restore
Client= fd_name
FileSet="Full Set"
Storage = sd_name
Pool = Default
Messages = Standard
Where = /tmp/bacula-restores   --> Specify the directory containing the restore files.
}

FileSet {
Name = "Full Set"
Include {
Options {
signature = MD5
Compression = GZIP          --> You can add this line to enable compression
}
File = ....
File = ....                   --> List of files to be backed up. Add the directories which needs to be backed up. Each directory in different line.
}
Exclude {                       --> Exclude list.}
}

Schedule {
Name = "WeeklyCycle"
Run = Full 1st sun at 23:05                 -->Every 1st Sunday at 21:05 a full backup will take place.
Run = Differential 2nd-5th sun at 23:05     -->differential every other Sunday
Run = Incremental mon-sat at 23:05          -->and incremental rest days of the month.
}

Client {
Name = fd_name                          --> File-Daemon's name
Address = X.X.X.X                     --> Client server's address
FDPort = 9102                               --> File-Daemon's port
Catalogue = MyCatalog
Password = "fd_pass"                        --> File-Daemon's password
File Retention = 30 days            # 30 days
Job Retention = 6 months            # six months
File Retention = 30 days            # 30 days
Job Retention = 6 months            # six months
AutoPrune = yes                     # Prune expired Jobs/Files
}

Storage {
Name = sd_name                              --> Storage-Daemon's name
Address = X.X.X.X                     --> You should use a fully qualified name here, better use the IP.
SDPort = 9103                               --> Storage-Daemon's port
Password = "sd_pass"                        --> Storage-Daemon's password
Device = FileStorage
Media Type = File
}

Catalogue {
Name = MyCatalog
dbname = "bacula"; dbuser = "bacula"; dbpassword = "bacula_pass"   --> Add bacula user's mysql password.
}

Pool {
Name = Default
Pool Type = Backup
Recycle = yes                       # Bacula can automatically recycle Volumes
AutoPrune = yes                     # Prune expired volumes
Volume Retention = 365 days         # one year     --> Specify backup retention duration
}

Save the config file.

Now backup the Storage-Daemon’s config file and then edit the following sections:

Director {
Name = dir_name
Password = dir_pass
}

Director {
Name = dir_name_mon
Password = dir_name_mon_pass
Monitor = yes
}

Device {
Name = FileStorage
Media Type = File
Archive Device = /var/backup/backup   --> Device used to store the backup. Can be a disk or a file or a tape.
LabelMedia = yes;
Random Access = Yes;
AutomaticMount = yes;
RemovableMedia = no;
AlwaysOpen = no;
}

Create the backup file.

mkdir /var/backup
touch /var/backup/backup
chown -R bacula:bacula /var/backup
chmod 660 /var/backup/backup

Enable auto-start of daemons

chkconfig bacula-sd on
chkconfig bacula-dir on

Start the daemons:

/etc/rc.d/init.d/bacula-dir start
/etc/rc.d/init.d/bacula-sd start

Configure bconsole:

Edit /etc/bacula/bconsole.conf

Director {
Name = dir_name
DIRport = 9101
address = dir_IP
Password = "dir_pass"
}

Bacula-Client configuration:

Most probably you will need to install all the prerequisites again on the Client-Server.

yum -y install libxml2-devel zlib-devel pango-devel atk-devel libtermcap-devel gtk2-devel libgnomeui-devel ORBit2-devel libart_lgpl-devel libbonobo-devel libbonoboui-devel GConf2-devel freetype-devel mysql-devel autoconf automake e2fsprogs-devel gcc-c++ glibc-devel glibc-headers krb5-devel libacl-devel libgomp libstdc++-devel libtermcap-devel m4 make mysql mysql-server ncurses ncurses-devel openssl-devel perl-DBI php qt4 qt4-devel readline-devel redhat-rpm-config rpm-build

If the client and server’s architecture are same (both x86_64 or both i386) then the rpms created in the server can be used in the client. If the architecture differs, then we will need to recbuild the src.rpms again to generate required rpm.

If the architecture is same then, move the following rpms from the Bacula-Server to Bacula-Client.

bacula-client-5.0.3-1.x86_64.rpm
bacula-libs-5.0.3-1.x86_64.rpm

And install them.

If the architecture is different. Then again as non-root user create the rpm_build directory structure and then build the rpms.

cp -r /usr/src/redhat ~/rpm_build

create .rpmmacros and add the following

%_topdir    %(echo ${HOME}/rpm_build)
%_tmppath   %{_topdir}/tmp
%packager   <Your_Firstname> <Your_LastName> <Your_Email_Address>

Move the bacula-5.0.3-1.src.rpm file from the Bacula-Server to the Bacula-Client.

Build it.

rpmbuild --rebuild --define "build_centos5 1" --define "build_mysql 1" --define "build_bat 1" --define "build_wxconsole 1" bacula-5.0.3-1.src.rpm

Now as root , install the created binaries.

rpm -Uvh /home/testuser/rpm_build/RPMS/i386/bacula-libs-5.0.3-1.i386.rpm
rpm -Uvh /home/testuser/rpm_build/RPMS/i386/bacula-client-5.0.3-1.i386.rpm

Edit the File-Daemon’s configuration, make the following changes.

Director {
Name = dir_name
Password = "dir_pass"
}
Director {
Name = dir_name_mon
Password = "dir_name_mon_pass"
Monitor = yes
}
FileDaemon {
Name = fd_name
FDport = 9102
WorkingDirectory = /var/lib/bacula
Pid Directory = /var/run
Maximum Concurrent Jobs = 20
}

Enable auto start of File-Daemon

chkconfig bacula-fd on

Start the daemon

service bacula-fd start

We can configure bconsole in the clients also, with same config values as in the Bacula-Server.

Edit /etc/bacula/bconsole.conf

Director {
Name = dir_name
DIRport = 9101
address = dir_IP
Password = "dir_pass"
}

The relationship between passwords in these config files is slightly complex. Use the scheme below to make sure that the passes work:

In bacula-dir.conf on the Bacula-Server:

Director{
Name = dir_name      // This name should be used in bconsole.conf in the Bacula Server as well as any  client.   Also this name should be used in the Director section of Storage daemon's config file (bacula-sd.conf) as well as File-Daemon's config file (bacula-fd.conf)
Password = dir_pass     //This password is to be used in bconsole.conf everywhere.
...
}

Storage {
Name = sd_name
Device = device_name  //This device name is to be used in bacula-sd.conf in Device section.
MediaType = media_type  // This is also to be used in bacula-sd.conf in device section.
Address = sd_IP
Password = sd_pass // This password is to be used in bacula-sd.conf in Director section.
...
}

Client {
Name = fd_name
Password = fd_pass    //This password is to be used in bacula-fd.conf in Director Section.
...
}

Now bacula is installed and configured. You can test it by running ‘bconsole’ from either client or the server.

root@vps [~]# bconsole
Connecting to Director *.*.*.*:9101
1000 OK: sd-24030-dir Version: 5.0.3 (30 August 2010)
Enter a period to cancel a command.
*status
Status available for:
1: Director
2: Storage
3: Client
4: All
Select daemon type for status (1-4):1
sd-24030-dir Version: 5.0.3 (30 August 2010) x86_64-redhat-linux-gnu redhat
Daemon started 19-fév011 05:28, 1 Job run since started.
Heap: heap=278,528 smbytes=83,716 max_bytes=85,705 bufs=242 max_bufs=282
Scheduled Jobs:
Level          Type     Pri  Scheduled          Name               Volume
===================================================================================
Incremental    Backup    10  19-fév011 23:05   BackupClient1      label
Full           Backup    11  19-fév011 23:10   BackupCatalog      label
====

Running Jobs:
Console connected at 19-fév011 09:05
No Jobs running.
====

Terminated Jobs:
JobId  Level    Files      Bytes   Status   Finished        Name
====================================================================
1  Full        280    17.82 M  OK       18-fév011 12:56 BackupClient1
2  Incr          0         0   OK       18-fév011 23:05 BackupClient1
3  Full          0         0   Error    18-fév011 23:10 BackupCatalog
4  Full     25,317    292.8 M  OK       19-fév011 05:47 BackupClient1
====
*quit


Huh.. Now Bacula is installed and configured. Now you should be ready to begin.

About these ads