PowerShell script exchange
Post Reply
Danh3
Enthusiast
Posts: 30
Liked: never
Joined: Nov 09, 2022 2:20 pm
Full Name: Dan
Contact:

retrieve information for restore point data size, name, and backup size of wins agent-level backup

Post by Danh3 »

How to retrieve information for restore point data size, name, and backup size for Wins agent-level backup.

I tested 3 but none of them work :
Get-VBRRestorePoint
GetAllStorages()
GetAllChildrenStorages()

thanks
Danh3
Enthusiast
Posts: 30
Liked: never
Joined: Nov 09, 2022 2:20 pm
Full Name: Dan
Contact:

Re: retrieve information for restore point data size, name, and backup size of wins agent-level backup

Post by Danh3 »

I'd like to give you a quick heads-up. Following the upgrade to V12, certain source jobs still use the old format, while others have switched to the new format chain. Unfortunately, now I'm unable to retrieve data size, name, and backup size of the restore point using Get-VBRComputerBackupJob
DanielJ
Service Provider
Posts: 200
Liked: 32 times
Joined: Jun 10, 2019 12:19 pm
Full Name: Daniel Johansson
Contact:

Re: retrieve information for restore point data size, name, and backup size of wins agent-level backup

Post by DanielJ » 1 person likes this post

You don't need to look at the restore points as such. You can just do this:

$backup = Get-VBRBackup -Name "Your agent job name"
$files = $backup.GetAllChildrenStorages()

You then have all the files in use by this backup, and can inspect them further for filenames and sizes, etc.
Danh3
Enthusiast
Posts: 30
Liked: never
Joined: Nov 09, 2022 2:20 pm
Full Name: Dan
Contact:

Re: retrieve information for restore point data size, name, and backup size of wins agent-level backup

Post by Danh3 »

@DanielJ

thanks and it works fine except one of wins agent clients when use Get-VBRBackup, it doesn't return any result

but the particular client shows up in Get-VBRComputerBackupJob, Any suggestions on how to handle this ?
DanielJ
Service Provider
Posts: 200
Liked: 32 times
Joined: Jun 10, 2019 12:19 pm
Full Name: Daniel Johansson
Contact:

Re: retrieve information for restore point data size, name, and backup size of wins agent-level backup

Post by DanielJ »

That's strange, but this should work for any type of job. It relies on an unsupported method though:

Code: Select all

$alljobs = [Veeam.Backup.Core.CBackupJob]::GetAll()
$job = $alljobs|?{$_.Name -eq 'Your job name'}
if ($job.IsNasBackup) {
  $backup = Get-VBRUnstructuredBackup -name $job.Name
} else {
  $backup = $allbackups|?{$_.JobID -eq $jobid}
}
if ($job.IsEpAgentManagementParentJob) { $backup = $backup.FindChildBackups() }
if (!$backup) { $backup = $allbackups|?{$_.BackupPolicyTag -eq $jobid} }  # It seems that some agent jobs only populate this field, not JobID.
After this you should have your backup in $backup, no matter what type of job it comes from. But if its an "unstructured" backup (object/NAS) you won't be able to find the backup files with GetAllChildrenStorages().
Danh3
Enthusiast
Posts: 30
Liked: never
Joined: Nov 09, 2022 2:20 pm
Full Name: Dan
Contact:

Re: retrieve information for restore point data size, name, and backup size of wins agent-level backup

Post by Danh3 »

thanks @DanielJ

i have tried your script and for some reason it not recognizing the Get-VBRUnstructuredBackup cmdlet.

Long to short - after multiple attempts/hrs... I found a workaround in v12 that could be useful for others facing the same issue. I've included my script below just in case someone else comes across this issue.

Some context behind this issue: the upgrade to V12 has a new per-vm format, causing the script that previously worked in V11 to break.I want to get total size(VIB, VBR) of restore points for each job.

For my script, though noticed a decrease in performance, taking 5 minutes for 8 jobs compared to the one-minute completion time with the V11 script. I might revisit this later and post an update when I have more time. I only tested (RepositoryType -eq "WinLocal") but not other types or sobr... and it might work or require additional tweak/testing...

If anyone can offer assistance in optimizing performance issue, that would be greatly appreciated.
sample output:

Code: Select all

Backup In Storage(GB)	JobName		Machine	  Backup Type	  	        Repo Type
731.84			        DXXXA		HXXX01	  VMware Backup	  	Winlocal
153.84			        DXXXA		HXXX02	  VMware Backup	  	Winlocal
111.56			        CXXX		HXXX	  VMware Backup	  	Winlocal
82.61			        Backup_XXX	x.x.x.x	  Windows Agent Policy	Winlocal
80.64			        Backup_XXX	DXXXX	  Windows Agent Policy	Winlocal

Code: Select all

###Script###

$vjobs_1 = Get-VBRJob | where-object {$_.Options.JobOptions.RunManually -eq $False  } | Sort-Object -Property name 
$vjobs = $vjobs_1 | where-object {$_.IsScheduleEnabled -eq $True -and $_.TypeToString -notlike "*copy*"  } | Sort-Object -Property name 
$Stroageusage_Per_Job = @()
foreach($vjob_n in $vjobs){
    
    $j_name = $vjob_n.Name
    $jobs = $vjob_n.GetObjectsInJob()
    write-output "jobname: $($j_name) and child: $( $jobs.name)"
    $RestorePoints = Get-VBRRestorePoint 
    foreach($job in $jobs){
    
        $Job_rsp = $RestorePoints | Where-Object {$_.name -eq $job.name}
        $Job_rsp_storage = $Job_rsp.GetStorage()
        $Job_rsp_L_storage =$Job_rsp_storage | Where-Object {$_.FindBackup().RepositoryType -eq "WinLocal"}
        $Job_rsp_L_stats = $Job_rsp_L_storage.stats
        $total_dw= 0
        foreach ($Job_rsp_L_stat in $Job_rsp_L_stats){

            $Job_rsp_L_stat_dw = [Math]::Round($Job_rsp_L_stat.backupsize/1gb,2)

            $total_dw+=$Job_rsp_L_stat_dw 
        } 
        $dw_array = @{
            
            jobname = $j_name
            Client = $job.name
            repo_type = "Winlocal"
            path = $Job_rsp_storage.FilePath
            backup_type = $vjob_n.TypeToString
            dw_size = $total_dw
        
        
        }

        $Stroageusage_Per_Job += $dw_array |select-object @{Name="Backup In Storage(GB)"; Expression = {$_.dw_size}}, 
            @{Name="JobName"; Expression = {$_.jobname}},
            @{Name="Machine"; Expression = {$_.Client}},  
            @{Name="Backup Type"; Expression = {$_.backup_type}},
            #@{Name="Path"; Expression = {$_.path}},
            @{Name="Repo Type"; Expression = {$_.repo_type}}
           
           }

    }
    $Stroageusage_Per_Job  | ft -AutoSize

###End of Script###
Danh3
Enthusiast
Posts: 30
Liked: never
Joined: Nov 09, 2022 2:20 pm
Full Name: Dan
Contact:

Re: retrieve information for restore point data size, name, and backup size of wins agent-level backup

Post by Danh3 »

revised the script to display the content of restore points ("vib/vbk") for each job(including children client).
tested it for both primary and backup copies, specifically for VM and File Agent - more quicker than before...

Code: Select all

# Get all Veeam jobs that are not set to run manually and have scheduling enabled, sorted by name
$vjobs_1 = Get-VBRJob | Where-Object { $_.Options.JobOptions.RunManually -eq $False } | Sort-Object -Property Name
$vjobs = $vjobs_1 | Where-Object { $_.IsScheduleEnabled -eq $True } | Sort-Object -Property Name

# Get objects/children included in each job
$get_jobs_in_cli = $vjobs.GetObjectsInJob()

# Initialize restore point content
$rsps = Get-VBRRestorePoint

# Get restore points for source jobs
$client_in_bkp = $get_jobs_in_cli.Name
$rsps_in_bkp = $rsps | Where-Object { $_.Name -in ($client_in_bkp) }


# Initialize an array to store storage usage information per job
$Stroageusage_Per_Job = @()

# Get repository types (cloud or on-prem)
$rsp_repo_types = $rsps.FindBackup().RepositoryType | Select-Object -Unique

# Loop through each repository type
foreach ($rsp_repo_type in $rsp_repo_types) {
    $rsps_in_bkp_copies = $rsps_in_bkp | Where-Object { $_.FindBackup().RepositoryType -eq $rsp_repo_type }

    # Loop through each restore point and collect information
    foreach ($rsps_in_bkp_copy in $rsps_in_bkp_copies) {
        Write-Output "Before error, VM name: $($rsps_in_bkp_copy.Name)"

        $total_dw = 0
        $Job_rsp_storage = $rsps_in_bkp_copy.GetStorage()
        $Job_rsp_L_stat_dw = [Math]::Round($Job_rsp_storage.Stats.BackupSize / 1GB, 2)
        $total_dw += $Job_rsp_L_stat_dw

        if ($total_dw -gt 0) {
            
             $jname1 = $rsps_in_bkp_copy.GetSourceJob().Name
             
            # Create a hashtable to store storage usage information for each client
            $dw_array = @{
                JobName       = $jname1
                Client        = $rsps_in_bkp_copy.Name
                RepoType      = $rsp_repo_type
                Path          = $Job_rsp_storage.FilePath
                BackupAgent   = $rsps_in_bkp_copy.FindBackup().TypeToString
                DWSize        = $Job_rsp_L_stat_dw
                BackupType    = $rsps_in_bkp_copy.Type
            }

            # Add the hashtable to the array
            $Stroageusage_Per_Job += $dw_array | Select-Object @{
                Name       = "Backup In Storage(GB)"
                Expression = { $_.DWSize }
            }, @{
                Name       = "JobName"
                Expression = { $_.JobName }
            }, @{
                Name       = "Machine"
                Expression = { $_.Client }
            }, @{
                Name       = "Backup Agent"
                Expression = { $_.BackupAgent }
            }, @{
                Name       = "Backup Type"
                Expression = { $_.BackupType }
            }, @{
                Name       = "Repo Type"
                Expression = { $_.RepoType }
            }
        }
    }
}

# Display the storage usage information in tabular format
$Stroageusage_Per_Job | Format-Table -AutoSize
$hs = hostname
# Export the storage usage information to a CSV file
$Stroageusage_Per_Job | Export-Csv -Path "C:\temp\$($hs)-veeam.csv" -NoTypeInformation
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests