Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.
Backup and Recovery Community Blog

Finding Your Tapes with OpsCenter (or Scripting!)

Created: 30 Mar 2012
AlanTLR's picture
+1 1 Vote
Login to vote

If you're like me, you're in a company that's understaffed and overworked.

If you're like me, you don't like to do more than 3 steps to do something that you have to do repeatedly.

If you're like me, you have a large group of tapes that have been ejected from your library and fallen down the wayside.

If you're like me, you prefer to have a browser way of doing things, but still want to do it from the command-line.

If you're like me, you've tried a "lost media" report and found tapes that were in ScratchPool, but not on that list.

Well, your'e probably not as bad as I am when it comes to changing tapes; I really hate doing them, but it's a necessary evil if you're using tapes.  What I end up with is several containers of tapes that were vaulted and not put into proper containers.  I can easily go through them and look up each tape to see if it's expired, or I can generate a nice list of all tapes that I can print out or email to check them against.  The first and easiest way to find Scratchpool tapes is via OpsCenter.

In OpsCenter, I can easily go to the "Monitor" -> "Media" tabs and create a filter, by clicking on the large green + next to the Filter area.  I've named mine "Offsite" and added the following filters: Slot < 0, and Volume Pool "Equals (case-insensitive)" ScratchPool.  This gives me a large list of scratchpool offsite tapes that I can unfortunately not export nor email, but I can use this list to help verify when I create a list using a script.

Now, with a script, the command I want to use is vmquery.  Vmquery is located in /usr/openv/volmgr/bin/vmquery (see usage below).  The output of searching through the scratchpool gives several lines per media.  Several lines parsed is easiest (for me) using perl.

 $ /usr/openv/volmgr/bin/vmquery
Usage: vmquery [-h <EMM_server> | <volume_database_host>,...,
           -h <EMM_server> | <volume_database_host>]
           [-b | -w | -W | -l]
           {
           -a |
           -m <media_id> |
           -v <volume_group> |
           -rn <robot_number> |
           -rt <robot_type> |
           -mt <media_type> |
           -p <pool_number> |
           -pn <pool_name> |
           -vltcid <vault_container_id> |
           -res <robot_type> <robot_number> <robot_control_host>
                <robot_coord1> <robot_coord2> |
           -assignbyid <media_id> <media_type> <pool_number> <status>
                       <assigntime> |
           -deassignbyid <media_id> <pool_number> <status>
           }
CAUTION: The act of unassigning volumes may lead to inconsistencies
         between the application media database and volume database,
         leading to the possibility for data loss. You must expire the
         media from an application interface.

$ /usr/openv/volmgr/bin/vmquery -pn ScratchPool | head -30
================================================================================
media ID:              002004
media type:            1/2" cartridge tape (6)
barcode:               002004
media description:     ---
volume pool:           ScratchPool (4)
robot type:            NONE - Not Robotic (0)
volume group:          ---
vault name:            ---
vault sent date:       ---
vault return date:     ---
vault slot:            ---
vault session id:      ---
vault container id:    -
created:               Thu Aug 02 12:27:01 2007
assigned:              ---
last mounted:          Wed Nov 09 16:19:02 2011
first mount:           Wed Oct 31 04:10:20 2007
expiration date:       ---
number of mounts:      27
max mounts allowed:    ---
================================================================================
media ID:              002007
media type:            1/2" cartridge tape (6)
barcode:               002007
media description:     ---
volume pool:           ScratchPool (4)
robot type:            NONE - Not Robotic (0)
volume group:          ---
vault name:            --- 

So, what do I want to search for?  I want to search for the dividers ("======..."), and look at each row after that.  I want to save the media ID, the vault slot--if any--and the robot slot.  Note that the robot slot only exists if the tape exists within the robot.  If the tape is in the ScratchPool, and it's not in the robotic library (no slot information), and it's not in a vault slot (vault slot ---), or not in a vault container (vault container id: -), then we know that it's some free-standing tape out there somewhere.  Easily done!

 $ cat list_scratchpool_tapes_offsite.pl
#!/bin/perl
use strict;

my $CMD_VMQUERY='/usr/openv/volmgr/bin/vmquery';
my $SCRATCH='ScratchPool';
my $STREAM;
my $LINE;
my @SPLITLINE;
my $STARTED=1;
my $MEDIAID = "---";
my $VOLPOOL = "---";
my $VSLOT   = "---";
my $RSLOT   = "---";

$STREAM=open(STRM,"$CMD_VMQUERY -pn $SCRATCH |") or die "Can't open pipe to $CMD_VMQUERY: $!";
while(<STRM>)
{
  $LINE=$_;
  chomp($LINE);
  if ( $LINE eq "================================================================================" )
  {
    if ( $VSLOT == "---" && $RSLOT == "" && $MEDIAID != "" ) { printf "$MEDIAID\n"; }
    $MEDIAID = "";
    $VOLPOOL = "---";
    $VSLOT   = "---";
    $RSLOT   = "";
  }

  if ( $LINE =~ /^media ID:/ ) { @SPLITLINE = split(/\s+/,$LINE); $MEDIAID=$SPLITLINE[2]; }
  if ( $LINE =~ /^volume pool:/ ) { @SPLITLINE = split(/\s+/,$LINE); $VOLPOOL=$SPLITLINE[2]; }
  if ( $LINE =~ /^vault slot:/ ) { @SPLITLINE = split(/\s+/,$LINE); $VSLOT=$SPLITLINE[2]; }
  if ( $LINE =~ /^robot slot:/ ) { @SPLITLINE = split(/\s+/,$LINE); $RSLOT=$SPLITLINE[2]; }
}

Note that if you use containers instead of vault slots, you can change the "^vault slot:" filter to "^vault container id:", but you'll need to change the $SPLITLINE index to [3] instead of [2].  If you use both, you can just add both.  You'd also need to change the initializations and comparisons to "-" instead of "---", as the empty "vault container id:" field is only one dash.

Again, there are several ways of doing this and many of finding out how many ScratchPool tapes you have, but again, I like to have the command-line as a backup.  The other advantage of this is that I can give sudo access to just one person to run the report and hand it off to someone else to sort through the tapes.  Have fun!