PowerShell script exchange
Post Reply
can
Novice
Posts: 9
Liked: 1 time
Joined: Apr 25, 2024 8:13 am
Full Name: can bilgiç
Contact:

How do I guest file restore with powershell script

Post by can »

Hello, I want to do guest file restore using powershell script, but I could not find a solution in the structure I wanted in the documentation. First of all, my first problem is how do I get the restore point I want between the restore points in the powershel script, for example, I have taken 6 backups and I want to use the 4th one, how do I provide it in a dynamic structure that the user can choose?
My second problem is how can I owerwrite on it by selecting only the file path I want in the restore point.
david.domask
Veeam Software
Posts: 1425
Liked: 365 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How do I guest file restore with powershell script

Post by david.domask »

Hi can,

For restore points, start with Get-VBRRestorePoint.

Usually it's best to first get the relevant backup with Get-VBRBackup and then pass the CBackup object to Get-VBRRestorePoint on the -Backup parameter.

The RestorePolicy flag on Start-VBRWindowsGuestItemRestore will control how Veeam handles if the same file exists at the target directory. (For Linxu workloads, this parameter is called Overwrite)

As for presenting choices to the user, you will need to build out your own menu system within the script (maybe work with Out-GridView), but if your goal is to provide a way for users to perform their own recoveries without having full access to the Veeam Backup and Replication Console, consider Enterprise Manager and its Role Based Access Controls -- for giving restore capabilities to end-users, this is probably the simpler options.
David Domask | Product Management: Principal Analyst
can
Novice
Posts: 9
Liked: 1 time
Joined: Apr 25, 2024 8:13 am
Full Name: can bilgiç
Contact:

Re: How do I guest file restore with powershell script

Post by can »

hi david
I tried to use the methods you said before, I will present an example structure for the process I want to do to explain my problem, in this structure, I am sharing with you the error I got halfway through the process when I tried to use the VBRLinuxGuestItemRestore method on powershel for the linux agent.

PS C:\Users\Administrator>
$backup = Get-VBRBackup -Name "CanTestBackup"

$restorepoint = Get-VBRRestorePoint -Backup $backup

$server = Get-VBRServer -Name "test"

$session = Start-VBRLinuxFileRestore -RestorePoint $restorepoint -MountServer $server

Start-VBRLinuxFileRestore : Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Core.COib' required by parameter 'RestorePoint'. Specified method is not supported.
At line:8 char:52
+ ... ssion = Start-VBRLinuxFileRestore -RestorePoint $restorepoint -MountS ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-VBRLinuxFileRestore], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Veeam.Backup.PowerShell.Cmdlets.StartVBRLinuxFileRestore


I encountered an error as you have seen, and when I pull the restore points, I get multiple restore points because there are 2 different hosts in my current backupjob, and how can I understand which of these restore points to choose, for example, I want to choose host number 2 instead of host number 1, and I only want the operation to take place on my host number 2, does veeam have its own structure to understand this? Also, while doing this operation on veeam, we can specify which path to choose in the incoming interface, how can we do this on powershel, as far as I have examined, I have not encountered such an argument, so I do not know if this is possible or not.

veeam document I took as an example:
https://helpcenter.veeam.com/docs/backu ... t-computer
david.domask
Veeam Software
Posts: 1425
Liked: 365 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How do I guest file restore with powershell script

Post by david.domask »

Hi can,

Thanks for the description, and in fact Powershell is telling you the issue here:
Start-VBRLinuxFileRestore : Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Core.COib' required by parameter 'RestorePoint'. Specified method is not supported.
At line:8 char:52
+ ... ssion = Start-VBRLinuxFileRestore -RestorePoint $restorepoint -MountS ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-VBRLinuxFileRestore], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Veeam.Backup.PowerShell.Cmdlets.StartVBRLinuxFileRestore
$restorepoint = Get-VBRRestorePoint -Backup $backup

Print $restorepoint variable to your shell and you will see that it's not just one Restore Point returned, but an array. So you will need to likely sort your $restorepoint object by CreationTime (I usually include the -Descending flag) and then call the desired restore point from the array. For example:

Code: Select all

$backups = Get-VBRBackup -Name 'some backup'
$rps = Get-VBRRestorePoint -Backup $backups | Sort-Object -Property CreationTime -Descending #now the first item in the array [0] is the most recent restore point
$server = Get-VBRServer -Name "some server"
$session = Start-VBRLinuxFileRestore -RestorePoint $restorepoint[0] -MountServer $server
Try playing with that a bit and you'll see what I mean.
David Domask | Product Management: Principal Analyst
can
Novice
Posts: 9
Liked: 1 time
Joined: Apr 25, 2024 8:13 am
Full Name: can bilgiç
Contact:

Re: How do I guest file restore with powershell script

Post by can »

Hi david,

I switched to a method like this by making a little difference in the method, but I encounter the following problem and I have no idea what to do about this problem:


PS C:\Users\Administrator>
$backup = Get-VBRBackup -Name "canTest"
$restorepoint = Get-VBRRestorePoint -Backup $backup | Sort-Object -Property CreationTime -Descending
$credentials = Get-VBRCredentials -Name "root"
$session = Start-VBRLinuxFileRestore -RestorePoint $restorepoint[0] -Credentials $credentials[5] -MountToOriginal
$root = Get-VBRLinuxGuestItem -LinuxFlrObject $session
Start-VBRLinuxGuestItemRestore -LinuxFlrObject $session -Item $root[0] -GuestCredentials $credentials[5] -Overwrite
Start-VBRLinuxGuestItemRestore : Cannot bind parameter 'Item'. Cannot convert the "Veeam.Backup.PowerShell.Infos.VBRFLRRootItem" value of type
"Veeam.Backup.PowerShell.Infos.VBRFLRRootItem" to type "Veeam.Backup.PowerShell.Infos.VBRFLRFsItem".
At line:7 char:63
+ ... LinuxGuestItemRestore -LinuxFlrObject $session -Item $root[0] -GuestC ...
+ ~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-VBRLinuxGuestItemRestore], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.StartVBRLinuxGuestItemRestore


I didn't see the -item parameter in powershel commands (I'm talking about commands in powershell ISE)

If I do it without giving the item parameter, for example, I enter an infinite loop:

PS C:\Users\Administrator>

$backup = Get-VBRBackup -Name "canTest"
$restorepoint = Get-VBRRestorePoint -Backup $backup | Sort-Object -Property CreationTime -Descending
$credentials = Get-VBRCredentials -Name "root"
$session = Start-VBRLinuxFileRestore -RestorePoint $restorepoint[0] -Credentials $credentials[5] -MountToOriginal
$root = Get-VBRLinuxGuestItem -LinuxFlrObject $session
Start-VBRLinuxGuestItemRestore -LinuxFlrObject $session -GuestCredentials $credentials[5] -Overwrite
cmdlet Start-VBRLinuxGuestItemRestore at command pipeline position 1
Supply values for the following parameters:
Item[0]: 1
Item[1]: 2
Item[2]: 3
Item[3]: 4
Item[4]: 5
Item[5]: 6
Item[6]: 7
Item[7]: 8
Item[8]: 9
Item[9]: 0

$root returns the following parameters -item and I don't understand what we mean by using them:

PS C:\Users\Administrator>


$backup = Get-VBRBackup -Name "canTest"
$restorepoint = Get-VBRRestorePoint -Backup $backup | Sort-Object -Property CreationTime -Descending
$credentials = Get-VBRCredentials -Name "root"
$session = Start-VBRLinuxFileRestore -RestorePoint $restorepoint[0] -Credentials $credentials[5] -MountToOriginal
Get-VBRLinuxGuestItem -LinuxFlrObject $session

Name
----
/var/log/
/



what should I do in this case or what is the most appropriate method I should do because it seems very difficult to restore a linux host via powershell scripts.
david.domask
Veeam Software
Posts: 1425
Liked: 365 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How do I guest file restore with powershell script

Post by david.domask »

Hi can,

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

I'd ask if you could check example 2 here -- you need to do another pass with Get-VBRLinuxGuestItem with the -ParentItem flag to return a ChildItem object. Try the example there with a test file and I think you'll see how it works.

Btw, some advice since you're hitting type issues, Powershell objects will have a method GetType() which will tell you the object type you're working with. Any time you see a message about incorrect type, it means you're passing the wrong type of object, and our cmdlets kindly tell you which object type it should be. Typically you can just search our Powershell User Guide for the expected type and you'll see which cmdlets interact with it. Also I advise please check the examples and see how the scripts are built, as they give pretty good examples on the basic process and what you might be missing.
David Domask | Product Management: Principal Analyst
can
Novice
Posts: 9
Liked: 1 time
Joined: Apr 25, 2024 8:13 am
Full Name: can bilgiç
Contact:

Re: How do I guest file restore with powershell script

Post by can »

Hi David,
I did in-depth research on the documentation and I reached what I wanted by slightly changing the structure I wanted to do, thank you for your help.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests