PowerShell script exchange
Post Reply
stsc_srzc
Influencer
Posts: 23
Liked: 2 times
Joined: Feb 21, 2013 11:53 am
Contact:

Get occupancy of a NAS/SMB share

Post by stsc_srzc »

Hello everyone,
I'm trying to get some occupancy information for my Veeam storage.
To get this information for each machine I have configured the repository to use per-machine backup files.
I collect information about each backup file and add up their occupancy to get a machine's total occupancy.

In my script I use Get-VBRBackup to get a list of backups. For each backup I get the objects and storages like this:

Code: Select all

$backups = Get-VBRBackup
foreach ($backup in $backups) {
	if ($backup) {
		$objects = $backup.GetObjects()
		$allStorages = $backup.GetAllStorages()
		
		foreach ($object in $objects) {
			$x = "^" + [Regex]::Escape($object.Name + ".")
			$objectRe = New-Object Regex $x, 'Compiled'

			$storages = $allStorages | Where-Object { $_.PartialPath -match $objectRe }

			foreach ($storage in $storages) {
				$stats = $storage.Stats
				# Here I use some class to store the object's name, backup size, etc. for every backup file. 
				# To get the total occupancy I add all the values per unique object name in a later step.
			}
	}
}

This works fine for VMWare backups, but for NAS/SMB backup I can't seem to get the information about the occupancy.
The command Get-VBRNASBackup shows the configured NAS backup, but I can't get any information about the storage from the output.

Is there a way to get similar information for NAS backups as in the script above?
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get occupancy of a NAS/SMB share

Post by oleg.feoktistov »

Hi,

Your script reflects no output as the architecture of NAS backups differs from those of VMware, Hyper-V etc. - there is such notion as storage to be started (no vbk, vib etc.). Thus, we would need to use some other method. However, as we see in the UI, no data on backup size is available for NAS backups (unlike for machines backups), so there is not much we can do through Powershell also. The only counter we see is Original Size, which we can get with the script below:

Code: Select all

$backups = Get-VBRNASBackup
foreach ($backup in $backups) {
    $nasPoints = [Veeam.Backup.Core.CNASBackupPoint]::GetBackupPoints($backup.Id)
    $nasPoints | select Id, NasBackupId, IsConsistent, @{n='ProtectedSize';e={$_.Info.ProtectedSize}}
}
Best regards,
Oleg
stsc_srzc
Influencer
Posts: 23
Liked: 2 times
Joined: Feb 21, 2013 11:53 am
Contact:

Re: Get occupancy of a NAS/SMB share

Post by stsc_srzc »

Hello Oleg,
thank you for your reply. I'll see if the original size will help me.

I checked the output of the script and there is an attribute "NasBackupId", is this the ID of the backup object (i. e. the specific share)?
If so, is there a way to get the name of the backup object by using the ID?

My goal is to get the occupancy per specific object rather than the whole job.
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get occupancy of a NAS/SMB share

Post by oleg.feoktistov »

Hi,

No, NasBackupId is the id of root backup for this job. Occupancy per share in a root backup is also not available.

Best regards,
Oleg
stsc_srzc
Influencer
Posts: 23
Liked: 2 times
Joined: Feb 21, 2013 11:53 am
Contact:

Re: Get occupancy of a NAS/SMB share

Post by stsc_srzc »

Hi again,
I came across another problem while inspecting the occupancy for Scale-Out Repositories.
It seems they don't provide a file path in their FilePath attribute, only the file name.

My (minimalistic) script looks like this now:

Code: Select all

# get all backups
$backups = Get-VBRBackup
    
foreach ($backup in $backups) {
    Write-Host " start backup:" $backup.Name
    if ($backup) {
        # get all objects (e. g. VMs, machines) and the stored files
        $objects = $backup.GetObjects()
        $allStorages = $backup.GetAllStorages()

        Write-Host "  objects: "$objects.Count", storages: "$allStorages.Count 
        foreach ($storage in $allStorages) {
            Write-Host "   path: " $storage.FilePath
        }
        # at this point I need the full path of the stored files for some matching the object name with the directory names
    }

    Write-Host " done backup: "$backup.Name
}
It yields this output:

Code: Select all

PS C:\Users\Administrator\Desktop\Powershell-Scripts\20220530> .\test2.ps1
 start backup: Agent Backup Policy Test - server01
  objects:  1 , storages:  8
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-05T111511.vib
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-08T111511.vib
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-09T111511.vib
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-07T111511.vib
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-03T113314.vbk
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-10T111512.vib
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-04T111714_19F7.vbk
   path:  E:\Repository1\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server01\Agent Back2022-06-06T111512.vib
 done backup:  Agent Backup Policy Test - server01
 start backup: Agent Backup Policy Test - server02
  objects:  1 , storages:  1
   path:  Agent Back2022-06-10T140550.vbk
 done backup:  Agent Backup Policy Test - server02
The actual path of server02's backup is "E:\RepositoryScale-Out\VeeamAgentUserbc504d56-14bd-aaac-15ce-000f009ed2a7\Agent_Backup_Policy_Test_-_server02\Agent Back2022-06-10T140550.vbk", but this is not visible for scale-out repositories. Is there another way to get this information for my backup object?
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get occupancy of a NAS/SMB share

Post by oleg.feoktistov »

Hi,

For SOBR it gets a bit tricky as you need to construct path for every extent separately. Please have a look at the script in this post.

Thanks,
Oleg
stsc_srzc
Influencer
Posts: 23
Liked: 2 times
Joined: Feb 21, 2013 11:53 am
Contact:

Re: Get occupancy of a NAS/SMB share

Post by stsc_srzc »

Hi, thank you for the quick reply. I'll check the other post.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests