PowerShell script exchange
Post Reply
tcse10
Novice
Posts: 8
Liked: never
Joined: Feb 04, 2015 10:32 am
Contact:

List Tapes useb by job

Post by tcse10 »

Hi there,
we are using B&R v8 and like to generate and print a report about the tapes used by a specific backup to tape job.
I think the best way to do this is to run a powershell script aft the tape job. I found a script for V7 at thins post http://forums.veeam.com/powershell-f26/ ... 21184.html and I am trying to port it to v8, but I am enabled to find a way getting the used tapes out of the VBRSession.
This is what I goat till now:

Code: Select all

 asnp "VeeamPSSnapIn"
    $job=get-vbrtapejob -name "Test"
    $session= Get-VBRSession -Job $job -Last
    $session
     [xml]$xml=$session.AuxData
    $session1=$xml.TapeAuxData.TapeMediums.TapeMedium.name
    $session1
    $session2 =Get-VBRTapeMedium -name $session1 |  Select-Object -Property @{N="Barcode";E={$_.Barcode}}, @{N="Location";E={$_.Locationex}}, @{N="Free capacitye";E={$_.Free}} | fl | out-string;
    $session2
can anyone help?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List Tapes useb by job

Post by veremin »

I'm wondering whether you want to create a report about tapes used during the latest Job session or report about VM restore points (files) and tapes they reside on? Thanks.
tcse10
Novice
Posts: 8
Liked: never
Joined: Feb 04, 2015 10:32 am
Contact:

Re: List Tapes useb by job

Post by tcse10 »

I like to report about tapes used during the latest Job session. But maybe, I will include the backed up VM restore point in future.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List Tapes useb by job

Post by veremin »

Now in order to achieve your goal you have to use more or less unsupported workaround. The rest of the referenced script can stay intact:

Code: Select all

$BTJ = Get-VBRTapeJob -Name "Name of your backup Job"
$Session = [veeam.backup.core.cbackupsession]::GetByJob($BTJ.id) | Sort CreationTime -Descending | select -First 1
Thanks.
tcse10
Novice
Posts: 8
Liked: never
Joined: Feb 04, 2015 10:32 am
Contact:

Re: List Tapes useb by job

Post by tcse10 »

Ok, This is working, but I got the next problem:
The Locationex property of the VBRTapeMedium seems to be removed, and Location only contains Slot (without number) or Drive.
Is there also a workaround? Or is it a configuration issue?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List Tapes useb by job

Post by veremin »

In fact, location has a lot of useful information, including slot and drive address (see below).

Image

Thanks.
tcse10
Novice
Posts: 8
Liked: never
Joined: Feb 04, 2015 10:32 am
Contact:

Re: List Tapes useb by job

Post by tcse10 »

I got my script working now, but I wood like to add a list of the latest restore points in the tape job wit its corresponding vms. I can’t find a way to do this in a simple manner. Do you have any suggestions to do this?

In case someone is interested in it, this is my script:

Code: Select all

param(
    [string]$jobName
    )

asnp "VeeamPSSnapIn"
    $Page = "
______            _                 ______                      _   
| ___ \          | |                | ___ \                    | |  
| |_/ / __ _  ___| | ___   _ _ __   | |_/ /___ _ __   ___  _ __| |_ 
| ___ \/ _`  |/ __| |/ / | | | '_ \  |    // _ \ '_ \ / _ \| '__| __|
| |_/ / (_| | (__|   <| |_| | |_) | | |\ \  __/ |_) | (_) | |  | |_ 
\____/ \__,_|\___|_|\_\\__,_| .__/  \_| \_\___| .__/ \___/|_|   \__|
                            | |               | |                   
                            |_|               |_|                   
"
$lineHZ="___________________________________________________________________________________"
    
    $job=get-vbrtapejob -name $jobName
    $Session = [veeam.backup.core.cbackupsession]::GetByJob($job.id) | Sort CreationTime -Descending | select -First 1
    
    $PageJob  = "
    Job title:  " + $jobName + "
    Start time: " + $session.CreationTime + "
    End time:   " + $session.EndTime + "
    Result:     " + $session.Result + "
    State:      " + $session.State + "
"
    $Page += $lineHZ + $PageJob + $lineHZ + "

Tapes used by this Job:
"

     [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={($_.Location.SlotAddress + $_.Location.Type)}}, @{N="Free capacity (GB)";E={($_.Free/1024/1024/1024)}} | Format-Table -AutoSize | out-string;
    $Page += $session2 

  
    $Page += "

                                                                      End of report"

    $Page | Out-Printer
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List Tapes useb by job

Post by veremin »

I've created previously a script that shows tape content. Is that something you're looking for? Thanks.
tcse10
Novice
Posts: 8
Liked: never
Joined: Feb 04, 2015 10:32 am
Contact:

Re: List Tapes useb by job

Post by tcse10 »

Inspired by your code I have created this. Maybe it's not a perfect solution but as far as i can tell it works.

Code: Select all

$TapeBackups = Get-VBRTapeBackup | where {$_.getJob().Name -eq $jobName}
$vms = $TapeBackups.GetLastOibs() | select name, CreationTime | Format-Table -AutoSize | Out-String
Maybes someone can find a way to relate to the session and without using the obsolete Get-VBRTapeBackup
antspants77
Influencer
Posts: 20
Liked: 5 times
Joined: Mar 16, 2011 3:15 pm
Full Name: Tony Spencer
Contact:

Re: List Tapes useb by job

Post by antspants77 »

Hi,
Sorry that this is an old thread and that GET-VBRTAPEBACKUP cmdlet is even more "obsolete and no loner supported"
However, your scripts seem to be exactly what I was looking for.

Environment.
Veeam 8.0.0.2084
4 x Hyper-v 2008 R2 Sp1
About 20Tbs of data across about 30 VMs
8 disk backup jobs every night.
2 tape dupe jobs to put these on tape each week.
About 20 tapes used each week across these 2 tape jobs.
Backing up to a HP MSL8096 Loader/Tape drive (2 drives, 96 slots)

Requirement.
To provide the customer with a list of tapes and their corresponding tapes to remove each week.

Current process
Open Tape job reports
Copy "Used tapes" into excel.
Then using replace to remove duplicate tape entries (Tape names are listed twice for each tape)
Using the comma as a delimiter to put the tapes into separate columns.
Paste special and use transpose to place all tapes into a single column.
Repeat for 2nd tape job.

Been looking at Vaults, Veeam One etc do not seem to provide what I need. (Take these tapes out and send them offsite)
Veeam One breaks it down by disk jobs within the Tape job. Even if it did, hard to sell them a product, just so they can be told what tapes they can take out like it did Commvault apparently.

As you will probably work out, I know very little about powershell.

Ran the above scripts by.
1. Open Veeam Backup & Replication Console.
2. From Veeam Menu, selected "Powershell"
3. Tried just pasting scripts and running, with a few carriage returns.
4. Tried creating a PS1 file and running that as well. E.g. .\tapeout.ps1

Tried with original script, but changing "test" to name of my tape job "VeeamBackups1 Tape Dupe"

Code: Select all

asnp "VeeamPSSnapIn"
    $job=get-vbrtapejob -name "VeeamBackups1 Tape Dupe"
    $session= Get-VBRSession -Job $job -Last
    $session
     [xml]$xml=$session.AuxData
    $session1=$xml.TapeAuxData.TapeMediums.TapeMedium.name
    $session1
    $session2 =Get-VBRTapeMedium -name $session1 |  Select-Object -Property @{N="Barcode";E={$_.Barcode}}, @{N="Location";E={$_.Locationex}}, @{N="Free capacitye";E={$_.Free}} | fl | out-string;
    $session2
I get the error

Code: Select all

Get-VBRTapeMedium : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument
that is not null or empty, and then try the command again.
At C:\temp\tapeout.ps1:8 char:40
+     $session2 =Get-VBRTapeMedium -name $session1 |  Select-Object -Property @{N= ...
+                                        ~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-VBRTapeMedium], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.GetVBRTapeMedium

When I run

Code: Select all

$TapeBackups = Get-VBRTapeBackup | where {$_.getJob().Name -eq $jobName}
$vms = $TapeBackups.GetLastOibs() | select name, CreationTime | Format-Table -AutoSize | Out-String

I get the error

Code: Select all

You cannot call a method on a null-valued expression.
At line:1 char:1
+ $vms = $TapeBackups.GetLastOibs() | select name, CreationTime | Format-Table -Au ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
As this is not supported any more and no other replacement can be found, I'm not sure if I should place a support call.
But let me know and I will

I also looked at v.Eremin script, but was unsure how to combine the original script and his addition.

So, if anyone could please supply me with a method, so that a single script can be run (from the desktop if possible) that just give me a list of tapes that the customer needs to take out.
nickl99
Enthusiast
Posts: 29
Liked: 4 times
Joined: Aug 03, 2016 5:09 am
Full Name: NICK LAING
Contact:

[MERGED] : List tapes, media set and retention

Post by nickl99 »

Hi Guys, I have 3 tape jobs that run on sunday and finish on Monday. I'd like a simple report listing tapes used and their retention time so our tape recall company can manage tape records themselves. Is powershell the best way to do this?

I am a newb at powershell, but willing to learn and tinker until correct. I could have a script that runs after each job, and writes to a csv? Or one script that runs after the last tape job and goes through each tape job, lists the tapes used and their expiry\retention. I only really need tape barcode and retention , but any other useful info would be cool.

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

Re: List Tapes useb by job

Post by veremin »

Take a look at the script provided above and see whether it asks your requirements. If you're after simpler, say retrieving tapes written within last 24 hours, then, check this thread. Thanks.
berndbaum
Novice
Posts: 3
Liked: never
Joined: Apr 12, 2018 7:49 am
Full Name: Bernd
Contact:

[MERGED] List of TAPES used by Backup2Tape Job

Post by berndbaum »

Hi ,

does anybody know if it is possible to get a list of Tapes used by a Backup to Tape Job ?
And also for a certain File ?

That can help me to prefetch Tapes in my VTL for a faster restore....

Thank you......
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: List Tapes useb by job

Post by PTide »

Hi Bernd,

Kindly check Vladimir's post

Thanks
serkantek
Influencer
Posts: 10
Liked: 1 time
Joined: Oct 08, 2017 11:23 pm
Full Name: Serkan Tek
Contact:

Re: List Tapes useb by job

Post by serkantek »

Hey Guys,

Sorry to revive this from the dead. I want to include the "EXPIRES IN" column into my existing report but I dont know what the right code is.
I just guessed it and getting a blank value for now. I want to display not only the date but the status of the tape as expired if the date has past.

Code: Select all

 Get-VBRTapeMedium | Where-Object {$_.IsFree -eq $False} | Sort-Object {$_.ExpirationDate} |  Select-Object -Property @{N="Barcode";E={$_.Barcode}}, @{N="Location";E={$_.Location}} ,@{N="Slot Number";E={($_.Location.SlotAddress + $_.Location.Type)}}, @{N="Expiration Date";E={$_.ExpirationDate}}, @{N="Expires In";E={$_.ExpiresIn}} | Format-Table -Autosize | Out-file -Encoding ascii $localpath
This is what output i get currently. The formatting is really bad in the forum but its spaced out ok on my report.

Code: Select all

Barcode  Location Slot Number Expiration Date        Expires In
-------  -------- ----------- ---------------        ----------
VW0001L7 Vault          Vault 27/10/2018 3:38:17 PM            
VW0004L7 Vault          Vault 28/10/2018 4:46:55 AM            
VW0007L7 Vault          Vault 28/10/2018 4:46:55 AM            
VW0010L7 Vault          Vault 28/10/2018 4:46:55 AM            
VW0003L7 Vault          Vault 28/10/2018 1:31:42 PM            
VW0008L7 Vault          Vault 28/10/2018 1:31:42 PM            
VW0012L7 Vault          Vault 28/10/2018 1:31:42 PM            
VW0005L7 Vault          Vault 28/10/2018 1:31:42 PM            
VW0009L7 Vault          Vault 28/10/2018 4:39:01 PM            
VW0002L7 Vault          Vault 28/10/2018 4:39:01 PM            
VW0006L7 Vault          Vault 28/10/2018 4:39:01 PM            
VW0011L7 Vault          Vault 28/10/2018 4:39:01 PM            
VW0018L7 Vault          Vault 11/11/2018 7:37:03 PM            
VW0013L7 Vault          Vault 11/11/2018 7:37:03 PM            
VW0021L7 Vault          Vault 11/11/2018 11:02:48 PM           
VW0016L7 Vault          Vault 11/11/2018 11:03:03 PM           
VW0015L7 Vault          Vault 11/11/2018 11:03:03 PM           
VW0023L7 Vault          Vault 11/11/2018 11:03:03 PM           
VW0020L7 Vault          Vault 11/11/2018 11:03:03 PM           
VW0019L7 Vault          Vault 12/11/2018 1:07:32 AM            
VW0014L7 Vault          Vault 12/11/2018 1:07:32 AM            
VW0017L7 Vault          Vault 12/11/2018 1:07:32 AM            
VW0022L7 Vault          Vault 12/11/2018 1:07:32 AM            
VW0027L7 Vault          Vault 18/11/2018 9:22:04 PM            
VW0029L7 Vault          Vault 18/11/2018 9:22:04 PM            
VW0026L7 Vault          Vault 18/11/2018 9:22:04 PM            
VW0030L7 Vault          Vault 19/11/2018 1:03:09 AM            
VW0028L7 Vault          Vault 19/11/2018 1:03:09 AM            
VW0031L7 Vault          Vault 19/11/2018 1:03:09 AM            
VW0025L7 Vault          Vault 19/11/2018 1:03:09 AM            
VW0032L7 Vault          Vault 19/11/2018 2:29:20 AM            
VW0033L7 Vault          Vault 19/11/2018 8:22:58 PM            
VW0024L7 Vault          Vault 19/11/2018 8:22:58 PM            
VW0034L7 Vault          Vault 19/11/2018 8:22:58 PM            
VW0040L7 Slot              34 25/11/2018 5:39:09 PM            
VW0035L7 Slot               5 25/11/2018 5:39:09 PM            
VW0043L7 Slot              37 26/11/2018 12:06:28 AM           
VW0041L7 Slot              33 26/11/2018 12:30:46 AM           
VW0044L7 Slot              36 26/11/2018 12:30:46 AM           
VW0037L7 Slot              31 26/11/2018 12:30:46 AM           
VW0038L7 Slot              30 26/11/2018 12:30:46 AM           
VW0045L7 Slot              29 26/11/2018 3:34:32 AM            
VW0036L7 Slot              35 26/11/2018 3:34:32 AM            
VW0039L7 Slot              26 26/11/2018 3:34:32 AM            
VW0042L7 Slot              27 26/11/2018 3:34:32 AM            
VM0003L7 Slot              25 29/10/2019 8:53:11 PM            
VM0002L7 Slot              21 29/10/2019 8:53:11 PM            
VM0001L7 Slot              17 29/10/2019 8:53:11 PM            
VM0006L7 Slot              24 30/10/2019 7:16:29 PM            
VM0004L7 Slot              16 30/10/2019 7:16:29 PM            
VM0005L7 Slot              20 30/10/2019 7:16:29 PM            
VM0007L7 Slot              15 31/10/2019 1:41:00 AM            
VM0009L7 Slot              19 31/10/2019 11:45:08 PM           
VM0008L7 Slot              14 31/10/2019 11:45:08 PM           
VM0010L7 Slot              23 1/11/2019 5:01:43 AM
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List Tapes useb by job

Post by veremin »

As far as I remember, VBRTapeMedium does not have ExpiresIn parameter. What you can do is to subtract current date from expiration one and output the result. Something like this:

Code: Select all

($_.ExpirationDate - (Get-Date)).Days
Thanks!
ChrisVH1982
Influencer
Posts: 15
Liked: never
Joined: May 28, 2012 10:44 am
Full Name: Christian van Haut
Contact:

[MERGED] Get tapes of tape backup session

Post by ChrisVH1982 »

Hello community,

I have been trying getting a report of the last monthly tape backup job with all tapes involved.

The following command returns the last job:
Get-VBRSession -Job (Get-VBRTapeJob -Name "Monthly") | Sort-Object CreationTime -Descending | Select -First 1

The following command returns all monthly tapes:
(Get-VBRTapeMediaPool -Name "Monthly_MSL4048" | Select Medium).Medium

But I need to get a list of tapes used for a specific job and don't know how to combine these commands.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List Tapes useb by job

Post by veremin » 1 person likes this post

Kindly, check the examples provided above and see whether they answer your requirements. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests