Filippo Zanardo's Blog

to blog or not to blog

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

0 downtime snapshot based XENServer 5.5 backup script

with 19 comments

Check this new better version of the script

Ok guys based on this script i made mine with some more features.
Basically i split the configuration file out of the script and added some new features:

automount: if set to true script try to mount the backupdir specified in mountcommand at start and umount at end, else no action taken and u have to mount dir manually

subfolder: Set to true to create a subfolder in the store for each backup based on vm name

versioning: Set to true to let the script manage to delete the backup older than a certain day or number or hours

and i rewrite the message so they are now more “human” readeable.

The usage it’s the same except u have to pass the path to the config file to the script like:

perl /path/to/ /path/to/config.txt

U can download the file here

Unzip in a folder and read and modify the configuration file (basic explanation is written in), i put also in the config file message’s string so it’s easy to translate in your preferred language, i added also the elapsed minute time of each backup.

Next remember to modify the SendEmail script changing the “server” line at line 65, to send notification mail.

## Network
“server” =>’’,
“port” => 25, ## Default port
“alarm” => ”, ## Default timeout for connects and reads, this gets set from $opt{‘timeout’}

and at line 54 hostname:

“hostname” => ‘’, ## Used in printmsg() for all output, and in SMTP EHLO.

Next call in a cron job or manually the script and enjoy.

Remember to put in the skip variable the uuid of the control domain on host and other vm that don’t need to backed up!

Don’t remove the “\” near @ cause it’s needed for the sendEmail script, so the string should looks like “mymail\”

Comments for bug, wish feature etc etc…

Based on todo list on the main page i will add other feature when i have time!


Check this new better version of the script

Written by pipposan

December 9, 2009 at 17:38

Nagios XenServer

with 4 comments

I use nagios to check my server, and most of the time i use xenserver 5.5 on them, so i have to trick up the machine to work with nagios and i use an example to check hardware raid on it.

Let’s start first of all execute this command, this download yum priorities and the rpm needed by rpmforge:

wget -c

then install it

rpm –import
rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm

Then install some lib needed for nagios, and finally install nagios-plugins nrpe and xinetd.

yum -y install compat-libstdc++-296 compat-libstdc++-33
yum install nagios-plugins nagios-nrpe xinetd

i use a central nagios server and i check raid via nrpe, if u don’t know what is nrpe read this:
nrpe documentation


NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine metrics (disk usage, CPU load, etc.). NRPE can also communicate with Windows agent addons like NSClient++, so you can check metrics on remote Windows machines as well.

next modify the file /etc/xinet.d/nrpe updating this line:

disable = no
only_from = #this is the ip of the nagios machine

allow nagios to run some script modify /etc/sudoers like:


this is not so secure on remote machine, modify to suit your needs, i use on lan machine.

next let xinetd start on startup

chkconfig xinetd on
service xinetd start

For example i sue hp prolaint server, so i explain how i check hardware raid on them, first install this rpm:

hp rpm

next i use this plugin to check raid:

raid check

modify nrpe config file (/etc/nagios/nrpe.cfg) adding this line:

command[check_raid]=/usr/lib/nagios/libexec/check_cciss -v

Finally we done set up the machine, and we can check his hardware raid on nagios central server, with the nrpe-plugin, my command on central nagios is:

$user1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

and i use it in a service with



p.s. if someone is interested in nagios or in a particular argument related, post your wish and later i can blog on this.

Written by pipposan

December 1, 2009 at 19:11

Posted in Nagios, XenServer

Tagged with , ,

Squid Windows Update

leave a comment »

Usually windows update didn’t work in squid here’s a way that works for me.

Create a text file named windowsupdate.txt in your squid configuration directory.
Place these entries in it:

Then edit your squid.conf file. Create a new acl:

acl WindowsUpdate dstdomain -i “/usr/local/etc/squid/windowsupdate.txt”

Disable the cache for this site:

no_cache deny WindowsUpdate

Allow everyone to these sites with this line:

http_access allow WindowsUpdate

After doing these things do a “squid -k reconfigure” to recreate the cache.

Windows Update and Microsoft Update should be working just fine now through your cache, keeping your Windows boxes up to date.

Written by pipposan

October 27, 2009 at 11:48

Posted in Squid

Tagged with ,

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 , , ,

XenServer Virtual Machine Backup

with 2 comments

Hi, my first post ever on this blog 🙂

I wanna share a simple script to backup virtual machine in Xen Server (5.5 actually).

This is a simple script check this one is better!

The script basically check if older backup exyst and delete the oldest one, than stop the virtual machine, export that to a file and then send an email about some basic stats for the backup.

Here’s the script:


#Today’s date
TODAY=`date +%d%m%Y`
#start of script
time_start=`date +%s`

#Control the folder backup for how may file contain
FILECOUNT=`ls /backup| wc -l`;
#check if files are more than 2
if [ $FILECOUNT -ge 2 ]
#remove oldest file as long as we need 2
cd /backup && ls -tr | head -n 1 | xargs rm -f;
echo “Removing oldest file”
echo “There are less than 2 file”

#shutdown the virtual machine
xe vm-shutdown vm=”nameofyourvm”
#export vm into a file ex: yourname22112009
xe vm-export vm=”nameofyourvm” filename=/backup/nameofyourvm$TODAY.xva
#start the vm
xe vm-start vm=”nagios”

#end of script
#calculate time execution of the script
time_end=`date +%s`
time_elapsed=$((time_end – time_start))
echo “script executed in $time_elapsed seconds”
echo $(( time_elapsed / 60 ))m $(( time_elapsed % 60 ))s

# email subject
# Email To ?
# Email text/message
echo “Backup OK” > $EMAILMESSAGE
echo “Execution time =” $(( time_elapsed / 60 ))m $(( time_elapsed %

Just copy the code, change name and path and add it to a scheduled cron job, et voilà!

Hope it helps!

Written by pipposan

October 12, 2009 at 14:23

Posted in XenServer

Tagged with , ,