PowerShell script exchange
Post Reply
karsten123
Service Provider
Posts: 477
Liked: 119 times
Joined: Apr 03, 2019 6:53 am
Full Name: Karsten Meja
Contact:

Backup size per vm

Post by karsten123 »

Hi,

is it possible to get the backup size per vm?
I allready have the per job sizes.

VBR is 11a; backup repository is set to per-vm chain.

Thank you in advance.
Karsten
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Backup size per vm

Post by oleg.feoktistov » 1 person likes this post

Hi Karsten,

If you want to get backup size per each vm contained in a backup, you need to obtain storages and their sizes.
Example:

Code: Select all

$backup = Get-VBRBackup -Name 'Backup Job 1'
$rps = Get-VBRRestorePoint -Backup $backup
$totalRps = @()
foreach ($rp in $rps) {
    $storage = $rp.FindStorage()
    $sizeRounded = [Math]::Round($storage.Stats.BackupSize/1GB, 2)
    $totalRps += $rp | select Name, @{n='BackupSizeGB';e={$sizeRounded}}

}
$totalRps
If want to get backup size per every vm chain, the concept is the same, but you also need to do some simple calculations to present the sum of backup sizes for each unique backup object.
Example:

Code: Select all

$backup = Get-VBRBackup -Name 'Backup Job 1'
$rps = Get-VBRRestorePoint -Backup $backup
$objects = $backup.GetObjects()
$objectChains = @()

foreach ($object in $objects) {
    $objectRps = $rps | where {$_.ObjectId -eq $object.Id}
    $backupSize = 0
    foreach ($objectRp in $objectRps) {
    $storage = $objectRp.FindStorage()
    $sizeRounded = [Math]::Round($storage.Stats.BackupSize/1GB, 2)
    $backupSize += $sizeRounded
    }
    $objectChains += $object | select DisplayName, @{n='BackupSizeGB';e={$backupSize}}

}

$objectChains
Thanks,
Oleg
karsten123
Service Provider
Posts: 477
Liked: 119 times
Joined: Apr 03, 2019 6:53 am
Full Name: Karsten Meja
Contact:

Re: Backup size per vm

Post by karsten123 »

Hi Oleg,

thank you very much. Wow. That is exactly it.

Have a nice week.
vmtech123
Veeam Legend
Posts: 251
Liked: 136 times
Joined: Mar 28, 2019 2:01 pm
Full Name: SP
Contact:

Re: Backup size per vm

Post by vmtech123 »

This works amazing.

Now, how would i do this for All jobs? instead of 'Backup Job 1' I'd love all the jobs to get checked.

I'm assuming run the whole script for each job in jobs or something, but i am not a powershell expert :(
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Backup size per vm

Post by david.domask » 1 person likes this post

Hi @vmtech123,

Few ways but laziest way is just get all Backups and then use a foreach loop and nest the above code into the loop. For example:

Code: Select all

$backups = Get-VBRBackup
$objectChains = @()

foreach($b in $backups){
	$rps = Get-VBRRestorePoint -Backup $b
	$objects = $b.GetObjects()

	foreach ($object in $objects) {
		$objectRps = $rps | where {$_.ObjectId -eq $object.Id}
		$backupSize = 0
		foreach ($objectRp in $objectRps) {
		$storage = $objectRp.FindStorage()
		$sizeRounded = [Math]::Round($storage.Stats.BackupSize/1GB, 2)
		$backupSize += $sizeRounded
		}
		$objectChains += $object | select DisplayName, @{n='BackupSizeGB';e={$backupSize}}

	}
}
$objectChains
Notice a few things:

1. Move the array initialization for $objectChains outside of the loop, otherwise it will initialize a new array on every loop (and erase the old one ;) )
2. For any point calling the CBackupObject ($backups in Oleg's original code), we rename it to the variable $b chosen for the loop
David Domask | Product Management: Principal Analyst
vmtech123
Veeam Legend
Posts: 251
Liked: 136 times
Joined: Mar 28, 2019 2:01 pm
Full Name: SP
Contact:

Re: Backup size per vm

Post by vmtech123 »

Thanks so much. I appreciate the help and the fact you explained WHY :) I think i was on the right track but this makes sense.. Awesome
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Backup size per vm

Post by david.domask »

Always welcome! Good luck with scripting :)

And I'm glad you like the explanations; they come from the pain I went through learning this stuff, so learn from my pain :D
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests