User Tools

Site Tools


hints_tips:force_status_of_volumes

Background

We run Bacula like an old fashioned Backup-system with a single tapedrive. Daily a single volume is creating containing the backup of that day as generated by multiple jobs. Regardless if there is space left of the tape volume we want to force Bacula to use a new volume/tape the next day/session. Therefor the volume should have the status “Used” at the end of the backup session. Usually this is the case, but sometimes for reasons not know to me the status remains “Appendable” causing Bacula the next time the pool is used to request the wrong volume in relation to the tape inserted into the drive. (Yes I know, Bacula's design is based upon the idea of letting Bacula to decide what volume to use and not the sysadmin, but I do not want that as in my humble opinion it is not very practical with single slot tapedrives versus tapespace versus required backupspace: no one wants to sleep next to the tapedrive….)

Approach

Obviously the best approach is to find out what is causing this and fix the issue. This is something which I favor, but I have no clue what is causing this at the moment. To be pragmatic I therefor created a workaround.

Implemented workaround

I will opt in this case for the option of running the job as the final admin-job in the backup-session.

WARNING This script is more of an example on how one can use bash scripting in conjunction with Bacula. In most cases you will not need this script. If you do not know exactly what you are doing please stay away from this script as it interferes heavily with Bacula's philosophy and it's expected working/behavior in most situations WARNING

Use the script at your own risk. It's not the best of bash-programming, but it seems to do it's job:

#!/bin/bash

bconsole="/usr/bin/bconsole -s -c /etc/bacula/bconsole.conf"

tmpfile="/tmp/llistmedia.txt"

function bconsole_list_media() {
  $bconsole <<EOD_LISTMEDIA
list media
quit
EOD_LISTMEDIA
}

function bconsole_llist_media() {
  $bconsole <<EOD_LLISTMEDIA
llist media
quit
EOD_LLISTMEDIA
}

function bconsole_update_volume_used() {
  vol=`echo $1`
  mypool=`echo $2`
  $bconsole <<EOD_UPVOLSTATUSED
update volume=$vol pool=$mypool volstatus="Used"
quit
EOD_UPVOLSTATUSED
}

bconsole_llist_media > $tmpfile

n=0
bconsole_list_media | while read mediatable;
do
   volume=`echo $mediatable | grep ^\|`
   wrds=`echo $volume | wc -w`
   if [ $wrds -ne "0" ]; then
     volID=`echo $volume | cut --delimiter="|" -f2` 
     volname=`echo $volume | cut --delimiter="|" -f3`
     volstat=`echo $volume | cut --delimiter="|" -f4`
     if [ $volID != "MediaId" ]; then
        volID=${volID//[[:space:]]}
        volname=${volname//[[:space:]]}
        volstat=${volstat//[[:space:]]}
        
        pool=`cat $tmpfile | grep "MediaId: "$volID -B 2 | grep "Pool" | cut --delimiter=":" -f2`
        pool=${pool//[[:space:]]}
        
        #echo "Volume $n with ID $volID and name $volname in pool $pool has status $volstat."
        if [ $volstat != "Used" ]; then
          #echo "  update volume=$volname pool=$pool volstatus=Used"
          bconsole_update_volume_used $volname $pool
        fi
        (( n += 1 ))
     fi
   fi
done
hints_tips/force_status_of_volumes.txt · Last modified: 2010/04/16 14:05 by olaf