Veritas-bu

[Veritas-bu] Using CAP/Mailslot and Netbackup 3.4

2001-02-09 11:33:26
Subject: [Veritas-bu] Using CAP/Mailslot and Netbackup 3.4
From: Raymond Jackson Jacksonr AT lucent DOT com
Date: Fri, 09 Feb 2001 08:33:26 -0800
This is a multi-part message in MIME format.
--------------398AEEAF1A8D25556ED1D720
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


  Here's one in ksh I just finished.  It works with our Sun L700
(a re-labeled StorageTek.)

  I first tried using vmchange with the "-e" option, but I got
back an error indication that it wasn't supported for my library.
With the help of this list I switched to tldtest and vmupdate
and it's working nicely now.

  I'm supporting a library in Colorado from here in California.
There are operators there, but they only move tapes; they 
don't know anything about NBU.  I first wrote a script to run
in the morning ejecting tapes based on our offsite retention
policy that emails the operators when the tapes are in the CAP.
This second script runs late in the afternoon and loads up the
replacement tapes that the operators put in the CAP during the
day.  We've only been running a week with both scripts, but so
far it's looking good.

Ray

Steve Quan wrote:
> 
> Yeah :) however, the only problem (for us anyway) is that it puts the
> tapes into *any* available (empty) slots, and we have a requirement for
> keeping some slots reserved for out of library recoveries etc. We script
> around "vmchange -i -rc1 <freeslotLocation> -m <volser>".
> 
> I'm still looking for the command to add new tapes via the CAP. I'd hoped
> that vmadd with a "-i" would do, but I was forced to use vmadd to put in
> the database, then vmchange to inject to some free slot.
> 
> /Steve
> ---
> On Thu, 8 Feb 2001, Donaldson, Grant wrote:
> 
> >       With regards to auto-injecting tapes, we are utilizing the following
> > command from within the  /usr/openv/netbackup/vault/production  directory
> > that works great:
> >
> > > ./vmupdate -rn 0 -rt tld -use_barcode_rules -empty_ie
> > >
> >       We are utilizing an STK 9740 Tape Library with a 14 slot CAP. I got
> > this command from the following e-mail to this list:
> >
> >
> >
> > >             From:   Brian Blake[SMTP:bblake AT veritas DOT com]
> > >             Sent:   July 12, 2000 12:33 AM
> > >             To:     Henschell, John
> > >             Cc:     'bpvault AT veritas DOT com'
> > >             Subject:        Re: New tapes not using the bar-code rule
> > > set
> > >
> > >             John,
> > >
> > >             If you wish to use barcode rules when injecting, you need to
> > > do one of two
> > >             things.
> > >
> > >             Check out the Vault SysAdm Guide... Procedures - Misc, I
> > > believe... it
> > >             describes how to modify bpinject so as to use the barcode
> > > rules.
> > >
> > >             Or, you could use the following command:
> > >
> > >             /usr/openv/volmgr/bin/vmupdate -rn <robot-number> -rt
> > > <robot-type> -empty_ie
> > >             -use_barcode_rules
> > >
> > >             That will empty the CAP and also use the barcode rules for
> > > any new media. This
> > >             is what we will be replacing bpinject with in future
> > > versions of bpvault.
> > >
> > >             Regards,
> > >
> > >             Brian
> > >
> > >
> > > ----------
> > > From:       RYAN ANDERSON[SMTP:RYAN_ANDERSON AT udlp DOT com]
> > > Sent:       Thursday, February 08, 2001 4:38 PM
> > > To:         David Stringer
> > > Cc:         veritas-bu AT Eng.Auburn DOT EDU
> > > Subject:    Re: [Veritas-bu] Using CAP/Mailslot and Netbackup 3.4
> > >
> > > David Stringer wrote:
> > > >
> > > > Hi People,
> > > >
> > > > We are using Netbackup 3.4 and a StorageTek 9740 tape library. There
> > > > doesn't seem to be anyway through the netbackup gui to add/remove tapes
> > > > to the library through the 12 tape CAP/mailslot on the library. Would
> > > > there be anyscripts that would accomplish this, or is anyone aware of
> > > > how to do it through the gui ?
> > > >
> > > > Thanks,
> > > > David Stringer
> > > > std AT telusplanet DOT net
> > >
> > > I believe the answer you are looking for is how to simply add in tape.
> > > From Media Manager do Actions --> New --> Single Volume --> (Choose type
> > > of media and type of library), then a new GUI will come up: Give tape
> > > the correct pool, slot, etc, then click the YES radio button for 'Inject
> > > via Mailslot?' , click 'OK' and wah-la.
> > >
> > > NOTE: Put the order of tapes you are going to add from top to bottom!
> > > The first one you add in may be tape 000001, but if HIU046 is in the top
> > > slot, it will grab it instead.
> > >
> > > You can choose the add multiple volumes, but you then have to go back
> > > and physically add in the tapes afterwards (at least in 3.2).  Scripting
> > > the ejection of tapes is pretty easy and straightforward with:
> > >
> > > vmchange -res -m <media id> -mt dlt -e
> > >
> > > Injecting them *may* be possible (and undocumented) with vmchange, but I
> > > don't know.
> > >
> > >
> > > RCA
> > > --
> > > Ryan C. Anderson        |   United Defense L.P.
> > > Unix Administrator      |   763.572.6684 (desk)
> > > ryan_anderson AT udlp DOT com  |   952.235.9936 (pager)
> > > _______________________________________________
> > > Veritas-bu maillist  -  Veritas-bu AT mailman.eng.auburn DOT edu
> > > http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu
> > >
> > _______________________________________________
> > Veritas-bu maillist  -  Veritas-bu AT mailman.eng.auburn DOT edu
> > http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu
> >
> 
> _______________________________________________
> Veritas-bu maillist  -  Veritas-bu AT mailman.eng.auburn DOT edu
> http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu
--------------398AEEAF1A8D25556ED1D720
Content-Type: text/plain; charset=us-ascii;
 name="inject_tapes"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="inject_tapes"

#!/bin/ksh
#
# inject_CAP_tapes version 1.0
#
#  Move barcoded tapes from the CAP to empty slots in the library
#  and log their movement.
#
# Changelog:
#
# 20010206 jacksonr     Initial revision (for Aurora)
#
ME="inject_tapes"
USAGE="Usage: $ME"
PATH=/usr/sbin:/usr/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/netbackup/bin:/usr/openv/volmgr/bin
DATE="$(date +%m%d%y.%H:%M:%S)"
ROBOTDEV=/dev/sg/c2t6l0
NUM_ROBOT_SLOTS=384
LOG=/var/log/$ME.$DATE.log
ERRORLOG=/var/log/${ME}_err.$DATE.log
TAPELOG=/var/log/tape_movement.log
LOCKFILE=/var/tmp/$ME.lock
PAGE=false
PAGEMSG=""
PAGEADDR="pagejacksonr AT lucent DOT com"
ERRADDR="jacksonr AT lucent DOT com"
MAILTO="jacksonr AT lucent DOT com"
DEBUG_LEVEL=9

#
#  Function definitions
#

debug() {
#
#  Print debug messages based on debug level
#
  typeset level msg

  level=$1
  msg=$2
  if [[ $level -le $DEBUG_LEVEL ]]
  then
    print -u2 "$msg"
  fi
}

bail_no_unlock() {
#
#  Error exit, deal with notifications.  Email the errorlog
#  and page if necessary.
#
  debug 1 "bail_no_unlock"
  head -100 $ERRORLOG | \
  /usr/ucb/mail -s"$ME errors" $ERRADDR

  if [[ $PAGE = "true" ]]
  then
    echo "$PAGEMSG" |\
    /usr/ucb/mail -s"$ME errors" $PAGEADDR
  fi
  exit 1
}

bail() {
#
#  Error exit, deal with notifications.  Email the errorlog
#  and page if necessary.
#
  debug 1 "bail"
  head -100 $ERRORLOG | \
  /usr/ucb/mail -s"$ME errors" $ERRADDR

  if [[ $PAGE = "true" ]]
  then
    echo "$PAGEMSG" |\
    /usr/ucb/mail -s"$ME errors" $PAGEADDR
  fi
  unlock
  exit 1
}

notify() {
#
# Save messages to the appropriate place(s) as determined
# by the notification type (note, err, page.)
#

  debug 1 "notify"
  print $2 >> $LOG
  if [[ $debug -gt 0 ]]
  then
    print -u2 "$ME: $2"
  fi

  case $1 in
    note)
      ;;
    err)
      print $2 >> $ERRORLOG
      print -u2 "$ME: $2"
      ;;
    page)
      print $2 >> $ERRORLOG
      print -u2 "$ME: $2"
      PAGE=true
      PAGEMSG="${PAGEMSG}. $2"
      ;;
  esac
}

verify_args() {
#
# Verify the argument(s) from the command line.
#
  debug 1 "verify_args"
}

lock() {
#
#  Establish advisory lock file.  Bail if it already exists or
#  we can't create it.
#
  debug 1 "lock"
  if [[ -f $LOCKFILE ]]
  then
    notify err "Lockfile $LOCKFILE exists"
    bail_no_unlock
  else
    print "$$ $DATE" > $LOCKFILE 2>> $ERRORLOG ||
    {
      notify err "Failed to create lockfile $LOCKFILE"
      bail_no_unlock
    }
  fi
}

unlock() {
#
#  Remove the advisory lockfile if it exists.  Don't bail
#  because bail calls unlock.
#
  debug 1 "unlock"

  if [[ -f $LOCKFILE ]] && ! rm $LOCKFILE 2>> $ERRORLOG
  then
    notify err "Failed to remove lockfile $LOCKFILE"
  fi
}

get_empty_slot_list() {
#
#  Create a comma-seperated list of the empty slots in the library.
#  We need the vm view, not the robot view because there may be
#  tapes in use.
#
  debug 1 "get_empty_slot_list"
  typeset occupied_slots occupied_slot slot

  empty_slots=""
  occupied_slots=$(vmquery -b -rn 0 | awk '{print $5}' | sort -n) ||
  {
    notify err "vmquery to find occupied slots failed"
    bail
  }

  slot=1
  for occupied_slot in $occupied_slots
  do
    if [[ $occupied_slot != +([0-9]) ]]
    then
      continue
    fi
    while [[ $slot -lt $occupied_slot ]]
    do
      empty_slots="${empty_slots}${slot},"
      debug 3 "Adding empty slot $slot"
      slot=$((slot + 1))
    done
    slot=$((slot + 1))
  done
  while [[ $slot -le $NUM_ROBOT_SLOTS ]]
  do
    empty_slots="${empty_slots}${slot},"
    slot=$((slot + 1))
    debug 3 "Adding empty slot $slot"
  done
  debug 3 "Empty slots = $empty_slots"
}

get_cap_status() {
#
#  Get the CAP status with tldtest and create a list of the occupied
#  slot numbers.  Also create a corresponding list of the barcodes.
#
  debug 1 "get_cap_status"
  typeset foo status slot first barcode

  occupied_cap_slots=""
  barcodes=""

  print "s i" | tldtest -r $ROBOTDEV 2>> $ERRORLOG |\
  while read first slot foo
  do
    if [[ $first != "Address" ]]
    then
      continue
    fi
    slot=${slot%,}
    slot=$((slot - 9))  # tldtest reports addresses starting at 10
    debug 3 "Parsing CAP slot $slot"
    read foo foo foo foo foo foo foo foo status
    if [[ $status = "1" ]]
    then
      debug 3 "CAP slot $slot is full"
      occupied_cap_slots="$occupied_cap_slots $slot"
      read first foo barcode
      if [[ $first != "Barcode" ]]
      then
        notify err "Tape with unreadable barcode in CAP slot $slot"
        bail
      else
        debug 2 "Found barcode $barcode in CAP slot $slot"
        barcodes="${barcodes}${barcode},"
      fi
    elif [[ $status = "0" ]]
    then
      debug 3 "CAP slot $slot is empty"
    else
      notify error "Parse error for CAP slot $slot, status = $status"
      bail
    fi
  done
  debug 3 "occupied_cap_slots = $occupied_cap_slots"
  debug 3 "barcodes = $barcodes"
}

get_next_free_slot() {
#
#  Remove the next free slot from the empty_slots list
#  and return it.
#
  debug 1 "get_next_free_slot"

  free_slot=${empty_slots%%,*}
  empty_slots=${empty_slots#*,}
  debug 3 "free_slot = $free_slot, empty_slots = $empty_slots"
  if [[ $free_slot != +([0-9]) ]]
  then
    notify err "Invalid slot number, $slot"
    bail
  fi
}

get_next_barcode() {
#
#  Remove the next barcode from the barcodes list
#  and return it.
#
  debug 1 "get_next_barcode"

  barcode=${barcodes%%,*}
  barcodes=${barcodes#*,}
  debug 3 "barcode = $barcode, barcodes = $barcodes"
}

inject_tape() {
#
#  Move the tap in CAP slot $1 to slot $2.  Record the
#  move in the TAPELOG along with the barcode, $3.
#
  debug 1 "inject_tape $1 $2 $3"

  if print "m i$1 s$2" |  tldtest -r $ROBOTDEV \
     2>> $ERRORLOG >> $LOG
  then
    print "Inject $3 from CAP $1 to slot $2 at $DATE" >> $TAPELOG
    debug 2 "Inject $3 from CAP $1 to slot $2 at $DATE"
    mailmsg="$mailmsg
Injected $3 from CAP $1 to slot $2"
  else
    notify err "Error moving $3 from CAP $1 to slot $2"
  fi
}
 
inject_tapes() {
#
#  Take the tapes (if any) from the CAP as listed in
#  occupied_cap_slots and move them
#  to the slots listed in empty_slots.
#
  debug 1 "inject_tapes"
  typeset capslot

  mailmsg=""

  if [[ -z $occupied_cap_slots ]]
  then
    notify note "No tapes found in the CAP"
    mailmsg="No tapes found in the CAP"
    return 0
  fi
  for capslot in $occupied_cap_slots
  do
    debug 2 "Processing CAP slot $capslot"
    get_next_free_slot
    if [[ -z $free_slot ]]
    then
      notify err "Ran out of free slots in inject_tapes(), capslot = $capslot"
      break
    fi
    get_next_barcode
    inject_tape $capslot $free_slot $barcode
  done
  vmupdate -rn 0 -rt tld -use_barcode_rules -rh co7010spnbkp01-nb \
           2>> $ERRORLOG >> $LOG  ||
  {
    notify err "vmupdate error after injecting media" 
    bail
  }
}

send_email() {
#
#  Tell someone what we did.
#
  debug 1 "send_email"

  /usr/ucb/mail -s"$ME results" $MAILTO << EOF

  The following tapes have been moved from the CAP to the library:

$mailmsg

  This message was sent by $ME on $(hostname).

EOF
}

cleanup_old_logfiles() {
#
#  Remove log files more than 2 weeks old.
#
  debug 1 "cleanup_old_logfiles"

  find /var/log -name "$ME*" -mtime +14 -exec rm {} \; >> $LOG 2>> $ERRORLOG
}

##########
#
#  Main
#
##########
#
#  Verify arguments.
#
case $# in
  0)
    ;;
  *)
    notify err "Wrong number of arguments.  $USAGE"
    bail_no_unlock
    ;;
esac

lock
notify note "Starting at $(date)"
get_empty_slot_list
get_cap_status
inject_tapes
send_email
cleanup_old_logfiles
unlock
notify note "Done at $(date)"
exit 0

--------------398AEEAF1A8D25556ED1D720--




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