Bacula – How To Install Bacula Backups + Postgresql on CentOS 5

1. Install Remmi Repository

rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

2. Install Postgresql

yum --enablerepo=remi install postgresql84

3. Edit the start-up script

vi /etc/rc.d/init.d/postgresql

4.Change the PGDATA and PGLOG variable to wherever you want

# Set defaults for configuration variables
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base/template1" ]
 echo "Using old-style directory structure"
# Override defaults from /etc/sysconfig/pgsql if file is present 
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}
export PGDATA
export PGPORT

5. Create the directory…and set the permissions

mkdir -p /path/to/pgdata
chown postgres:postgres /path/to/pgdata

6. Initialize the database…

su - postgres -c "initdb -D /path/to/pgdata"

7. Now you can start postgres

root@host# service postgresql start

8. Now you can check this with the ps and you’ll notice (in red) that the pgdata dir is where the database is

ps aux | grep post
postgres 11140 0.0 0.1 122556 3372 ? S 10:41 0:00 /usr/bin/postmaster -p 5432 -D /path/to/pgdata
postgres 11142 0.0 0.0 111736 672 ? S 10:41 0:00 postgres: logger process 
postgres 11144 0.0 0.0 122692 1168 ? S 10:41 0:00 postgres: writer process 
postgres 11145 0.0 0.0 112736 672 ? S 10:41 0:00 postgres: stats buffer process 
postgres 11146 0.0 0.0 111864 848 ? S 10:41 0:00 postgres: stats collector process 
root 11186 0.0 0.0 61120 724 pts/1 S+ 10:58 0:00 grep post

9. Edit the pg_hba.conf file like this * -> your ip address

local all all trust
# IPv4 local connections:
host all all trust
host all all *.*.*.* trust
# IPv6 local connections:
#host all all ::1/128 ident

At this point, you should have built and installed PostgreSQL, or already have a running PostgreSQL, and you should have configured, built and installed Bacula. If not, please complete these items before proceeding.

Please note that the ./configure used to build Bacul will need to include –with-postgresql=PostgreSQL-directory, where PostgreSQL-directory is the directory name that you specified on the ./configure command for configuring PostgreSQL (if you didn’t specify a directory or PostgreSQL is installed in a default location, you do not need to specify the directory). This is needed so that Bacula can find the necessary include headers and library files for interfacing to PostgreSQL.

Bacula will install scripts for manipulating the database (create, delete, make tables etc) into the main installation directory. These files will be of the form *_bacula_* (e.g. create_bacula_database). These files are also available in the <bacula-src>/src/cats directory after running ./configure. If you inspect create_bacula_database, you will see that it calls create_postgresql_database. The *_bacula_* files are provided for convenience. It doesn’t matter what database you have chosen; create_bacula_database will always create your database.

Now you will create the Bacula PostgreSQL database and the tables that Bacula uses. These instructions assume that you already have PostgreSQL running. You will need to perform these steps as a user that is able to create new databases. This can be the PostgreSQL user (on most systems, this is the pgsql user).

# cd <install-directory>

This directory contains the Bacula catalog interface routines.


10. This script creates the PostgreSQL bacula database.

If it fails, it is probably because the database is owned by a user other than yourself. On many systems, the database owner is pgsql and on others such as RedHat and Fedora it is postgres. You can find out which it is by examining your /etc/passwd file. To create a new user under either your name or with say the name bacula, you can do the following:

 (enter root password)
 su pgsql (or postgres)
 createuser kern (or perhaps bacula)
 Shall the new user be allowed to create databases? (y/n) y
 Shall the new user be allowed to create more new users? (y/n) (choose
 what you want)

.At this point, you should be able to execute the ./create_bacula_database command.


This script creates the PostgreSQL tables used by Bacula.


This script creates the database user bacula with restricted access rights. You may want to modify it to suit your situation. Please note that this database is not password protected.

Each of the three scripts (create_bacula_database, make_bacula_tables, and grant_bacula_privileges) allows the addition of a command line argument. This can be useful for specifying the user name. For example, you might need to add -h hostname to the command line to specify a remote database server.

11. Compile Bacula

CFLAGS="-g -Wall" ./configure \
 --sbindir=/usr/sbin \
 --sysconfdir=/etc/bacula \
 --with-scriptdir=/etc/bacula \
 --enable-smartalloc \
 --enable-bat \
 --with-postgresql \
 --with-working-dir=/var/bacula \
 --with-pid-dir=/var/run \

12 . Make Bacula

make install

13 . Make Auto Start Daemons

make install-autostart

And you just finish installing Bacula

You may also like...

Leave a Reply