Discussions related to exporting backups to tape and backing up directly to tape.
Post Reply
squirtleuk
Novice
Posts: 7
Liked: never
Joined: Jun 09, 2015 1:46 pm
Full Name: Alan Bailey
Contact:

Used Tape Report

Post by squirtleuk »

Guys,

I have tried to write a ps script that will list and email the tapes used each day, I thought to search using the media pool date as a reference. But I am getting no results, below is what I have come up with:

Code: Select all

asnp VeeamPSSnapin

$date = (get-date).ToShortDateString()

#SMTP server name
$smtpServer = "smtp.weatherbys.local"

#Creating a Mail object
$msg = new-object Net.Mail.MailMessage

#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

#Email structure
$msg.From = "grp-man-bkp01@weatherbys.co.uk"
$msg.ReplyTo = "grp-man-bkp01@weatherbys.co.uk"
$msg.To.Add("abailey@weatherbys.local")
$msg.subject = "Wellingbourgh Veeam Backup Server - Tapes to request back from Iron Mountain"
$msg.body = Get-VBRTapemedium | where {$_.Mediaset -contains '*$date*'} | select Name | Format-Table -Property Name | out-string

#Sending email
$smtp.Send($msg)
Please let me know your thoughts, and any suggestions to achieve my goal.

Thanks in advance.

Alan B.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Used Tape Report

Post by veremin »

What if you try to query mediaset name a bit differently?

Code: Select all

Get-VBRTapeMedium | where {$_.mediaset.name -like "*$date*"} 
Also, make sure that date present in media set name is written in the same format as variable $date is.

Thanks.
squirtleuk
Novice
Posts: 7
Liked: never
Joined: Jun 09, 2015 1:46 pm
Full Name: Alan Bailey
Contact:

Re: Used Tape Report

Post by squirtleuk »

Thanks this works very well. I would like to add to this command the ability to only include tape that are still in the library (i.e. have the script run twice a day, and the script should ignore any tapes already removed after the script has ran the first time). I have come up with this command:

Code: Select all


asnp VeeamPSSnapin

$date = (get-date).ToShortDateString()

#SMTP server name
$smtpServer = "smtp.weatherbys.local"

#Creating a Mail object
$msg = new-object Net.Mail.MailMessage

#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

#Email structure
$msg.From = "grp-man-bkp01@weatherbys.co.uk"
$msg.ReplyTo = "grp-man-bkp01@weatherbys.co.uk"
$msg.To.Add("itoperationsteam@weatherbys.local")

$msg.subject = "Wellingbourgh Veeam Backup Server - Tapes to request back from Iron Mountain"

$line1 = Get-VBRTapemedium | where ({$_.Mediaset.name -like "*$date*"} -and {$_.Location -like "*Slot*"}) | select Name | Format-Table -Property Name | out-string
$line2 = "Remove these tapes from the Veeam library and send offsite with the Iron Mountain Courier."

$msg.body = "$line1`n`n$line2"

#Sending email
$smtp.Send($msg)

The "{S_.Location -line "Slot"} works on it own to list tapes in the library, but with the "{S_mediaset.name -like "*$date*"} the result is no tapes listed.

Any advice.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Used Tape Report

Post by veremin »

Can't see any issue with code itself. Just for testing purpose can you split filtering into two steps and see whether it helps:

Code: Select all

$CurrentTapes = Get-VBRTapemedium | where {$_.Mediaset.name -like "*$date*"} 
$CurrentTapesInSlot = $CurrentTapes | where {$_.location -like "Slot"}
Thanks.
Shestakov
Veteran
Posts: 7328
Liked: 781 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Used Tape Report

Post by Shestakov » 2 people like this post

Alan, we are also working on the corresponding report for Veeam One, to deliver our customers from the Powershell.
If you have any recommendations on the info to be shown in the report, please let me know. Thanks!
jacob.estrin
Novice
Posts: 9
Liked: 1 time
Joined: Dec 19, 2014 2:11 am
Full Name: Jacob Estrin
Contact:

Re: Used Tape Report

Post by jacob.estrin » 1 person likes this post

Hi,

I had the same sort of requirement where I needed to list all the tapes that needed to be ejected from our tape loader. I thought it would be worthwhile to post this and found that it is very similar to your script (which I think it is really good by the way). I did put my response in an html format which works well for our guys, however is not required.

My powershell script is:

Code: Select all

# Written by Jacob Estrin on 24/06/2015

#Add Veeam Snap In
Add-PSSnapin -Name VeeamPSSnapIn

#Mail Server Variables
$smtpServer = "192.168.0.1"
$smtpFrom = "veeam@helloworld.com.au"
$smtpTo = "helpdesk@helloworld.com.au"
$messageSubject = "Veeam Tape Ejection Report"

#Message Variables
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true

#Veeam Tape Variables
$tapecount = $(Get-VBRTapeMedium | Where-Object {$_.IsFree -eq $true -and $_.name -NotLike "CLN*" } |select Name |Sort-Object Name | measure).count
$tapes = Get-VBRTapeMedium | Where-Object {$_.LastWriteTime -ne $null -and $_.Location -like "slot"} |select Name,LastWriteTime |Sort-Object Name | ConvertTo-Html -Head $Header

#Message Body
$Header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 10px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 10px;border-style: solid;border-color: black;}
</style>
"@
$bodyline1= "<p>Please eject the following tapes from the tape loader and replace them with fresh tapes <br><br></p>"
$bodyline2= "<p><br><br>There are currently $tapecount free tapes left in the tape loader. <br><br></p>"
$bodyline3= "<p><br><br>If there are less than 10 fresh tapes available, please order additional tapes. <br><br></p>"
$message.Body = $bodyline1 + $tapes + $bodyline2 + $bodyline3

#Send the Message
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests