PowerShell script exchange
Post Reply
Sindhuja
Influencer
Posts: 21
Liked: never
Joined: Jan 22, 2018 11:01 pm
Full Name: Sindhuja Balasubramanian
Contact:

How to get host information for a backup file?

Post by Sindhuja »

Hello All,

For our backup reporting, we are trying to link the backup files to their host/server location.

The following logic is used to get the server/host information.

Code: Select all

# Sample code
$backup = Get-VBRBackup -Name "Backup Job Name"
$backupStorages = $backup.GetAllStorages()
foreach ( $s in $backupStorages)
{
# Get the host id for the backup file, and look out for the server
Get-VBRServer | ? {$_.Id -eq $s[0].HostId} 
}
This logic works for jobs that use "Backup Repository" as target destination.

However, for backup jobs that use "Scale-Out" Repository, the "HostId" returned is same as the Veeam Backup Server.
Is this expected ? I was expecting the "HostId" to point to one of the Extents (of Scale-Out Repository).

Any other API to get the Host information (like Host name, Unique Id,etc) where the backup file is stored (in case of backup repository and scale-out repository)?

Any help is appreciated!

Regards,
Sindhuja
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: How to get host information for a backup file?

Post by tdewin »

I actually found a unsupported way some time ago:
https://forums.veeam.com/powershell-f26 ... ml#p279960

You can use the FindExtentRepo call on a sobr repository together with the storage id and instance of [Veeam.Backup.Core.CStorageToExtentAssociationService]::new() (as shown in that example)

Btw, whenever you want to filter out something in a for loop, it is always good to cache the list outside the for loop. Instead of this

Code: Select all

foreach ( $s in $backupStorages)
{
Get-VBRServer | ? {$_.Id -eq $s[0].HostId} 
}
you cache the servers

Code: Select all

$servers = Get-VBRServer
foreach ( $s in $backupStorages)
{
$servers | ? {$_.Id -eq $s[0].HostId} 
}
In some case this kind of small changes can dramatically speed up your code
Sindhuja
Influencer
Posts: 21
Liked: never
Joined: Jan 22, 2018 11:01 pm
Full Name: Sindhuja Balasubramanian
Contact:

Re: How to get host information for a backup file?

Post by Sindhuja »

That was useful, Timothy!
As I understand, the "HostId" in backup storage does not point to the "Repository" Host Id (in either "Backup Repository" or "Scale-out").
In our lab setup, coincidently we have one of the "Backup repository" set up in the "Veeam Backup Server" itself.
Due to this, I had assumed the "HostId" of backup storage would point to the actual Host.

"whenever you want to filter out something in a for loop, it is always good to cache the list outside the for loop."
Yes, in the actual script, we do cache "Get-VBRServer" :)

So, here is the final logic, I have comeup with

In case of a Scale-Out Backup Repository,

Code: Select all

$b = Get-VBRBackup -Name "Backup Job - scaleout"
$repo = $.GetRepository()
$bstg = $b.GetAllStorages()
$svc = [Veeam.Backup.Core.CStorageToExtentAssociationService]::new()
$servers = Get-VBRServer
foreach ( $s in $bstg )
{
     $ext = $repo.FindExtentRepo($s.Id,$svc)
     # Get the server or host
     $servers | ? {$_.Id -eq $ext.HostId}
}

In case of a Backup Repository (not a CIFS)

Code: Select all

$b = Get-VBRBackup -Name "Backup Job - backup repo"
$repo = $.GetRepository()
$bstg = $b.GetAllStorages()
$servers = Get-VBRServer
foreach ( $s in $bstg )
{
     # Get the server or host
     $servers | ? {$_.Id -eq $repo.HostId}
}
However, for a CIFS type of Backup Repository, I cannot find the host. Is there a way?

Regards,
Sindhuja
Sindhuja
Influencer
Posts: 21
Liked: never
Joined: Jan 22, 2018 11:01 pm
Full Name: Sindhuja Balasubramanian
Contact:

Re: How to get host information for a backup file?

Post by Sindhuja »

Ignore my typos in the script above :)
Please review the logic below...

Code: Select all

$servers = Get-VBRServer
$b = Get-VBRBackup -Name "Backup Job Name"
$repo = $b.GetRepository()
if($repo.TypeDisplay -eq 'Scale-out')  # Is there a better way?
{
    # In case of a Scale-Out Repository
    $bstorages = $b.GetAllStorages()
    $svc = [Veeam.Backup.Core.CStorageToExtentAssociationService]::new()    
    foreach ( $s in $bstorages )
    {
         $ext = $repo.FindExtentRepo($s.Id,$svc)
         # Get the server or host
         $repoServer = $servers | ? {$_.Id -eq $ext.HostId}
         Write-Host $s.FilePath, $repoServer.Name
    }
}
else
{
    # In case of a Backup Repository
    # Get the server or host
    $repoServer = $servers | ? {$_.Id -eq $repo.HostId}
    
    Write-Host $repoServer.Name
}
However, as mentioned in the earlier post for a CIFS, I see HostId as '00000000-0000-0000-0000-000000000000'
Sindhuja
Influencer
Posts: 21
Liked: never
Joined: Jan 22, 2018 11:01 pm
Full Name: Sindhuja Balasubramanian
Contact:

Re: How to get host information for a backup file?

Post by Sindhuja »

Can anyone confirm my understanding above?
Thanks in advance
Sindhuja
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests