PowerShell script exchange
Post Reply
donaldli
Service Provider
Posts: 23
Liked: 7 times
Joined: Mar 17, 2021 3:22 am
Full Name: Donald Li
Contact:

backup GetAllStorages() BackupSize different to SOBR Used Space

Post by donaldli »

When I sum BackupSize retrieved from GetAllStorages of all backups, the total amount looks higher than the number being viewed through SOBR Used Space.
What's the difference in between those two approaches?

Code: Select all

            foreach ($storage in $backup.GetAllStorages()) {
                if (-Not $storage.IsContentExternal) {
                    $usedSpace += $storage.Stats.BackupSize
                }
            }
david.domask
Veeam Software
Posts: 1952
Liked: 473 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: backup GetAllStorages() BackupSize different to SOBR Used Space

Post by david.domask »

Hi @donaldli,

First just a note mostly for the other readers that the .NET Methods are not supported and may have some nuances that might preclude a full answer here, but I'll do my best.

How are you building the $backup object just for my reference?

Similarly, can you use GetAllChildrenStorages() instead of GetAllStorages()? The latter is an older method and I'm not sure where (if at all) it's used, but for long time I've been using GetAllChildrenStorages() as it seems to be what we call usually nowadays.

I did notice some incongruencies in my lab, but I also purposefully break things in my lab so I suspect I have some entries in the db that aren't showing in the UI (probably my fault from old db edit testing, not expected in actual environments)

If you can explain how you build $backups and confirm that switching to GetAllChildrenStorages() doesn't meet your needs (Still use this one IMO), then post again and will think on it.
David Domask | Product Management: Principal Analyst
donaldli
Service Provider
Posts: 23
Liked: 7 times
Joined: Mar 17, 2021 3:22 am
Full Name: Donald Li
Contact:

Re: backup GetAllStorages() BackupSize different to SOBR Used Space

Post by donaldli »

Hi David,
Thanks for your reply!
I tried using GetAllChildrenStorages() and tested in 3 environments. It looks like the GetAllChildrenStorages() will return double. I guess it's because we had upgraded backup chain format.
  • In 1st environment:
    - OrgA
    -- VBR Console used space: 13.2 TB
    -- PS GetAll total backupsize: 12.89 TB
    -- PS GetAll # of storage: 4055
    -- PS GetChildrenAll total backupsize: 23.63 TB
    -- PS GetChildrenAll # of storage: 7332
    - OrgB
    -- VBR Console used space: 13.1 GB
    -- PS GetAll total backupsize: 13.13 GB
    -- PS GetAll # of storage: 2
    -- PS GetChildrenAll total backupsize: 26.25 GB
    -- PS GetChildrenAll # of storage: 4
  • In 2nd environment:
    - OrgC
    -- VBR Console used space: 11.57 TB
    -- PS GetAll total backupsize: 11.57 TB
    -- PS GetAll # of storage: 3084
    -- PS GetChildrenAll total backupsize: 22.85 TB
    -- PS GetChildrenAll # of storage: 6092
    - OrgD
    -- VBR Console used space: 9.5 GB
    -- PS GetAll total backupsize: 9.5 GB
    -- PS GetAll # of storage: 2
    -- PS GetChildrenAll total backupsize: 19.0 GB
    -- PS GetChildrenAll # of storage: 4
  • The 3rd environment is very big. Now my code is still running. It output all storage in details for both GetAllStorages and GetAllChildrenStorages. As for now, the # of storage by GetAllStorages is 400k, while the # of storage by GetAllChildrenStorages is 483k.
    They are different.
david.domask
Veeam Software
Posts: 1952
Liked: 473 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: backup GetAllStorages() BackupSize different to SOBR Used Space

Post by david.domask »

Hi Donald,

Thanks for that - you mention Orgs, is it correct you're using this on vCD backups? I suspect you may be correct and multiple objects are being returned from vApps or something, but I would check the first 10 outputs of one of the arrays you return and just see what's under there; my guess is that indeed it will return some duplicate data perhaps, but it's been awhile since I worked with vCD. If you can confirm it and share your script, I can try to take a look and see why we might have excess results.
David Domask | Product Management: Principal Analyst
donaldli
Service Provider
Posts: 23
Liked: 7 times
Joined: Mar 17, 2021 3:22 am
Full Name: Donald Li
Contact:

Re: backup GetAllStorages() BackupSize different to SOBR Used Space

Post by donaldli »

Hi David,
Yes, we're using vCD backup.
Here is the PS Code.
$logFile is output of all storages retrieved by $backup.GetAllStorages().
$logFileCS is output of all storages retrieved by $backup.GetAllChildrenStorages().

Code: Select all

try {
    $vcdOrgItems = Find-VBRvCloudEntity -Organization

    $now = Get-Date
    $report = New-Object -TypeName System.Collections.Generic.List[PSCustomObject]​
    # Write-LogOutput $logFile "`n$($vcdOrg.OrgName)`tbackupId`tbackup.JobId`tbackup.JobName"
    foreach ($item in $vcdOrgItems) {
        $vcdHost = $item.Path.Split("\")[0]
        $vcd = Get-VBRServer -Name $vcdHost
        $siteRef = ($vcd.Info.Options | select-xml -XPath '/root/VcdConnectionOptions/LocalSiteUid').Node.InnerXml
        $hostSiteUid = $item.VcdRef.GetType()::Make($siteRef)
        $vcdOrg = New-Object -TypeName Veeam.Backup.Model.CVcdOrganization `
            -ArgumentList $item.VcdId, $hostSiteUid, $item.VcdRef, $item.Name

        $unique_vms = @()
        $usedSpace = 0
        $usedSpaceCS = 0
        $totalObjects = 0
        $orgBackupIds = [Veeam.Backup.DBManager.CDBManager]::Instance.VcdMultiTenancy.FindOrganizationBackups($vcdOrg)
        $backupseq = 0
        Write-LogOutput $logFile "`n$($vcdOrg.OrgName)`tbackupId`tbackup.JobId`tbackup.JobName`tbackup.CreationTime`tbackup.VmCount`tbackup.LastPointCreationTime`t`tinternalstorageseq`tstorage.Stats.BackupSize`tstorage.CreationTime`tstorage.PartialPath"

        Write-LogOutput $logFileCS "`n$($vcdOrg.OrgName)`tbackupId`tbackup.JobId`tbackup.JobName`tbackup.CreationTime`tbackup.VmCount`tbackup.LastPointCreationTime`t`tinternalstorageseq`tstorage.Stats.BackupSize`tstorage.CreationTime`tstorage.PartialPath"
        foreach ($backupId in $orgBackupIds) {
            $backupseq += 1
            $backup = [Veeam.Backup.Core.CBackup]::Get($backupId)
            $backup_prefix = "$backupseq`t$backupId`t$($backup.JobId)`t$($backup.JobName)`t$($backup.CreationTime)`t$($backup.VmCount)`t$($backup.LastPointCreationTime)`t"

            # Loop through the storage usage and only report the "internal" storage
            # We query COS directly to obtain the "external" storage separately
            $internalstorageseq = 0
            $backupstoragesizetotal = 0
            foreach ($storage in $backup.GetAllStorages()) {
                if (-Not $storage.IsContentExternal) {
                    $internalstorageseq += 1
                    Write-LogOutput $logFile "$backup_prefix`t$internalstorageseq`t$($storage.Stats.BackupSize)`t$($storage.CreationTime)`t$($storage.PartialPath)"
                    $backupstoragesizetotal += $storage.Stats.BackupSize
                }
            }
            # Write-LogOutput $logFile "$backupseq`tBackup All Storage size:`t$backupstoragesizetotal"
            $usedSpace += $backupstoragesizetotal

            $internalstorageseq = 0
            $backupchildrenstoragesizetotal = 0
            foreach ($storage in $backup.GetAllChildrenStorages()) {
                if (-Not $storage.IsContentExternal) {
                    $internalstorageseq += 1
                    Write-LogOutput $logFileCS "$backup_prefix`t$internalstorageseq`t$($storage.Stats.BackupSize)`t$($storage.CreationTime)`t$($storage.PartialPath)"
                    $backupchildrenstoragesizetotal += $storage.Stats.BackupSize
                }
            }
            $usedSpaceCS += $backupchildrenstoragesizetotal
        }

        $orgReport = @{
            orgName      = $vcdOrg.OrgName;
            protectedVms = $unique_vms.Length;
            totalObjects = $totalObjects;
            usedSpace    = $usedSpace;
            usedSpaceCS  = $usedSpaceCS;
            # URL = $item.Path
        }
        $report.Add($orgReport)
    }

    $result = ConvertTo-Json -Compress $report

    New-Item $lockfile -Type File -Force -Value "$(Get-TimeStamp) lock" | Out-Null
    Start-Sleep -s 1
    New-Item $reportfile -Type File -Force -Value $result | Out-Null
    Remove-Item $lockfile

}
catch {
    $Msg = $_.Exception.Message
    $Item = $_.Exception.ItemName
    Write-Host "Info: [Generate-OrganizationReport] $Msg"
    Exit 1
}
finally {
    if ($disconnect_session) { Disconnect-VBRServer }
}

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests