PowerShell script exchange
Post Reply
Glen.Adkins
Novice
Posts: 4
Liked: never
Joined: Oct 16, 2023 5:17 pm
Full Name: Glen Adkins
Contact:

Total Storage used per Job for offsite calculation

Post by Glen.Adkins »

Hello,
I need to calculate how much offsite storage I may need for my offsite backups of my current backup chains. I put together something but its not quite what I am looing for. Obviously management needs this to determine how much storage we need to purchase for our offsite copy jobs. It would be great if it outputs to a excel spreadsheet as well. I have a script as I said, but I am not sure of the values it is returning and if this is the number I need. Also, I cannot tell the size format either. This is an output example:

Jobname Endtime TotalUsedSize ReadSize TransferedSize
prod-job-01 10/15/2023 22:07 58,312,616,455,234 3,504,784,539,648 1,283,170,031,516
Is this the total size of the job, including all of the restore points, or simply last nights job size?
Ideas?
Thank you
Glen
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Total Storage used per Job for offsite calculation

Post by oleg.feoktistov »

Hi Glen,

It's really hard to tell whether you are getting correct metrics without looking into the script. Could you please share it? Omitting private info, of course.

Best regards,
Oleg
Glen.Adkins
Novice
Posts: 4
Liked: never
Joined: Oct 16, 2023 5:17 pm
Full Name: Glen Adkins
Contact:

Re: Total Storage used per Job for offsite calculation

Post by Glen.Adkins »

Thank you.
As requested.

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

Disconnect-VBRServer | out-null
connect-vbrserver -server servername -user useraccount

$JobsOutput = @()


Foreach ($JobObject in Get-VBRJob | ?{$_.JobType -eq "Backup"})
{
$LastSession = $JobObject.FindLastSession()
$JobOutput = New-Object -TypeName PSObject
$JobOutput | Add-Member -Name "Jobname" -MemberType Noteproperty -Value $JobObject.Name
$JobOutput | Add-Member -Name "Endtime" -MemberType Noteproperty -Value $LastSession.endtime
$JobOutput | Add-Member -Name "TotalUsedSize" -MemberType Noteproperty -Value $LastSession.Info.Progress.TotalUsedSize
$JobOutput | Add-Member -Name "ReadSize" -MemberType Noteproperty -Value $LastSession.Info.Progress.ReadSize
$JobOutput | Add-Member -Name "TransferedSize" -MemberType Noteproperty -Value $LastSession.Info.Progress.TransferedSize
$JobsOutput += $JobOutput
$JobsOutput | Export-Csv -Path c:\temp\Storagetest.csv

}
$JobsOutput | Out-GridView
Disconnect-VBRServer | out-null
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Total Storage used per Job for offsite calculation

Post by oleg.feoktistov » 1 person likes this post

Thanks for sharing the script. Just for future references - in the message preview mode you can wrap your code in tags (</> label) to make it more readable (like I did above).

As for your questions:
I am not sure of the values it is returning and if this is the number I need
TotalUsedSize - the used size on a source VM.
ReadSize - the amount of data read from source before applying compression and deduplication.
TransferedSize - the amount of data transferred to target after applying compression and deduplication.

You can read more on the real-time session metrics here.
Also, I cannot tell the size format either
These sizes are all in bytes, so for convenience I usually go with this formatting:

Code: Select all

[Math]::Round($LastSession.Info.Progress.TransferedSize/1GB, 2)
Is this the total size of the job, including all of the restore points, or simply last nights job size?
Your script pulls only the last run for each job. Meaning it will calculate metrics only for the last restore point for each job you iterate over.

The closest data here that more or less corresponds to the size of a restore point is the one held in TransferedSize. However, VBR can invoke other activities that may impact the resulting restore point size. So if you are after actual amount of all the restore points created in a backup, here is the better way to get this info:

Code: Select all

$ErrorActionPreference = "SilentlyContinue"
$backups = Get-VBRBackup
$jobs = Get-VBRJob | where {$_.JobType -eq 'Backup'}

foreach ($job in $jobs) {
  $backup = $backups | where {$_.JobId -eq $job.Id}
  $storages = $backup.GetAllChildrenStorages()
  $totalSize = $null
  foreach ($storage in $storages) {
    $totalSize += $storage.Stats.BackupSize
  }
  $backup | select Name, @{n='TotalSize';e={[Math]::Round($totalSize/1GB, 2)}}
}
This script sums up all actual backup file sizes in a backup and reflects total size along with the backup name for each job.

Hope it helps,
Oleg
Glen.Adkins
Novice
Posts: 4
Liked: never
Joined: Oct 16, 2023 5:17 pm
Full Name: Glen Adkins
Contact:

Re: Total Storage used per Job for offsite calculation

Post by Glen.Adkins »

I copied and pasted what you wrote into a new script and then added the VBR server and it runs, but it doesnt display anything. I am assuming I need to add that portion. Correct?
I added this.

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

Disconnect-VBRServer | out-null
connect-vbrserver -server =VBRServer -user useraccount


Not sure which variable I need to use to output this to a CSV file.
Ideas?
Thanks
Glen
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Total Storage used per Job for offsite calculation

Post by oleg.feoktistov »

Looks like mistyped the property name. It should be $jobs = Get-VBRJob | where {$_.JobType -eq 'Backup'}. I amended the original script.
Not sure which variable I need to use to output this to a CSV file.
You could declare an empty array for all backups before the loop and add there a backup every iteration. Then export this array to csv like you did in your script. Thanks!
Glen.Adkins
Novice
Posts: 4
Liked: never
Joined: Oct 16, 2023 5:17 pm
Full Name: Glen Adkins
Contact:

Re: Total Storage used per Job for offsite calculation

Post by Glen.Adkins »

Thank you! Got it! This worked for what I needed.
Thanks again!!
Glen
RubinCompServ
Service Provider
Posts: 261
Liked: 66 times
Joined: Mar 16, 2015 4:00 pm
Full Name: David Rubin
Contact:

Re: Total Storage used per Job for offsite calculation

Post by RubinCompServ »

oleg.feoktistov wrote: Oct 17, 2023 4:46 pm

Code: Select all

$ErrorActionPreference = "SilentlyContinue"
$backups = Get-VBRBackup
$jobs = Get-VBRJob | where {$_.JobType -eq 'Backup'}

foreach ($job in $jobs) {
  $backup = $backups | where {$_.JobId -eq $job.Id}
  $storages = $backup.GetAllChildrenStorages()
  $totalSize = $null
  foreach ($storage in $storages) {
    $totalSize += $storage.Stats.BackupSize
  }
  $backup | select Name, @{n='TotalSize';e={[Math]::Round($totalSize/1GB, 2)}}
}
This script sums up all actual backup file sizes in a backup and reflects total size along with the backup name for each job.

Hope it helps,
This was a HUGE help! Thank you @oleg.feoktistov!
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Total Storage used per Job for offsite calculation

Post by oleg.feoktistov »

@RubinCompServ, glad to help. Have a great New Year!
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests