PowerShell script exchange
Post Reply
tremblay@ivaco.com
Novice
Posts: 6
Liked: never
Joined: Feb 03, 2022 8:22 pm
Full Name: Syltrem
Contact:

Get-VBRBackupFile

Post by tremblay@ivaco.com »

Hi

This cmdlet returns the file NAME that contains a specific backup's data, but it does not show the PATH to that file.

Is there any way to find the path ?

$backup = Get-VBRBackup -Name "MyBackup"
$backup | select-object name, RepositoryId

The name does not include the path, and although I could possibly inquire about the repository, it contains many extents and the file could be in any one, so that wouldn't help much.

Thanks for any hint
chris.arceneaux
VeeaMVP
Posts: 668
Liked: 359 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Get-VBRBackupFile

Post by chris.arceneaux »

Welcome to the Veeam forums!

Thanks for the feedback. Am I correct that you're looking for the full file path of the file? If so, the below code will point you in the right direction.

Code: Select all

# Retrieve Job
$job = Get-VBRJob -Name "Job Name"

# Find backup related to Job
$backup = Get-VBRBackup | Where-Object {$_.JobId -eq $job.Id}

# Retrieve backup storage
$storages = $backup.GetAllChildrenStorages()

# List filepath and server of a single storage
# Filepath
$storages[0].FilePath.ToString()
# Server name
$server = Get-VBRServer | Where-Object {$_.Id -eq $storages[0].HostId}
$server.Name
Image
tremblay@ivaco.com
Novice
Posts: 6
Liked: never
Joined: Feb 03, 2022 8:22 pm
Full Name: Syltrem
Contact:

Re: Get-VBRBackupFile

Post by tremblay@ivaco.com »

Hi Chris

Thanks for your reply.

>>> Am I correct that you're looking for the full file path of the file?
Yes indeed

Any way I look at it, mine does not show the path. Pretty strange.

Maybe a problem with version 10 ? Not yet on 11...

PS C:\Users\Administrator.ZZZCO-DOM> (Get-PSSnapin VeeamPSSnapin).Version

Major Minor Build Revision
----- ----- ----- --------
10 0 0 0



PS C:\Users\Administrator.ZZZCO-DOM> $storages = $backup.GetAllChildrenStorages()
PS C:\Users\Administrator.ZZZCO-DOM> $storages[0].FilePath.ToString()
ZZZ Servers - BMR - ZZZHV02D2022-01-11T125834_CB88.vib
PS C:\Users\Administrator.ZZZCO-DOM> $storages[1].FilePath.ToString()
ZZZ Servers - BMR - ZZZHV02D2022-01-25T120051_10CC.vib
PS C:\Users\Administrator.ZZZCO-DOM> $storages[7].FilePath.ToString()
ZZZ Servers - BMR - ZZZHV02D2022-02-03T120044_43E3.vbk


also

S C:\Users\Administrator.ZZZCO-DOM> $storages | select-object filepath

ilePath
-------
ZZZ Servers - BMR - ZZZHV02D2022-01-11T125834_CB88.vib
ZZZ Servers - BMR - ZZZHV02D2022-01-25T120051_10CC.vib
ZZZ Servers - BMR - ZZZHV02D2022-01-27T131221_C89A.vbk
ZZZ Servers - BMR - ZZZHV02D2022-01-13T122536_DEE7.vbk
ZZZ Servers - BMR - ZZZHV02D2022-02-01T131238_642E.vib
ZZZ Servers - BMR - ZZZHV02D2022-01-06T125501_3ED1.vbk
ZZZ Servers - BMR - ZZZHV02D2022-01-18T131059_B384.vib
ZZZ Servers - BMR - ZZZHV02D2022-02-03T120044_43E3.vbk
ZZZ Servers - BMR - ZZZHV02D2022-01-20T120046_921D.vbk

and

PS C:\Users\Administrator.ZZZCO-DOM> $files = Get-VBRBackupFile -Backup $backup
PS C:\Users\Administrator.ZZZCO-DOM> $files

Path Id
---- --
ZZZ Servers - BMR - ZZZHV02D2022-01-11T125834_CB88.vib f4f8adcc-ae11-4a7d-8a07-17b0a593469c
ZZZ Servers - BMR - ZZZHV02D2022-01-25T120051_10CC.vib 0446e0ef-db42-4a7d-9fd2-476c70500a06
ZZZ Servers - BMR - ZZZHV02D2022-01-27T131221_C89A.vbk 616290ac-1ade-4f94-9583-4ecddb864853
ZZZ Servers - BMR - ZZZHV02D2022-01-13T122536_DEE7.vbk a52bd3f1-6973-426f-bddc-7b3fdea3c929
ZZZ Servers - BMR - ZZZHV02D2022-02-01T131238_642E.vib 27073adb-97e2-40a6-ae56-810edddd4935
ZZZ Servers - BMR - ZZZHV02D2022-01-06T125501_3ED1.vbk 6b6be311-9d3c-45b4-ab9e-8e1b37929a21
ZZZ Servers - BMR - ZZZHV02D2022-01-18T131059_B384.vib 526c4775-fef7-4bbf-838e-ca4380c451a3
ZZZ Servers - BMR - ZZZHV02D2022-02-03T120044_43E3.vbk 2abd2b24-bc87-4357-abf6-da2d4a3de83c
ZZZ Servers - BMR - ZZZHV02D2022-01-20T120046_921D.vbk 65c19105-7603-483a-8173-e0b9d81a03a1
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRBackupFile

Post by david.domask » 1 person likes this post

Hi Tremblay,

Are these backups on a Scale Out Repository by chance? (SOBR)

SOBR uses a relative path for tracking the files so you need to do some construction of the path from the Repository Path, the Job Name, and the backup file name.

The following was written for another script purpose but should help in v11. Pass it a Backup Object fetched with Get-VBRRBackup and it should work. (Borrows a bit from Tim's code here, but updated for v10/v11 as there were some changes): powershell-f26/get-all-used-backup-repo ... ml#p279960)

Code: Select all

function Get-StoragesPathsAndBlocksizeFromBackup-v11 {
	param(
		[Parameter(Mandatory=$true, Position=0)]
		[Object[]]$Backup
	)
	$Storages = $Backup[0].GetallChildrenStorages() | Sort-Object -Property PartialPath, CreationTime -Descending
	$Repository = $Backup.FindRepository()[0]
	$StoragePathsandBlocksize  = @()
	if($Repository.Type -eq "ExtendableRepository"){
		foreach($Storage in $Storages){
			$Extent = $Repository.FindRepositoryForExistingStorage($Storage.Id)
			if($Backup.JobID -eq '00000000-0000-0000-0000-000000000000'){
				$JobName = $Backup.GetMetaFilePath().Elements[0]
			}Else{
				$jobName = $Backup.FindJob().Name
			}
			$StoragePathsandBlocksize += New-Object -TypeName psobject -Property @{Extent=$Extent.Name;Path=$($Extent.Path.ToString(),$JobName.ToString(),$Storage.filepath -join "\");BlockSize=$Storage.BlockAlignmentSize;CreationTime=$Storage.CreationTime}
			}
	} else {
		$StoragePathsandBlocksize += $Storages | Sort-Object -Property PartialPath, CreationTime -Descending | Select-Object -Property PartialPath,BlockAlignmentSize
	}
	return $StoragePathsandBlocksize
}
David Domask | Product Management: Principal Analyst
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRBackupFile

Post by david.domask » 2 people like this post

Oh, small whoops as I realize you wrote you're on v10; one of the methods was different there. Use the following if you're on v10:

v10 Version

Code: Select all

function Get-StoragesPathsAndBlocksizeFromBackup-v10 {
	param(
		[Parameter(Mandatory=$true, Position=0)]
		[Object[]]$Backup
	)
	if($Backup.JobType -eq 'EpAgentBackup' -or $Backup.Jobtype -eq 'SimpleBackupCopyPolicy'){
		$Storages = $Backup[0].GetallChildrenStorages() | Sort-Object -Property PartialPath, CreationTime -Descending
	} else {
		$Storages = $Backup[0].GetAllStorages() | Sort-Object -Property PartialPath, CreationTime -Descending
	}
	$Repository = $Backup.FindRepository()[0]
	$StoragePathsandBlocksize  = @()
	if($Repository.Type -eq "ExtendableRepository"){
		foreach($Storage in $Storages){
			$Extent = $Repository.FindExtentRepo($Storage.Id)
			$job = $Backup.FindJob()
			$StoragePathsandBlocksize += New-Object -TypeName psobject -Property @{Extent=$Extent.Name;Path=$($Extent.Path.ToString(),$job.Name.ToString(),$Storage.filepath -join "\");BlockSize=$Storage.BlockAlignmentSize;CreationTime=$Storage.CreationTime}
			}
	} else {
		$StoragePathsandBlocksize += $Storages | Sort-Object -Property PartialPath, CreationTime -Descending | Select-Object -Property PartialPath,BlockAlignmentSize
	}
	return $StoragePathsandBlocksize
}
David Domask | Product Management: Principal Analyst
tremblay@ivaco.com
Novice
Posts: 6
Liked: never
Joined: Feb 03, 2022 8:22 pm
Full Name: Syltrem
Contact:

Re: Get-VBRBackupFile

Post by tremblay@ivaco.com »

Thanks for sharing David, exactly what I needed and really not something easy for me to devise ! I'm glad you have it for both V10 and V11, too.
Have a great weekend !
tremblay@ivaco.com
Novice
Posts: 6
Liked: never
Joined: Feb 03, 2022 8:22 pm
Full Name: Syltrem
Contact:

Re: Get-VBRBackupFile

Post by tremblay@ivaco.com »

Hi

Although this is working fine to retrieve the info about the files, how can I add the required value to $StoragePathsandBlocksize to use with :

Start-VBROffloadBackupFile -BackupFile ??????? -ThisBackupAndIncrements

The $files.path variable is not suitable for this and I tried different things to no avail...

This is how I select the files I'd like to offload :
$files = Get-StoragesPathsAndBlocksizeFromBackup-v10($backups) `
| Where-Object {[System.IO.Path]::GetExtension($_.Path) -like ".vbk" -and $_.CreationTime -lt (get-date).AddDays(-22)}

Error message :
Cannot convert the "C:\my path\file.vbk" value of type "System.String" to type "Veeam.Backup.PowerShell.Infos.VBRBackupFile".


Also, I noted that the Path variable contains the string "System.Object[]" for some reason
Path : V:\Veeam Backups\System.Object[]\SIQ Servers - BMR - SIQSV02D2022-01-20T200735_9315.vbk

Your help is very much appreciated.
Thank you
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRBackupFile

Post by david.domask »

Hi Tremblay!

Well, in fact it's telling you the issue :) What you originally asked for was a list of File Names, which is what my code gives you, but you need a specific CStorage object.

https://helpcenter.veeam.com/docs/backu ... ml?ver=110

This cmdlet needs a specific object for the -BackupFile parameter, and you might check the example:

Code: Select all

$backup = Get-VBRBackup -Name "Exchange backups"
$files = Get-VBRBackupFile -Backup $backup
Start-VBROffloadBackupFile -BackupFile $files -ThisBackup
So you need something like this:

Code: Select all

PS C:\Users\Administrator> $job

Job Name                  Type            State      Last Result  Description
--------                  ----            -----      -----------  -----------
classic-bcj               VMware Backu... Idle       None         #corebackup


PS C:\Users\Administrator> $backup = Get-VBRBackup -name $job.name
PS C:\Users\Administrator> $backup

Job Name                  Type            Creation Time               VM count
--------                  ----            -------------               --------
classic-bcj               VMware Backu... 2/17/2021 13:15:51                 3


PS C:\Users\Administrator> Get-VBRBackupFile -Backup $backup

Path                                                    IsAvailable Id
----                                                    ----------- --
DDom-TinyVM-vrdm.vm-23625D2022-02-03T060000_8389.vib           True 1fabee86-5f86-4b2f-bd51-010fb53e66b5
DDom-TinyVM-vrdm.vm-23625D2022-02-08T060000_E5EB.vib           True 92f2a9f7-8504-4086-ac6a-0b2d5ad4268e
DDom-TinyVM-vrdm.vm-23625D2022-01-12T060000_CE19.vib           True b6079ea1-9ac8-4066-9384-2c1ab4a2f902
DDom-TinyVM-vrdm.vm-23625D2022-02-12T060000_D815.vib           True f701a25b-e44f-4fc9-ade3-3083280b28bc
DDom-TinyVM-vrdm.vm-23625D2022-02-07T060000_57AB.vib           True 4ef2fd28-93f3-498e-ba53-33531fa64f32
DDom-TinyVM-vrdm.vm-23625D2022-02-02T060000_4173.vib           True 523a0d88-a90b-480c-a5af-47f2a80f4008
DDom-TinyVM-vrdm.vm-23625D2021-12-13T060000_3867.vib           True 56975b6c-0c49-4776-b3ce-506d28618d82
DDom-TinyVM-vrdm.vm-23625D2022-02-14T060000_E833.vib           True 97309927-2259-49a5-94c9-51ddeac391ee
...
This will return an array of the backup files that you can pass.

So your issue was just a slight misunderstanding on what the cmdlet you were working with ;)

Let me know if this helps!
David Domask | Product Management: Principal Analyst
tremblay@ivaco.com
Novice
Posts: 6
Liked: never
Joined: Feb 03, 2022 8:22 pm
Full Name: Syltrem
Contact:

Re: Get-VBRBackupFile

Post by tremblay@ivaco.com »

Hi

I understand what you're saying but I was looking for a way to add the value returned by VBRBackupFile into the $StoragePathsandBlocksize returned by the Get-StoragesPathsAndBlocksizeFromBackup-v10 function.
Thanks
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRBackupFile

Post by david.domask »

Er, well I think maybe there's a misunderstanding.

Like I said, the code I provided provides file paths; SOBR is tricky because it has to build the path.

But the SOBR offload cmdlet doesn't want that; it wants a CStorage object, which is what Get-VBRBackupFile returns.

A CStorage object carries information from the database about a Storage, which in Veeam terminology means backup file. The Veeam you're trying to use doesn't need to know the full path, it just needs to know which storage you want, and Veeam handles the rest behind the scenes. The ID is more important than the path. So in this case, you want the output of Get-VBRRBackupFile "as-is", and Veeam knows what to do.

So maybe you can explain why you want the file path when the cmdlet doesn't want or need it; the cmdlet is looking for the CStorage object, and from that, Veeam knows everything about a given storage.

Maybe you can elaborate more on what specifically you're trying to do -- maybe there are some backups that aren't offloading that you want to be offloaded? If so we need more details on those backups (type of backup, where they're stored, etc).

But if the goal is just to manually manage the offloading, then the example and the output of Get-VBRBackupFile is exactly what you want.

So maybe you can elaborate on the challenge you're currently facing, as in fact for the offload cmdlet you don't need the full path at all at any point.
David Domask | Product Management: Principal Analyst
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRBackupFile

Post by david.domask » 2 people like this post

Necro-bump, but fixed this function to work with v12 and 12.1. I've just tested on VM and Agent backups, not sure how it will play with other job types :)

Code: Select all

function Get-StoragesPathsAndBlocksizeFromBackup-v12 {
	param(
		[Parameter(Mandatory=$true, Position=0)]
		[Object[]]$Backup
	)
	$Storages = $Backup[0].GetallChildrenStorages() | Sort-Object -Property PartialPath, CreationTime -Descending
	$Repository = $Backup.FindRepository()[0]
	$StoragePathsandBlocksize  = @()
	if($Repository.Type -eq "ExtendableRepository"){
		foreach($Storage in $Storages){
			$Extent = $Repository.GetRepositoryForExistingStorage($Storage.Id)
			if($Backup.JobID -eq '00000000-0000-0000-0000-000000000000'){
				$JobName = $Backup.GetMetaFilePath().Elements[0]
			}Else{
				$jobName = $Backup.FindJob().Name
			}
			$StoragePathsandBlocksize += New-Object -TypeName psobject -Property @{Extent=$Extent.Name;Path=$($Extent.Path.ToString(),$JobName.ToString(),$Storage.filepath -join "\");BlockSize=$Storage.BlockAlignmentSize;CreationTime=$Storage.CreationTime}
			}
	} else {
		$StoragePathsandBlocksize += $Storages | Sort-Object -Property PartialPath, CreationTime -Descending | Select-Object -Property PartialPath,BlockAlignmentSize
	}
	return $StoragePathsandBlocksize
}

david.domask wrote: Feb 04, 2022 6:18 am

Code: Select all

function Get-StoragesPathsAndBlocksizeFromBackup-v11 {
	param(
		[Parameter(Mandatory=$true, Position=0)]
		[Object[]]$Backup
	)
	$Storages = $Backup[0].GetallChildrenStorages() | Sort-Object -Property PartialPath, CreationTime -Descending
	$Repository = $Backup.FindRepository()[0]
	$StoragePathsandBlocksize  = @()
	if($Repository.Type -eq "ExtendableRepository"){
		foreach($Storage in $Storages){
			$Extent = $Repository.FindRepositoryForExistingStorage($Storage.Id)
			if($Backup.JobID -eq '00000000-0000-0000-0000-000000000000'){
				$JobName = $Backup.GetMetaFilePath().Elements[0]
			}Else{
				$jobName = $Backup.FindJob().Name
			}
			$StoragePathsandBlocksize += New-Object -TypeName psobject -Property @{Extent=$Extent.Name;Path=$($Extent.Path.ToString(),$JobName.ToString(),$Storage.filepath -join "\");BlockSize=$Storage.BlockAlignmentSize;CreationTime=$Storage.CreationTime}
			}
	} else {
		$StoragePathsandBlocksize += $Storages | Sort-Object -Property PartialPath, CreationTime -Descending | Select-Object -Property PartialPath,BlockAlignmentSize
	}
	return $StoragePathsandBlocksize
}
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests