Veritas-bu

[Veritas-bu] Inventory script for NBU without barcode reader

2001-03-21 14:40:50
Subject: [Veritas-bu] Inventory script for NBU without barcode reader
From: fx AT Veritas DOT com (fx [François-Xavier Peretmere])
Date: Wed, 21 Mar 2001 20:40:50 +0100
This is a multi-part message in MIME format.

------=_NextPart_000_0000_01C0B247.976FC2C0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

> From: Bob Bakh [mailto:bbakh AT veritas DOT com]
> Sent: Monday 12 March, 2001 22:10

> Now I know some have posted this in the past, but does any
> one have the script to inventory a robot without a barcode reader?

 pure sh code. not widely tested, use at your own risks, etc... i welcome
any feedback / correction / suggestion...

 Amicalement,
               fx

#include <std_disclaimer.h>

--
     fx AT veritas DOT com       | To have no errors
François-Xavier Peretmere | would be life without meaning.
 http://www.veritas.com/  | No struggle, no joy.

------=_NextPart_000_0000_01C0B247.976FC2C0
Content-Type: text/plain;
        name="hard_inventory.sh"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
        filename="hard_inventory.sh"

#!/bin/sh
#
# fx AT Veritas DOT com
# Francois-Xavier Peretmere / Veritas Software France / Consulting
#
#  $VRTScprght
#
# $Id: hard_inventory.sh,v 1.1 2000-12-20 04:24:38+01 fx Exp fx $
#
# $Log: hard_inventory.sh,v $
# Revision 1.1  2000-12-20 04:24:38+01  fx
# - new: add unknown labeled media found during inventory to media DB
# - new: trap signals
# - new: check processes when starting & stop bprd
# - change: only robot number is needed now
# - several small bugs corrected
#
# Revision 1.0  2000-12-08 02:52:24+01  fx
# Initial revision
#
# tested on the following platform:
# - SunOS diane 5.6 Generic_105181-03 sun4c sparc SUNW,Sun_4_50 / =
NetBackup 3.4GA
#
#
# known limitations:
#  - must be run on the slave with the robotic control because of =
tpconfig
#  - if not on the master, bprd won't be restarted at the end
#


# tape density (-t)
tdst=3Ddlt
# robot volume group
robvg=3DRobot
# stand alone volume group
outvg=3DOutside

# default beginning slot (-b)
slot1=3D0
# slot2 can be set from cmd line (-e), if not, it's the last seen slot =
in robot
slot2=3D99999999999999999

debug=3D0
verbose=3D0
donothing=3D0

# drive number to use in robot, according to tpconfig
drvnb=3D0

# nb & mm paths
OV_ROOT=3D/usr/openv
NB_ROOT=3D$OV_ROOT/netbackup
VM_ROOT=3D$OV_ROOT/volmgr
NB_BIN=3D$NB_ROOT/bin
NB_ADM=3D$NB_BIN/admincmd
VM_BIN=3D$VM_ROOT/bin

# get master from bp.conf file (-M)
if [ ! -r $NB_ROOT/bp.conf ]; then
  _exit 7 "bp.conf not found"
fi
master=3D`cat $NB_ROOT/bp.conf| egrep -v "^#"| grep SERVER| head -1| cut =
-d=3D -f2`

# robtest command for the robot
# robtest=3Dtl8test -r <robot dev> -d1 <drive1 dev>
robtest=3D"$VM_BIN/tl8test -r /dev/sg/c0t0l0 -d1 /dev/rmt/0cbn -d2 =
/dev/rmt/1cbn"

# robot host, ie. localhost
robht=3D`hostname`

PATH=3D/bin:/usr/bin:$NB_BIN:$NB_ADM:$VM_BIN
export PATH

# number of loop when waiting for the drive to become ready after =
mounting a tape
loop=3D3

myname=3D`basename $0`


_exit()
{
  if [ -n "$2" ]; then
    echo "$myname: error - $2"
  fi
 =20
  # restart bprd if we are on the master
  we=3D`$NB_ADM/bpgetconfig SERVER | head -1 | cut -d=3D -f2`
  if [ "$we" =3D `hostname` ]; then
    if [ ! -x $NB_BIN/bprd ]; then
      echo "$myname: error - can not execute $NB_BIN/bprd" > /dev/stderr
      exit 10
    fi
    $NB_BIN/bprd
  fi
 =20
  exit $1
}

_usage()
{
 echo "Usage: $myname -r robot [-s] [-M <master>] [-b slot1] [-e slot2] =
[-d drive] [-m second] [-t density] [-v]"

  exit $1
}

# handlers for sig traps
trap '_exit 4 "stopped by signal"' 1 2 3 5 10 15 23 24

# check binaries
if [ ! -d $NB_ADM -o ! -d $VM_BIN ]; then
  echo "$myname: missing NetBackup directories and/or binaries"
  echo " check NetBackup paths ($OV_ROOT, $NB_BIN, $VM_BIN, $NB_ADM)"
  exit 1
fi

robot=3D-1
# get command line switches
while getopts M:r:b:e:d:m:t:nshv param
do
  case "$param" in
     M)  master=3D$OPTARG  ;;         # master server
     r)  robot=3D$OPTARG   ;;         # robot number
     b)  slot1=3D$OPTARG   ;;         # slot 1 (beginning)
     e)  slot2=3D$OPTARG   ;;         # slot 2 (end)
     d)  drvnb=3D$OPTARG   ;;         # drive index number to use
     m)  mnttm=3D$OPTARG   ;;         # time in seconds to wait for =
drive to become ready
     t)  tdst=3D$OPTARG    ;;         # tape density
     s)  silent=3D1        ;;
     v)  verbose=3D1       ;;
     z)  debug=3D!         ;;
     n)  donothing=3D1     ;;
     h|[?]) _usage 1     ;;
  esac
done
shift `expr $OPTIND - 1`

if [ $robot -lt 0 ]; then
  echo "$myname: error - robot is not set. use -r switch to set"
  _usage 2
fi

# get drive type from drive number
drvtype=3D`$VM_BIN/tpconfig -d | awk '{ if( $1 =3D=3D '$drvnb') { print =
$4 }}'`
# check drive type and set mount time in second  (-m)
# drive type can be one of the following:
#      "4mm", for 4mm tape drives
#      "8mm", for 8mm tape drives
#      "dlt", for DLT tape drives
#      "dlt2", for DLT tape drives (2)
#      "dlt3", for DLT tape drives (3)
#      "hcart", for half-inch tape drives
#      "hcart2", for half-inch tape drives (2)
#      "hcart3", for half-inch tape drives (3)
case $drvtype in
  4mm)                  mnttm=3D40; break;;
  8mm)                  mnttm=3D50; break;;
  dlt|dlt2|dlt3)        mnttm=3D70; break;;
  hcart|hcart2|hcart3)  mnttm=3D30; break;;
  *)  echo "$myname: error - incorrect drive type $drvtype" > =
/dev/stderr
      exit 1 ;;
esac
# tape density =3D drive type
tdst=3D$drvtype

if [ $debug -gt 0 ]; then
  echo "DEBUG( drive type is $drvtype )"
fi

# check if we're root
if [ -n $LOGNAME -a $LOGNAME !=3D "root" ]; then
  echo "$myname: error - this script must be run by root" > /dev/stderr
  exit 9
fi

# check that Volume Manager processes are running
psnb=3D`$NB_BIN/bpps -a | egrep '(avrd|ltid|vmd)' | grep -v grep | wc =
-l`
if [ ! $psnb -eq 3 ]; then
  _exit 2 "missing media manager process(es) (ltid vmd avrd)"
fi


if [ $debug -gt 0 ]; then
  echo "DEBUG( drive number $drvnb is type $drvtype. mount time set to =
$mnttm )"
fi

# get robot type
# robot type -  can be one of the following:
#      "acs" for Automated Cartridge System robots
#      "tl4" for Tape Library 4mm robots
#      "tl8" for Tape Library 8mm robots
#      "tld" for Tape Library DLT robots
#      "ts8" for Tape Stacker 8mm robots
#      "tsd" for Tape Stacker DLT robots
#      "tlh" for Tape Library Half-inch robots
#      "rsm" for Removable Storage Management robots
robstr=3D`tpconfig -d | grep "robotic path"`
if [ ! $? -eq 0 ]; then
  echo "$myname: can't find a robot in media manager configuration"
  exit 8
fi
robtype=3D`echo $robstr | awk '{if ( $1 ~ =
/^[A-Z][A-Z][A-Z0-9]+\('$robot'\)/ ) { print substr($1,0,3)} }' | tr =
'[A-Z]' '[a-z]`
if [ $debug -gt 0 ]; then
  echo "DEBUG( robot type is $robtype )"
fi

# robtest counts drive from 1
rdrvnb=3D`expr $drvnb + 1`

# stop bprd
if [ ! -x $NB_ADM/bprdreq ]; then
  echo "$myname: error - can not execute $NB_ADM/bprdreq" > /dev/stderr
  exit 10
fi
if [ ! $donothing -eq 1 ]; then
  $NB_ADM/bprdreq -M $master -terminate
fi
if [ $? -gt 0 ]; then
  _exit 2 "bprdreq -M $master -terminate failed"
fi

# check that there are no running backup or restore
psnb=3D`ps -edf | egrep 'bptm | bpbrd' | grep -v grep | wc -l `
if [ $psnb -gt 0 ]; then
  _exit 2 "can't inventory robot while jobs are running"
fi

# check there's no tape in drive
# ToDo !

# put all robotic tapes in non robotic VG
# ToDo - change only VG for medias between s1 & s2

# echo "DEBUG( changing all tapes in robot $robot to stand alone VG =
$outvg )"
for t in `vmquery -M $master -b -rn $robot | awk '{if (NR>3 && $3 !=3D =
"NONE") print $1 }'`
do
  if [ $debug -gt 1 ]; then
    echo "DEBUG( vmchange -M $master -res -m $t -mt $tdst -v $outvg )"
  fi
  if [ $donothing -eq 1 ]; then
    echo "EXEC( vmchange -M $master -res -m $t -mt $tdst -v $outvg )"
  else
    $VM_BIN/vmchange -M $master -res -m $t -mt $tdst -v $outvg
  fi
done


# generate slots between slot1 & slot2 & keep slots with media only
slots=3D
for s in `echo s s | $robtest | grep "contains Cartridge =3D yes" | cut =
-d' ' -f2`
do
  # are we beetween slot1 & slot2 ?
  if [ $s -ge $slot1 -a $s -le $slot2 ]; then
    slots=3D"$slots $s"
  fi
done
# echo "DEBUG( before - slots[$slots] slot1[$slot1] slot2[$slot2] )"

# some sanity checks
# slot1 < first slot ?
if [ $slot1 -lt `echo $slots | cut -d' ' -f1` ]; then
  slot1=3D`echo $slots | cut -d' ' -f1`=20
fi
# slot2 > last slot  ?
if [ `echo $slots | awk '{ print $NF }'` -lt $slot2 ]; then
  slot2=3D`echo $slots | awk '{ print $NF }'`
fi

# sanity check for slot1 & slot2. get slots with tapes, between slot1 & =
slot2
if [ $slot2 -lt $slot1 -o $slot1 -lt 0 -o $slot2 -lt 0 ]; then
  _exit 12 "incorrect value for slot1 ($slot1) or slot2 ($slot2)"
fi
# echo "DEBUG( after - slots[$slots] slot1[$slot1] slot2[$slot2] )"

for s in $slots
do
  # echo "DEBUG( looping slot $s... )"
  if [ $verbose -gt 0 -o $debug -gt 0 ]; then
    echo "(slot $s) mounting tape in slot $s to drive $drvnb..."
  fi
  echo m s$s d$rdrvnb | $robtest >/dev/null
 =20
  # wait for drive to become ready.
  l=3D0
  while [ $l -lt $loop ];
  do
    trd=3D`$VM_BIN/vmoprcmd -d ds | awk '{ if( $1 =3D=3D '$drvnb' ) { =
mf=3DNF-2; print $mf }}' 2>/dev/null`
    if [ "$trd" =3D "Yes" ]; then
      break;
    fi
    if [ $debug -gt 0 ]; then
      echo "DEBUG( drive $drvnb is not ready. sleeping $mnttm second =
before retrying )"
    fi
    loop=3D`expr $loop + 1`
    sleep $mnttm  =20
  done
   =20
  if [ $debug -gt 0 ]; then
    echo "DEBUG( drive $drvnb is ready )"
  fi
 =20
  # get tape label - gotcha: field RVSN could be 6, check NF ?
  label=3D`$VM_BIN/vmoprcmd -d ds | awk '{ if( $1 =3D=3D '$drvnb') { =
print $5 }}'`
 =20
  # check result
  if [ "$label" =3D "-" ]; then
    echo "$myname: no tape found in drive $drvnb from slot $s"
    echo "   THIS SHOULDN'T HAPPEN - please report problem"
    _exit 11
  fi
  if [ -z $label ]; then
    echo "$myname: tape found in drive $drvnb from slot $s has no label"
    # we do nothing, just bring back tape to its slot
  else
    if [ $verbose -gt 0 ]; then
      echo " tape in drive $drvnb has label $label from slot $s"
    fi
    # check if tape is found in media db
    $VM_BIN/vmquery -b -M $master -m $label >/dev/null
    if [ $? -gt 0 ]; then
      echo "adding tape $label to media db"
      echo "DEBUG( vmadd -M $master -h $robht -m $label -mt $tdst )"
      $VM_BIN/vmadd -M $master -h $robht -m $label -mt $tdst
    fi
    echo "DEBUG( vmchange -M $master -res -m $label -mt $drvtype -rn =
$robot -rt $robtype -rc1 $s -rh $robht )"
    if [ $donothing -eq 1 ]; then
      echo "EXEC( vmchange -M $master -res -m $label -mt $drvtype -rn =
$robot -rt $robtype -v $robvg -rc1 $s -rh $robht )"
    else
      $VM_BIN/vmchange -M $master -res -m $label -mt $drvtype -rn $robot =
-rt $robtype -v $robvg -rc1 $s -rh $robht
    fi
  fi
 =20
  # umount and put tape back in slot
  # echo "EXEC( echo unload d$rdrvnb | $robtest )"
  echo "unload d$rdrvnb" | $robtest >/dev/null
  # echo "EXEC( echo m d$drvnb s$s | $robtest )"
  echo "m d$rdrvnb s$s" | $robtest >/dev/null
 =20
done

_exit 0


------=_NextPart_000_0000_01C0B247.976FC2C0--


<Prev in Thread] Current Thread [Next in Thread>