PowerShell script exchange
Post Reply
nnaveenkumar
Lurker
Posts: 1
Liked: never
Joined: Jan 02, 2023 2:19 pm
Full Name: Naveen Kumar
Contact:

Script for retrieving VM backed up size and path for the VM/Servers

Post by nnaveenkumar »

Hi All,

Can anyone help in getting Powershell script to retrieve occupancy and repository destination path of All servers/VMs backed up.
rovshan.pashayev
Veeam Software
Posts: 404
Liked: 79 times
Joined: Jul 03, 2023 12:44 pm
Full Name: Rovshan Pashayev
Location: Czechia
Contact:

Re: Script for retrieving VM backed up size and path for the VM/Servers

Post by rovshan.pashayev »

Hello,

Try following script, which should give you Server/VM name, Job Name and Repository Path:

Code: Select all

Get-VBRBackup | ForEach-Object {
    $backupJob = $_
    $jobName = $backupJob.Name
    $jobObject = Get-VBRJob -Name $jobName
    $vmNames = Get-VBRJobObject -Job $jobObject | Select-Object -ExpandProperty Name

    $repositoryPath = ($backupJob.GetRepository()).Path

    foreach ($vmName in $vmNames) {
        [PSCustomObject]@{
            Name = $vmName
            JobName = $jobName
            RepositoryPath = $repositoryPath
        }
    }
}
Rovshan
Rovshan Pashayev
Analyst
Veeam Agent for Linux, Mac, AIX & Solaris
oleg.feoktistov
Veeam Software
Posts: 2000
Liked: 662 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Script for retrieving VM backed up size and path for the VM/Servers

Post by oleg.feoktistov »

Hi Naveen,

Adding to Rovshan's point, if you want to discover how much space each machine occupies in a repository (like you do in backup properties in the UI), you can try this sample script:

Code: Select all

$jobs = Get-VBRJob | where {$_.JobType -eq 'Backup'}
$repos = Get-VBRBackupRepository
$objectStorageTypes = @('AmazonS3', 'AmazonS3Compatible', 'AmazonS3Glacier', 'AmazonSnowball', 'AzureArchiveStorage', 'AzureDataBox', 'AzureStorage', 'GoogleCloudStorage', 'IbmCosS3', 'WasabiS3')
$backups = Get-VBRBackup 
foreach ($job in $jobs) {
    $backup = $backups | where {$_.JobId -eq $job.Id}
    $childBackups = $backup.FindChildBackups()
    foreach ($childBackup in $childBackups) {
      $backupSize = $null
      $storages = $childBackup.GetAllStorages()
      foreach ($storage in $storages) {
        $backupSize += $storage.Stats.BackupSize
      }
      $roundedSize = [Math]::Round($backupSize/1GB, 2)
      $repo = $repos | where {$_.Id -eq $childBackup.RepositoryId}
      $vmName = $childBackup.GetVmOrJobName()
      if ($repo.Type -iin $objectStorageTypes) {
         switch ($repo.Type) {
           'AzureStorage' { 
             $objectStorage = Get-VBRObjectStorageRepository -Id $repo.Id
             $account = $repo.Credentials.Account
             $folder = $objectStorage.AzureBlobFolder.Name
             $container = $objectStorage.AzureBlobFolder.Container.Name
             $path = "azureBlob://ofstorageaccount02/container/Veeam"
            
           }

         }
        $childBackup | select @{n='MachineName';e={$vmName}}, @{n='RepositoryName';e={$repo.Name}}, `
            @{n='Path';e={$path}}, @{n='BackupSizeGB';e={$roundedSize}}
      }
      else {
        $childBackup | select @{n='MachineName';e={$vmName}}, @{n='RepositoryName';e={$repo.Name}}, `
            @{n='Path';e={$childBackup.DirPath}}, @{n='BackupSizeGB';e={$roundedSize}}
      }
    }
}

Please note that it gets a bit tricky with object storage as a standalone repository as there is no direct path there, so in the example above for Azure Blob Storage I constructed a repository path that you can see in the UI. The sample above is just for backup jobs with azure blob and common repositories (windows, linux etc.) as targets, but the principle for other object storages targeted directly is pretty much the same.

Hope it helps,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests