PowerShell script exchange
Post Reply
UnknownRectangle
Novice
Posts: 3
Liked: never
Joined: Aug 08, 2023 11:54 am
Full Name: Steven Gallagher
Contact:

GetAllStorages() method returns no value for new backup chain format

Post by UnknownRectangle »

Hi All,

We've been using a script for a long time now to report the backup size per job each day. However, we've noticed that backups using the new backup chain format (per-vm backup file and metadata) returns no value for the GetAllStorages() method. For the backups that haven't been upgraded yet we still get a value. I'm guessing this is due to the new backup chain format?

I'm fairly amateur with powershell and looking for some pointers on how to resolve this, any help would be appreciated. Below is the script that we've been using:

Code: Select all

# Load Veeam Snapin
Import-Module Veeam.Backup.PowerShell

#Clear out variable values
$VbrJobs = @()
$JobReport = @()
$Backup = @()
$BackupSize = @()
$Job = @()

#Get All Backup Jobs
$VbrJobs = Get-VBRJob | where-object {$_.IsScheduleEnabled -eq $True -and $_.JobType -eq "Backup"} | Sort-Object typetostring, name

#Loop through all backups jobs        
Foreach($Job in $VbrJobs)
    {
        #Clear values of all variables used
        $Objects = @()
        $Object = @()
        $VMName = @()
        $Tasks = @()
        $vmcount = @()
        $GetVMs = @()
        $WarningVMs = @()
        $WarningMsg = @()

        #Find the Last Backup Job where equals job name
        $JobDetails = $Job.FindLastSession()
        $Log = $JobDetails.Logger.GetLog()


        #Get the VBRBackup where equals job name in order to expose size of backup
        $Backup = Get-VBRBackup -Name $Job.Name
        $RepoTarget = $Job.FindTargetRepository()
        $RepoTarget = $RepoTarget.Name

        #Expose size of Backup and run calculation
        $BackupSize = $Backup.GetAllStorages() | Sort-Object creationtime | Select-Object -last 1 | select @{e={[math]::Round($_.stats.backupsize/1024/1024/1024,2)}}

        #Get all the VMs in the Job
        $Objects = $Job.GetObjectsInJob()

        #Count the number of VMs in Job
        $vmcount = $Objects.Count

        $BackupDate=(get-date (get-date).AddDays(-1) -UFormat "%d/%m/%Y")

            if ($Job.FindLastSession().Logger.GetLog().UpdatedRecords.Title | Select-String "Synthetic") {
            $isFull = "True"
        }
        else {
            $isFull = "False"
        }

        #Build Hash table of Completed Backup Jobs
        $JobReport += New-Object -TypeName psobject -Property @{
                                                                    JobName=$JobDetails.JobName;
                                                                    DateofBackup=$BackupDate;
                                                                    StartTime=$JobDetails.CreationTimeUTC;
                                                                    EndTime=$JobDetails.EndTime;
                                                                    Full=$isFull;
                                                                    Result=$JobDetails.Result;Size=$BackupSize.'[math]::Round($_.stats.backupsize/1024/1024/1024,2)';
                                                                    VMCount=$vmcount
                                                                    Repo=$RepoTarget
                                                                } 
    }

$GetDateYYYYMMDD = Get-Date -UFormat "%Y-%m-%d"
$NewFolderPath = "C:\VeeamReports\"
$GetDayOfWeek = (get-date).DayOfWeek

# Set the location of the file to save to
$FilePath = $NewFolderPath + $GetDateYYYYMMDD + "-Veeam-BackupReports.csv"

#Sort Hash table by JobName
$JobReport = $JobReport | Sort-Object -Property JobName

#Select Details to save to File - will append for the week
$JobReport | select -Property JobName,DateofBackup,StartTime,EndTime,Full,Result,Size,VMCount,Repo | Export-Csv -Append $FilePath -NoTypeInformation
david.domask
Veeam Software
Posts: 2317
Liked: 554 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: GetAllStorages() method returns no value for new backup chain format

Post by david.domask » 2 people like this post

Hi @UnknownRectangle,

Yes, very likely it's due to the new backup chain format; True Per-Machine "works" by having a "Parent" backup with a dedicated child backup for each machine in the job. (e.g., if you have 2 VMs in a job, you will have separate chains and VBM (metadata) files for both VMs).

You can find the Child Backups with the FindChildBackups() method on CBackup objects:

Code: Select all

PS C:\Users\Administrator> $backup[0].GetAllStorages()
PS C:\Users\Administrator> $backup[0].FindChildBackups().GetAllStorages() |Select id, name, creationtime

Id                                   name CreationTime
--                                   ---- ------------
77c19f36-e7e6-42fb-bdc6-1d88582316e6      7/19/2023 8:00:21 AM
f38cd05e-9a92-4f82-afa4-2576f90ad39b      7/18/2023 8:00:19 AM
49a66dc6-5ce9-4197-8e50-267297086b68      8/8/2023 1:21:45 PM
eb0493d3-78af-4610-af2d-5c0e9e37fc1a      7/16/2023 8:00:04 AM
7a84e8d9-cef5-45ad-8465-680adaccd5f3      8/9/2023 8:00:22 AM
6477b4b6-9855-43a9-b0a0-6a1a733dec25      7/15/2023 8:00:21 AM
db0da294-72c6-4de1-aa05-c031c101079a      7/17/2023 8:00:08 AM
6affb6f7-8824-431e-8d5c-d48cf7d8a7b6      7/13/2023 8:00:15 AM
ed70dbb6-c0d1-4eac-ace7-d73f7028deab      7/14/2023 8:00:19 AM
e060ba72-fcd8-4078-b283-f77da7c90d67      7/17/2023 8:16:54 PM
See on the second line that we call FindChildBackups first and then call GetAllStorages()?

I've truncated the results for readability purposes, but you can get the idea I think.

Similarly, the above is just example code; in real scripting, you should avoid chained .NET methods (i.e., don't do $variable.SomeMethod().AnotherMethod() )

Chaining like this can make debugging scripts really difficult as it "swallows" the real issues sometimes and also can have unpredictable results. Instead do it like:

$ChildBackups = $backup.FindChildBackups()
$ChildBackups.GetAllStorages()

Note that the FindChildBackups() may return an array of multiple child backups, so probably call this outside of a loop, then loop over the child backups and execute your code.
David Domask | Product Management: Principal Analyst
david.domask
Veeam Software
Posts: 2317
Liked: 554 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: GetAllStorages() method returns no value for new backup chain format

Post by david.domask » 1 person likes this post

Also small addendum: I don't have time to test this, but I think that GetAllChildrenStorages() method on the CBackup objects will also do what you want.

For some reason I forgot we were talking about GetAllStorages() and not GetAllChildrenStorages(); I don't know the _exact_ difference between these methods, but I remember in v10 we introduced GetAllChildrenStorages() and when I checked in the past, this one was preferred. They return mostly the same data, but I think GetAllChildrenStorages() is preferred.
David Domask | Product Management: Principal Analyst
oleg.feoktistov
Veeam Software
Posts: 2015
Liked: 671 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: GetAllStorages() method returns no value for new backup chain format

Post by oleg.feoktistov » 1 person likes this post

The difference is that GetAllChildrenStorages(), unlike GetAllStorages(), if invoked on a parent backup, queries children backups and returns a list of children storages. It also works on a child backup though. So, with GetAllChildrenStorages() you kind of have it all in one method.
Not 100% sure, but I suppose GetAllChildrenStorages() was made for convenience after we supported agent management. That's where parent-child backup relations were introduced on the backend before backup copy immediate mode and true per-vm era.
david.domask
Veeam Software
Posts: 2317
Liked: 554 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: GetAllStorages() method returns no value for new backup chain format

Post by david.domask » 1 person likes this post

Ah, thanks for the extra info @oleg.feoktistov. It would make sense yeah, and I even have a note on this in my PS notes that says something similar. :)

So yeah, I guess for anyone reading, starting with v10, if you are using GetAllStorages(), switch to GetAllChildrenStorages(). From my notes and testing the difference, the latter always returned everything that the former did, but also the child backups that weren't included by the former. I remember testing this pretty thoroughly across all backup types, but this was at the time of v10, and we've added some more since then (but I expect it will still work for those)
David Domask | Product Management: Principal Analyst
UnknownRectangle
Novice
Posts: 3
Liked: never
Joined: Aug 08, 2023 11:54 am
Full Name: Steven Gallagher
Contact:

Re: GetAllStorages() method returns no value for new backup chain format

Post by UnknownRectangle »

Thanks for the info all. I'll test and see if that works.
UnknownRectangle
Novice
Posts: 3
Liked: never
Joined: Aug 08, 2023 11:54 am
Full Name: Steven Gallagher
Contact:

Re: GetAllStorages() method returns no value for new backup chain format

Post by UnknownRectangle »

Hi All,

Just wanted to confirm that it worked with the GetAllChildrenStorages() method. Similar to the example David gave:

$ChildBackups = $backup.FindChildBackups()
$ChildBackups.GetAllChildrenStorages()

This returns all backup job names appended with "- <VM-Name>". Then it was a case of looping that to retrieve the backup size per VM and totalling those together.

Thanks for the help!
Post Reply

Who is online

Users browsing this forum: No registered users and 45 guests