PowerShell script exchange
Post Reply
Morpheus666
Novice
Posts: 3
Liked: 1 time
Joined: Jun 21, 2016 3:17 pm
Full Name: John Spencer
Contact:

Help with script that returns BackupDate, JobName, VMName, VMSize, BackupSize

Post by Morpheus666 »

Case # ESC0010972 - Veeam Backup & Replication - Technical Case 06110593 Escalation

I inherited the backups a few months ago when the guy running it left the company. I recently upgraded VEEAM BR to version 12. The very next time the script below ran (that has worked for several years) it stopped working on 'GetLastOibs'.
The error is "Cannot find an overload for "GetLastOibs" and the argument count: "0"."
Here is the script, is it an easy fix?

Code: Select all

$date = get-date -f MM-dd-yyyy
$CSVFile = ".\reports\VeeamBackup_$date.csv"

Add-PSSnapIn VeeamPSSnapIn -ErrorAction SilentlyContinue

$cdate=Get-Date
$backups=@()
foreach ($bkp in Get-VBRBackup) {
    $DataSize = ($bkp.GetLastOibs()|select -ExpandProperty AuxData|select -ExpandProperty RealVmSize|measure -sum).sum
    $BkpSize = ($bkp.GetAllStorages()|select -ExpandProperty Stats|select -ExpandProperty BackupSize|measure -sum).sum
    foreach ($obj in $bkp.GetLastOibs()) {
        $vm = New-Object PSObject -Property @{
            BackupDate = $cdate
            JobName = $bkp.JobName
            VMName = $obj.Name
            VMSize  = $obj.AuxData.RealVmSize
            BackupPct = $obj.AuxData.RealVmSize / $DataSize
            BackupSize = $BkpSize * ($obj.AuxData.RealVmSize / $DataSize)
        }
        $backups += $vm
    }
    $DataSize = 0
    $BkpSize = 0
}
$backups|select BackupDate, JobName, VMName, VMSize, BackupSize |Export-Csv -NoTypeInformation $CSVFile
copy $CSVFile \\servername\folder
david.domask
Veeam Software
Posts: 2590
Liked: 606 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Help with script that returns BackupDate, JobName, VMName, VMSize, BackupSize

Post by david.domask »

Hi @Morpheus666,

First, as I think was mentioned in the case, GetLastOibs() and GetAllStorages() are not supported; these are internal .NET methods, and they change quite frequently and are not designed for public supportability in mind. You can see my explanation on supported vs unsupported methods here and what to expect when using them: post477483.html#p477483

Probably you will want to pass the $bkp variable to Get-VBRRestorePoint with the -Backup parameter; it returns COib objects much like the GetLastOibs() method does, just without a filter. You can further filter based on the -Name parameter for Get-VBRRestorePoint.

Very likely, GetAllOibs() is not responding because of a change in v12 to include True PerMachine backup files. The structure of these backups have a parent/child relationship, which is why I don't think it's passing anything.

I strongly recommend to use Get-VBRRestorePoint and adjust your scripts to use this data to fetch the COib objects, as you may run into such bumps on future updates using the unsupported .NET methods.

If you're willing to stay in Unsupported Territory, you can use the following, but please note that such unsupported methods are outside the scope of Veeam Support and you will need to seek assistance on the forums for future updates if it breaks.

Pass $true as an argument for the GetLastOibs() method:

Code: Select all

PS C:\Users\Administrator> $Backup.GetLastOibs($true)

VM Name                   Creation Time          Type
-------                   -------------          ----
ddom-tinyvm               6/16/2023 8:05:02 AM   Increment
ddom-tinyvm               4/13/2023 11:50:31 AM  Full
ddom-tinyvm               2/10/2023 8:00:47 AM   Increment
ddom-tinyvm               8/29/2022 11:16:10 PM  Full
GetLastOibs() has an argument it needs answered as to whether it should delve into the child backups or not; by setting it to true, it will parse through the child backups and return the COib information from them.
David Domask | Product Management: Principal Analyst
Morpheus666
Novice
Posts: 3
Liked: 1 time
Joined: Jun 21, 2016 3:17 pm
Full Name: John Spencer
Contact:

Re: Help with script that returns BackupDate, JobName, VMName, VMSize, BackupSize

Post by Morpheus666 »

Thank you so much for the reply, I agree using the preferred method will be the way to go. I inherited this whole setup, I'm trying to fix a lot of broken things. So getting this part functional now is really important, it's how we charge back for part of the storage used. I'll definitely be asking how to get the same data points with the commandlet Get-VBRRestorePoint,,, again thank you very much.
david.domask
Veeam Software
Posts: 2590
Liked: 606 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Help with script that returns BackupDate, JobName, VMName, VMSize, BackupSize

Post by david.domask »

Glad I could help @Morpheus666, and sure, I think as a holdover just to get reporting going, you can use the unsupported workaround until you and your team are ready to refactor this part of the code.

It likely won't need much change, literally just replacing the call for GetLastOibs() with Get-VBRRestorePoint and whatever filters you desire :)

But when you're ready for it, make a new thread with your script and business logic, and let us know which part is giving headaches.
David Domask | Product Management: Principal Analyst
Morpheus666
Novice
Posts: 3
Liked: 1 time
Joined: Jun 21, 2016 3:17 pm
Full Name: John Spencer
Contact:

Re: Help with script that returns BackupDate, JobName, VMName, VMSize, BackupSize

Post by Morpheus666 » 1 person likes this post

I will...Thank you again, the accountants have their data and are happy, at least as happy as accountants can be.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests