In my quest to fully automate management of all my tape libraries in our various data centres I decided to write powershell scripts to do numerous tasks, one of them was to erase tapes and re-assign the tape back to a specific Media Set.

My initial look at the BEMCMD API document should have yielded an “Assign Media to Media Set” command but after an hour of scouring the documentation and search the web I finally realized there was a “Move Media” command that fulfils the task.

Lets say the tape in slot 1 of your library (appropriatly labelled as “LIBRARY”) has just been erased using the command BEMCMD -o111 -s1 -d”LIBRARY” you then have to do the following:

  1. Obtain the MEDIA ID of the tape in slot 1 using BEMCMD -o86 -s1 -d”LIBRARY”
  2. Then apply the move using the command BEMCMD -o130 -i{ID-FROM-ABOVE-COMMAND} -mn:”NAME-OF-MEDIA-SET”

The Media Set name will change immediately if there is no error.

Dont forget if you script this using powershell then the following commands will get you the media library name (Which can change if you have hardware issues).

c:
cd "\Program Files\Symantec\Backup Exec"
#
# Get Library Name and get rid of blank lines in output
#
$a = .\bemcmd -o84 -j|where {$_ -ne ""}
#
# Separate Device name
#
$o = $a[0].split(":")
$device = $o[1].Trim()

Get the media details fo the tape in slot 1, you could use a variable like $slotid if using in a loop etc…

#
# Get slot 1 details
#
$c=".\bemcmd -o86 -s1 -d"+'"'+$device+'"'
#
# execute the cmd and save the output
#
$output=cmd /c $c

#
# Split the output eg. FieldName : Value
#
$ctline = $ouput[2].split(":")
if($f -eq "NO")
{
    $mediadetails = $output[5].split(":")
    $mid = $mediadetails[1].trim();
    if( $mid -eq "{00000000-0000-0000-0000-0000-00000000000}" )
    {
        "Slot 1 has no no media"
    }
    else
    {
        "Assigning tape...."
        $c = ".\bemcmd -o130 -i"+$mid+ -mn:"media-set-to-assign-tape-to"
        $output=cmd /c $c
    }
}

Simple!

Advertisements