PowerShell script exchange
Post Reply
Rmachado
Service Provider
Posts: 23
Liked: 4 times
Joined: Dec 15, 2016 11:39 pm
Contact:

Query name, last result and barcode from Tape Job

Post by Rmachado »

Hello.

Im trying to get the info from the tape barcodes used in the last run of a job or set of jobs (it can be a where using a daily media pool, for example) in powershell . Tried in Veeam One, but i cant get that info for the selected jobs displaying the last used tapes (or a query with period of time).

To be more clear , what im trying to do :
Name of the job, last run, creation date, Barcode used, media set (These info are all in the right click in a Job - Report)
Image

i tried to use Get-VBRTapeMedium, but i can get only lastWriteTime, but not the job names
Tried Get-VBRTapeJob to get the ame, Type (Tape Job) and Media Set, LastResult, but i cant get the used media.

I dont know how to use both to get to the results that i need. Someone can give me a idea how to use both in the same powershell?

Thank you!
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Query name, last result and barcode from Tape Job

Post by oleg.feoktistov »

Hi @Rmachado,

I'm afraid I cannot find any direct bindings between tape backup sessions and tape medium neither in Powershell objects, nor in core .NET classes/methods to explicitly tell which ones were used here and there. The only and quite implicit relevance I found, which might help (or might not) is tape medium's LastWriteTime vs. tape backup session's EndTime. Comparing those datetimes and validating mediums used in a job we are acting on, I was able to get more or less specific info. Sample code:

Code: Select all


# Get backup to tape jobs
$job = Get-VBRTapeJob | where {$_.Type -eq 'BackupToTape'}

# Select last session for a tape job
$session = [Veeam.Backup.Core.CBackupSession]::GetByJob($job[1].Id) | select -Last 1

# Parse tape mediums with LastWriteTime =< session EndTime (but not less than 2 hours ago from session EndTime)
$mediums = Get-VBRTapeMedium | where {$_.LastWriteTime -le $session.EndTime -and $_.LastWriteTime -ge $session.EndTime.AddHours(-2)}
$summary = @()
foreach ($medium in $mediums) {

    # Check if medium in question belongs to tape job's full backup media pool
    foreach ($jobMedium in $job[1].FullBackupMediaPool.Medium) {
        if ($medium.Barcode -eq $jobMedium.Barcode) {

    # If it does, create custom object and add it to summary
            $summary += $medium | select @{n='MediumUsed';e={$_.Name}}, @{n='JobMedium';e={$jobMedium}}, @{n='SessionName';e={$session.Name}}, @{n='SessionEndTime';e={$session.EndTime}}, @{n='MediumLastWriteTime';e={$medium.LastWriteTime}}, Barcode, Location, Capacity, FreeSpace, MediaSet
        }
    }
   
  # Check if medium in question belongs to tape job's incremental backup media pool
    foreach ($jobMedium in $job[1].IncrementalBackupMediaPool.Medium) {
        if ($medium.Barcode -eq $jobMedium.Barcode) {

   # If it does, create custom object and add it to summary
            $summary += $medium | select @{n='MediumUsed';e={$_.Name}}, @{n='JobMedium';e={$jobMedium}}, @{n='SessionName';e={$session.Name}}, @{n='SessionEndTime';e={$session.EndTime}}, @{n='MediumLastWriteTime';e={$medium.LastWriteTime}}, Barcode, Location, Capacity, FreeSpace, MediaSet
        }
    }
   
} 
Hope it can be of any help.

Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: MarkBoothmaa and 19 guests