Veeam – Tape Drive Inventory

Veeam – Tape Drive Inventory

Hey All, back again with another interesting problem and solution that we hope will help others out there in the tech world. If you have never heard of Veeam backup & recovery, I encourage you to do a quick google search. It is a fantastic product that allows you to backup and restore systems and files quite easily.

With the increase of crypto-virus and ransomware attacks that have been happening in recent times, the client wanted to add an additional offline backup to their existing solution. This job would take place weekly to ensure at least one backup could not be reached by a virus in a worst case scenario.

Currently there is no official automated way to perform a tape inventory, once a tape has been placed in the attached drive. To help with this problem, we have come up with a simple power shell script that can run as a scheduled task.

The script will run an inventory job on the tape drive, and will create a small report which details the success of failure of the inventory job.

Get-vbrtapelibrary -Name "HPE Ultrium 8-SCSI" | Start-VBRTapeInventory -Wait > "C:\temp\details.txt"

Secondly, it will generate a small report that shows the actual status of the drive itself. (what media is loaded).

Get-VBRTapeDrive | Out-String > "C:\temp\details2.txt"

And lastly, it will wrap these little reports up and fire an email off so that you can see if the inventory was successful, and what the tape label is thats within the drive.

Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort

We are pulling a few status strings from the reports and using that for the subject line of the email. This way, at a glance you will know if the job was successful and also if the tape drive is loaded with media:

#--- Check the result of the inventory job
select-string -Path "C:\temp\details.txt" -pattern 'Result' | select-object -ExpandProperty Line

#--- Check the state of the tape drive (empty or loaded)
select-string -Path "C:\temp\details2.txt" -pattern 'State' | select-object -ExpandProperty Line
#--- Set the subject line of the email
$Subject = "VEEAM Tape Inventory - '$details' |  Drive '$details2'"

I will place the script we came up with below as a rough guideline for those who are looking to automate the veeam tape drive inventory job.

Remember, a manual inventory job can still be run after a tape has been changed out; this is just a ‘safety net’ so that the backup job will not fail, in the case a manual inventory was not run prior to the backup schedule.

<# ===============================================================
Date: 10/1/2021
Written by: Wheatland Tech Services
Details: This is a power shell script designed to inventory an attached tape drive and send an emailed report for review
================================================================= #>

# -----------  Define Variables  -------------
$details
$content
$status
$details2

#-----------   Inventory Tape Drive  --------------
& Get-vbrtapelibrary -Name "HPE Ultrium 8-SCSI" | Start-VBRTapeInventory -Wait > "C:\temp\details.txt"
Start-Sleep -s 4

#-----------  Assign Variables  -----------------
$details = select-string -Path "C:\temp\details.txt" -pattern 'Result' | select-object -ExpandProperty Line
$content = get-content -path "C:\temp\details.txt" | Out-String
$status = Get-VBRTapeDrive | Out-String > "C:temp\details2.txt"
$details2 = select-string -Path "C:\temp\details2.txt" -pattern 'State' | select-object -ExpandProperty Line

# ----------- Send Email notification to support --------------
$From = "<sending email>"
$To = "<receiving email>"
$Subject = "VEEAM Tape Inventory - '$details' |  Drive '$details2'"
$Body = "Tape inventory has completed, please check the log to ensure `n $content `n $status"
$SMTPServer = "<email server address>"
$SMTPPort = "<SMTP Port>"

Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort

Once the script has been saved to the system, a scheduled task can be created to run the script as required.

Here is an example of the email that is generated. In this case, the job completed with a state of success, but there was no tape in the library, resulting in a state of ‘Empty’. Now we know we need to get a tape in there before the jobs are set to run!

That’s it! We hope this helps someone out there who is struggling with this issue. If so please let us know!