Bacula-users

Re: [Bacula-users] doesn't register loaded tape

2008-06-02 13:19:39
Subject: Re: [Bacula-users] doesn't register loaded tape
From: Mark Nienberg <gmane AT tippingmar DOT com>
To: bacula-users AT lists.sourceforge DOT net
Date: Mon, 02 Jun 2008 10:19:12 -0700
Maria McKinley wrote:

  Playing around a bit more I had this bizarre occurance:

Device status:
Autochanger "Exabyte" with devices:
    "Drive-1" (/dev/st0)
Device "Drive-1" (/dev/st0) open but no Bacula volume is currently mounted.
     Device is being initialized.
     Slot 9 is loaded in drive 0.
     Total Bytes Read=64,512 Blocks Read=1 Bytes/block=64,512
     Positioned at File=0 Block=0
====

In Use Volume status:
G0000008 on device "Drive-1" (/dev/st0)
     Reader=0 writers=0 reserved=1 released=0
====

====
*
*
31-May 19:41 billie-sd JobId 591: Please mount Volume "G0000008" or label a new one for:
     Job:          NightlySave.2008-05-31_01.05.32
     Storage:      "Drive-1" (/dev/st0)
     Pool:         Weekly
     Media type:   VXA-2


I've seen that happen too. Try using the attached script vxa-changer in place of the standard mtx-changer. Rather than overwriting your current mtx-changer, you can just edit the "Changer Command" line in "bacula-sd.conf" to point to vxa-changer.

While you are editing "bacula-sd.conf", add the line

Maximum Changer Wait = 1800;

to the Device{} section for your drive.

This script is modified to give the longer wait sometimes needed by vxa drives and it has better debug logging. Look at /var/lib/bacula/mtx.log for the output.

Mark

#!/bin/sh
#
# Bacula interface to mtx autoloader
# modified for Exabyte VXA packetloader by Mark Nienberg
#
#  If you set in your Device resource
#
#  Changer Command = "path-to-this-script/mtx-changer %c %o %S %a %d"
#    you will have the following input to this script:
#
#  So Bacula will always call with all the following arguments, even though
#    in come cases, not all are used.
#
#  mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index"
#                  $1              $2       $3        $4               $5
#
#  for example:
#
#  mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
# 
#  will request to load the first cartidge into drive 0, where
#   the SCSI control channel is /dev/sg0, and the read/write device
#   is /dev/nst0.
#
#  The commands are:
#      Command            Function
#      unload             unload a given slot
#      load               load a given slot
#      loaded             which slot is loaded?
#      list               list Volume names (requires barcode reader)
#      slots              how many slots total?
#
#  Slots are numbered from 1 ...
#  Drives are numbered from 0 ...
#
#
#  If you need to an offline, refer to the drive as $4
#    e.g.   mt -f $4 offline
#
#  Many changers need an offline after the unload. Also many
#   changers need a sleep 60 after the mtx load.
#
#  N.B. If you change the script, take care to return either 
#   the mtx exit code or a 0. If the script exits with a non-zero
#   exit code, Bacula will assume the request failed.
#

MTX=mtx

# mt status output
# SunOS     No Additional Sense
# FreeBSD   Current Driver State: at rest.
# Linux     ONLINE

OS=`uname`
case ${OS} in
  SunOS)
    ready="No Additional Sense"
    ;;
  FreeBSD)
    ready="Current Driver State: at rest."
    ;;
  *)
    ready="ONLINE"
  ;;
esac

#
# log whats done
#
# to turn on logging, uncomment the following line
touch /var/lib/bacula/mtx.log
#
dbgfile="/var/lib/bacula/mtx.log"
debug() {
    if test -f $dbgfile; then
        echo "`date +\"%Y%m%d-%H:%M:%S\"` $*" >> $dbgfile
    fi
}


#
# Create a temporary file
#
make_temp_file() {
  TMPFILE=`mktemp /var/lib/bacula/mtx.XXXXXXXXXX`
  if test x${TMPFILE} = x; then
     TMPFILE="/var/lib/bacula/mtx.$$"
     if test -f ${TMPFILE}; then
        echo "Temp file security problem on: ${TMPFILE}"
        exit 1
     fi
  fi
}

#
# The purpose of this function to wait a maximum 
#   time for the drive. It will return as
#   soon as the drive is ready, or after a max wait. 
# Note, this is very system dependent, so if you are
#   not running on Linux, you will probably need to
#   re-write it, or at least change the grep target.
#
# mark changed this to every 10 sec with total wait of 28 min,
# note "Maximum Changer Wait = 1800" must also be set in bacula-sd.conf
wait_for_drive() {
  debug "  entered wait_for_drive"
  i=1 
  while [ $i -le 168 ]; do  # Wait max 28 minutes
    sleep 10
    # the status is on the last line of the mt output
    mt_rtn=`mt -f $1 status | tail -n1`
    debug "$i - mt status for $1 returned $mt_rtn"
    if echo $mt_rtn | grep "${ready}" >/dev/null 2>&1; then
      break
    fi
    i=`expr $i + 1`
  done
}

# check parameter count on commandline
#
check_parm_count() {
    pCount=$1
    pCountNeed=$2
    if test $pCount -lt $pCountNeed; then
        echo "usage: mtx-changer ctl-device command [slot archive-device 
drive-index]"
        echo "  Insufficient number of arguments given."
        if test $pCount -lt 2; then
            echo "  Mimimum usage is first two arguments ..."
        else
            echo "  Command expected $pCountNeed arguments"
        fi
        exit 1
    fi
}

# Check for special cases where only 2 arguments are needed, 
#  all others are a minimum of 5
#
case $2 in
    list)
        check_parm_count $# 2
        ;;
    slots)
        check_parm_count $# 2
        ;;
    *)
        check_parm_count $# 5
        ;;
esac


# Setup arguments
ctl=$1
cmd="$2"
slot=$3
device=$4
drive=$5

debug "Parms: $ctl $cmd $slot $device $drive"

case $cmd in 
   unload)
      debug "Doing mtx -f $ctl unload $slot $drive"
      ${MTX} -f $ctl unload $slot $drive

      # mark added a short sleep here
      debug "sleeping 5 sec after unload"
      sleep 5
      ;;

   load)
      # record the start time of the mtx load command
      before="$(date +%s)"

      debug "Doing mtx -f $ctl load $slot $drive"
      ${MTX} -f $ctl load $slot $drive

      rtn=$?
      debug "mtx load returned $rtn"

      if [ $rtn -eq 0 ]; then
        wait_for_drive $device      
        after="$(date +%s)"
        elapsed_seconds="$(expr $after - $before)"
        debug "Elapsed time from load to drive ready: $elapsed_seconds"
        debug "waiting 60 sec before returning"
        sleep 60
      fi

      exit $rtn
      ;;

   list) 
      debug "Doing mtx -f $ctl status -- to list volumes"
      make_temp_file
      ${MTX} -f $ctl status >${TMPFILE}
      rtn=$?
      cat ${TMPFILE} | grep " Storage Element [0-9]*:.*Full" | awk "{print \$3 
\$4}" | sed "s/Full *\(:VolumeTag=\)*//"
      cat ${TMPFILE} | grep "^Data Transfer Element [0-9]*:Full (Storage 
Element [0-9]" | awk '{printf "%s:%s\n",$7,$10}'
      rm -f ${TMPFILE} >/dev/null 2>&1
      exit $rtn
      ;;

   loaded)
      debug "Doing mtx -f $ctl status -- to find what is loaded"
      make_temp_file
      ${MTX} -f $ctl status >${TMPFILE}
      rtn=$?
      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk "{print 
\$7}"
      cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 
0}"
      rm -f ${TMPFILE} >/dev/null 2>&1
      exit $rtn
      ;;

   slots)
      debug "Doing mtx -f $ctl status -- to get count of slots"
      ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$5}"
      ;;
esac
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users
<Prev in Thread] Current Thread [Next in Thread>
  • Re: [Bacula-users] doesn't register loaded tape, Mark Nienberg <=