Filippo Zanardo's Blog

to blog or not to blog

Posts Tagged ‘tape

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:

#!/bin/sh

console=”/usr/bin/bconsole -c /etc/bacula/bconsole.conf”
command=”$1″
TAPEDRIVE0=/dev/st0
storagename=”Tape”

#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”
else
#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”`
#echo “VOLUME DA USARE :$VOLUMEDAUSARE”

STATOVOLUME=`echo “list volume=$VOLUME” | $console | grep -A3 “VolStatus” | grep $VOLUME| awk {‘print $6’}`
#echo “:$STATOVOLUME”
#echo “USED: $USED RECYCLE:$RECYCLE APPEND:$APPEND ERROR:$ERROR”

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

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 name.sh and put in RunBeforeJob in every job’s configuration u need.
RunBeforeJob=/path/to/name.sh

Enjoy

Advertisements

Written by pipposan

October 23, 2009 at 10:43

Posted in Bacula

Tagged with , , ,