Tape job results

PowerShell script exchange

Tape job results

Veeam Logoby itpfp » Wed Mar 26, 2014 11:43 am 2 people like this post

Hi,

I have recently started with using Veaam7 for both VM backups (upgrade from 6.5) and also for tape offload.

I did have a usability issue with the tape offload part. We make a daily VM backup to a san, and then offload this backup to tape. The tapes are inside a library, and we have a third party company taking these tapes offsite on a daily basis.

Before we used HP dataprotector which allowed us to send the third party an email with the relevant tapes and location (slots) in the library, so that they can effectively bring the tapes offsite.

In Veaam, there doesn't seem to be a way to set notification options specific to tape jobs (allthough I did see the option using powershell), which means the only apparent way is using the global notification option. This is not workable for us, as the third party company is of course only interested in the tape job, not the other jobs we might and do run.

Furthermore, the standard job notification only displays tape name+barcode not location of the tape in the library.

Since I do use and like powershell, I went ahead and tried to find a way of doing it via powershell, and in fact I found a way. Now I don't know if this is the most direct way, but this is (for now) the most direct way I could find. I will share this here, in case others might find it usefull.

Also I would be interested if there is a more direct way. Simply put, I need the tapes used for a specific sesison for a specific job.

This is how I have handled it (I used parts of code already published on this forum, mainly the way to invoke the script).

I have added a task in the Windows task scheduler that runs on an event trigger: Log: Veeam Backup, Source Veeam Backup, event ID 0. The action is to run the following powershell script:

Code: Select all

$x = (get-eventlog "Veeam Backup" | where {$_.timegenerated -gt $(get-date).addminutes(-10)}).Message   #search evenlog for last 10 minues
   
    if ($x -eq "Session Daily Tapeoffload has been completed.")  #search for text in eventlog, the Daily Tapeoffload is the actual name of the veeam job
    {
    asnp "VeeamPSSnapIn"
    $job=get-vbrtapejob -name "Daily Tapeoffload"
    $session=$job.findlastsession()
     [xml]$xml=$session.AuxData
    $session1=$xml.TapeAuxData.TapeMediums.TapeMedium.name
    $session2 =Get-VBRTapeMedium -name $session1 |  Select-Object -Property @{N="Barcode";E={$_.Barcode}}, @{N="Location";E={$_.Locationex}} | fl | out-string;
    Send-MailMessage -To recipient@something.com -From sender@something.com -Subject "Daily TapeOffload" -bodyashtml -encoding ASCII -body "<font face=Arial>Daily TapeOffload has succeeded.<br><br> $session2</b></font>" -smtpserver smtp.somedomain.com
}



This code invokes only if it finds the text "Session Daily tapeoffload has been completed" in the event log, it then adds the veeam snapin, gets the job details, the session details, the last session and then gets the session's AuxData property, which happens to be formatted in XML. Since powershell has native support for getting values out of an xml, this is a pretty good way to get the actual name of the tapes being used in this particular job. Since we now have all the tape names, we can use these names to get the barcode (which we also could have gotten from the xml) and more importantly the actual location of these tapes. Finally the information is being sent out to the third party company, who now have all the information they need.

Now the only other way ( I could find) to get the tape names is using $session.getdetails() but this simply gets you names of tape (+ barcodes) and any other warning messages, which meant I needed to do string manipulation. In the case of using auxdata and reading the xml into powershell this isn't needed and flexible for whichever number of tapes that might be used.
itpfp
Influencer
 
Posts: 16
Liked: 3 times
Joined: Mon Mar 17, 2014 2:11 pm
Full Name: it

Re: Tape job results

Veeam Logoby v.Eremin » Thu Mar 27, 2014 2:54 pm

Great script, indeed. The only remark I have is related to LocationEx property. This property seems to return the medium previous location, not the current one. If you want to find where the media is currently located, you should use Location, instead. Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Tape job results

Veeam Logoby itpfp » Wed Apr 02, 2014 8:38 am

v.Eremin wrote:Great script, indeed. The only remark I have is related to LocationEx property. This property seems to return the medium previous location, not the current one. If you want to find where the media is currently located, you should use Location, instead. Thanks.


I know ;)

I can't remember why I did it this way, but veeam will put the tape back into the slot it picked it up from, therefore the script does work, and correctly displays the slot the tape is in at the moment it needs to be brought offline. It will still reflect the Original slot it was taken out from after it was brought offline.
itpfp
Influencer
 
Posts: 16
Liked: 3 times
Joined: Mon Mar 17, 2014 2:11 pm
Full Name: it

Re: Tape job results

Veeam Logoby v.Eremin » Wed Apr 02, 2014 8:43 am

The only confusion I can think of is the situation when the media is currently in the drive, meanwhile, the script shows that it is present in the slot. But with tape medium being returned to original slot it shouldn't bother you that much. Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Tape job results

Veeam Logoby itpfp » Wed Apr 02, 2014 12:15 pm 1 person likes this post

v.Eremin wrote:The only confusion I can think of is the situation when the media is currently in the drive, meanwhile, the script shows that it is present in the slot. But with tape medium being returned to original slot it shouldn't bother you that much. Thanks.


No it's not that exactly.

Location returns this:

Code: Select all
$tape =get-vbrtapemedium -name EDL100L5
$tape.location | fl


Code: Select all
Type      : Slot
LibraryId : ab242879-f3d4-493b-b2d3-2e26fac86aa7
Address   : 30


whereas

Code: Select all
$tape.locationex | fl


Code: Select all
Slot 31

Forgot about the reason, now I do know. You are probably referring to the orignal slot property:

$tape.orginalslot which returns 30 in this case.

locationex does rerturn the current position of the tape, and returns either the correct slot number, or the drive number or offline.

example of tape in drive:

Code: Select all
$tape = get-vbrtapemedium -name edl058l5
$tape.locationex

Drive 1 (Tape0)

and and example of an offline tape:

Code: Select all
$tape = get-vbrtapemedium -name edl062l5
$tape.locationex

Offline

So in all three examples of tapes, the powershell script returns the correct current location as verfied using veeam's GUI. Unless of course my veeam install is broken :)
itpfp
Influencer
 
Posts: 16
Liked: 3 times
Joined: Mon Mar 17, 2014 2:11 pm
Full Name: it

Re: Tape job results

Veeam Logoby v.Eremin » Wed Apr 02, 2014 1:25 pm

Yes, you're right, indeed. I must have been slightly confused by the parameter name. In fact, LocationEx is nothing but a convenient wrapper for Location - the one that represents information regarding tape location in human understandable format. Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests