Filippo Zanardo's Blog

to blog or not to blog

Archive for the ‘Bacula’ Category

Bacula Tape Restore Without Database

leave a comment »

Hi guys,
sometimes happens that your machine crash and is unrecoverable, so your bacula database, and so how can you extract what do you need from a tape used with bacula?

bacula volume utility tools come in help.
First you can try to check what jobs,files contain the tape with the command bls, for example:

bls -j -V Test1 /dev/st0

This command try to read the tape inside st0 with the volume Test1 (label of your tape) and show a list of job inside the tape, like:

bls: butil.c:258 Using device: "DDS-4" for reading.
11-Jul 11:54 bls: Ready to read from volume "Test1" on device "DDS-4" (/dev/nst0).
Volume Record: File:blk=0:1 SessId=4 SessTime=1121074625 JobId=0 DataLen=165
Begin Job Session Record: File:blk=0:2 SessId=4 SessTime=1121074625 JobId=1 Level=F Type=B
Begin Job Session Record: File:blk=0:3 SessId=5 SessTime=1121074625 JobId=5 Level=F Type=B
Begin Job Session Record: File:blk=0:6 SessId=3 SessTime=1121074625 JobId=2 Level=F Type=B
Begin Job Session Record: File:blk=0:13 SessId=2 SessTime=1121074625 JobId=4 Level=F Type=B
End Job Session Record: File:blk=0:99 SessId=3 SessTime=1121074625 JobId=2 Level=F Type=B
Files=168 Bytes=1,732,978 Errors=0 Status=T
End Job Session Record: File:blk=0:101 SessId=2 SessTime=1121074625 JobId=4 Level=F Type=B

This information is very important later for restore exactly what we need, SessId and SessTime is our precious information.

Now that we collect enough information we can proceed to restore with the useful command bextract, but we need to tell what session or job to extract, how?
Simple, with bootstrap file, based on the example above we need to restore session 3 from the tape so we create a simple file for example named sess3.bsr, with something similar inside:

Volume = Test1
VolSessionId = 3
VolSessionTime = 1121074625

Finally we can extract safely our data with bextract with this command:

bextract -b sess3.bsr /dev/st0 /tmp

and voilà you have restored exactly what you need with only a tape.



Written by pipposan

June 9, 2010 at 10:14

XenServer Backup with Bacula VM director and web interface

with 2 comments

Ok guys now it’s time to put the director on a virtual machine, usually i use debian but u can use whatever distro you like, with mysql-server and apache2 installed.

It’s simply in xenserver create a Debian vm as long you install also linux pack, just make new vm from debian template 🙂

Next install some packages needed for bacula and bweb (web interface that i use with bacula).
Run this command:

apt-get install apache2 mysql-server mysql-client libmysqlclient15-dev php5-mysql php5-mysql

This packages install mysql-server apache2 and php5, make sure you have make and some compiler cause i will compile bacula, or simply install this:

apt-get install build-essential

ok now we have quiet done with prerequisites, we can go to the bacula sourceforge page and copy the direct link from download page, and execute:


also donwload bacula gui:


ok now extract bacula with the command:

tar -xzvf bacula-5.0.0.tar.gz

enter the bacula folder and configure for compiling using:

./configure –sysconfdir=/etc/bacula –with-scriptdir=/etc/bacula/scripts –with-smtp-host=localhost –with-mysql –with-tcp-wrappers –enable-smartalloc

after configuration’s finished launch this command:

make install

Compile the information needed by bacula database prompted and we are ready.

u can check the state of bacula using bconsole use the command:


ok now go back 1 folder and extract bacula gui, go into this folder/bweb, and run this command needed by bweb, or check INSTALL file:

apt-get install libgd-graph-perl libhtml-template-perl libexpect-perl \
libdbd-mysql-perl libdbd-pg-perl libdbi-perl \
libdate-calc-perl libtime-modules-perl

now install with this command:

perl Makefile.PL
make install

copy the bweb perl program to your cgi location

mkdir -m 755 /usr/lib/cgi-bin/bweb
install -m 755 -o root -g root bweb/cgi/*.pl /usr/lib/cgi-bin/bweb

get a config file, if you want to use an other place edit lib/

echo ‘$VAR1 = { template_dir => “/usr/share/bweb/tpl” };’ > /etc/bacula/bweb.conf
chown www-data /etc/bacula/bweb.conf

copy the bweb template file

mkdir -p /usr/share/bweb/tpl/en
install -m 644 -o root -g root bweb/lang/en/tpl/*.tpl /usr/share/bweb/tpl/en

copy the bweb graphics elements (bweb elements must reside in /bweb)

mkdir /var/www/bweb
install -m 644 -o root -g root bweb/html/*.{js,png,css,gif,ico,html} /var/www/bweb

done, reload your apachewith ” /etc/init.d/apache2 reload” and you can finally browse at http://yourip/bweb
and insert information needed by bweb for the configuration file.

Ok now part one is done, we only need to configure our director to talk with the other daemon, and the one we installed on xen server host machine, open the file /etc/bacula/bacula-dir.conf and add this line for the storage daemon:

# Definition of DDS tape storage device
Storage {
Name = Tape
Address = x.x.x.x # N.B. Use a fully qualified name here
SDPort = 9103
Password = “yourpassword” # password for Storage daemon
Device = ULTRIUM # must be same as Device in Storage daemon
Media Type = ULTRIUM # must be same as MediaType in Storage daemon

remember to put the same name device, and media type specified in bacula-sd.conf in the xenserver host machine.

For the file daemon:

Client {
Name = f10-64-build-fd
Address =
FDPort = 9102
Catalog = MyCatalog
Password = “pippo” # password for FileDaemon
File Retention = 30 days # 30 days
Job Retention = 6 months # six months
AutoPrune = yes # Prune expired Jobs/Files

Name must be the same that the one specified in bacula-fd.conf on xenserver host machine.

Restart bacula-director with “/etc/bacula/bacula restart” You can check the status of the connection using bconsole (/etc/bacula/bconsole) type st in the console and type 4 for the status of all components, if no error message show you configure well and u can begin to create a pool and a backup job.

Read the documentation about bacula for setting up the job, or maybe later i will blog about that.

Comments for help!

Written by pipposan

February 16, 2010 at 17:57

XenServer 5.5 Tape Backup with Bacula

with 8 comments

Usually some of my customers use tape backup and i don’t want to use the iscsi trick, so i choose Bacula as my backup solution, i use it for about 2 or 3 years and it’s simple and stable and it works for me.

Basically you have to install some of the dependencies to be able to install Bacula, without compiling, first in your file:


enable all the respository setting enabled=1.
Next install this package with this command:

yum install qt4 qt4-devel qwt qwt-devel mtx mt-st mysql-server

Now start mysql:

service mysqld start

Ok now we have installed dependecies needed by bacula, now go to Sourceforge Bacula page and search for rpms-contrib-fschwarz i use bacula-mysql-3.0.2-1.el5.i386.rpm, go to download and copy the direct link for example:

Log in on ssh to the xenserver and execute this command:


Now in the current folder u download the bacula’s rpm, install with

rpm -ivh bacula…..

ok now bacula is installed, start the daemon and enable on startup:

service bacula-sd start
service bacula-fd start
chkconfig bacula-sd on
chkconfig bacula-fd on

Xenserver block port needed by bacula so stop iptables or execute this command:

iptables -A INPUT -p tcp –dport 9102 -j ACCEPT
iptables -A OUTPUT -p tcp –sport 9102 -j ACCEPT
iptables -A INPUT -p tcp –dport 9103 -j ACCEPT
iptables -A OUTPUT -p tcp –sport 9103 -j ACCEPT

usually i use director on a vm with webserver enabled so i can check the backup via bweb, so enable and start the director is not necessary. Now you have to modify the bacula’s config file now i put some example, modify to suite your needs.

File /etc/bacula/bacula-sd.conf

Storage { # definition of myself
Name = f10-64-build-sd
SDPort = 9103 # Director’s port
WorkingDirectory = “/var/lib/bacula”
Pid Directory = “/var/run”
Maximum Concurrent Jobs = 20

# List Directors who are permitted to contact Storage daemon
Director {
Name = yourdirector-name
Password = “yourpassword”

Device {
Name = ULTRIUM #
Media Type = ULTRIUM
Archive Device = /dev/nst0 #the device where tape is attacched usually /dev/st0
AutomaticMount = yes; # when device opened, read it
AlwaysOpen = yes;
RemovableMedia = yes;
RandomAccess = no;

file /etc/bacula/bacula-fd.conf

# Restricted Director, used by tray-monitor to get the
# status of the file daemon
Director {
Name = yourdirector-name
Password = “yourpassword”

# “Global” File daemon configuration specifications
FileDaemon { # this is me
Name = f10-64-build-fd
FDport = 9102 # where we listen for the director
WorkingDirectory = /var/lib/bacula
Pid Directory = /var/run
Maximum Concurrent Jobs = 20

The basic configuration for the storage daemon and the file daemon is done, now add them to your director and create a backup job.

Later i will post some about the director’s configuration and how to install the web interface (bweb).

If you have some question, comments or ask me.

Written by pipposan

February 4, 2010 at 19:02

Bacula Script Reuse Tape

leave a comment »

I use bacula to backup my linux/win machine, i see that sometimes retention period or maximum volume job didn’t work as i expect (also recycle current volume) , so i create a script to autopurge/reuse Tape.

Here it is:


console=”/usr/bin/bconsole -c /etc/bacula/bconsole.conf”

#mount tape in the drive
PURGE=`echo “mount Tape” | $console`

#print wich tape is mounted
MOUNTED=`echo “status Storage=$storagename” | $console | grep $TAPEDRIVE0 | grep “is mounted with”`

if [ -z “$MOUNTED” ] ; then
echo “Drive is UNMOUNTED: $MOUNTED”
echo “0”
#echo “Drive is MOUNTED: $MOUNTED”
VOLUME=`echo “status Storage=$storagename” | $console | grep -A2 $TAPEDRIVE0 | grep “Volume:” | awk {‘print $2’}`
echo “Mounted Volume: $VOLUME”
VOLUMEDAUSARE=`echo “status Director” | $console | grep -A3 “Scheduled Jobs” |grep -A2 “Volume” | awk {‘print $7’} |tr “\n” ” ” |sed -e “s/ //g”`

STATOVOLUME=`echo “list volume=$VOLUME” | $console | grep -A3 “VolStatus” | grep $VOLUME| awk {‘print $6’}`

if [ “$STATOVOLUME” = “Append” ]; then
echo “APPEND”
elif [ “$STATOVOLUME” = “Error” ]; then
PURGE=`echo “purge volume=$VOLUME” | $console`
echo “ERROR”
elif [ “$STATOVOLUME” = “Used” ]; then
PURGE=`echo “purge volume=$VOLUME” | $console`
echo “USED”
elif [ “$STATOVOLUME” = “Recycle” ]; then
PURGE=`echo “purge volume=$VOLUME” | $console`
echo “Recycle”
elif [ “$STATOVOLUME” = “Purged” ]; then
echo “Purged”
elif [ “$STATOVOLUME” = “Full” ]; then
PURGE=`echo “purge volume=$VOLUME” | $console`
echo “Full”

PURGE=`echo “umount Tape” | $console`
PURGE=`echo “mount Tape” | $console`
exit 0

Basically check the tape inside the drive and purge it, if tape’s state is Full,Used,Error.

After volume is purged you lost all data, so use it carefully.

Save file with a and put in RunBeforeJob in every job’s configuration u need.


Written by pipposan

October 23, 2009 at 10:43

Posted in Bacula

Tagged with , , ,