PowerShell script exchange
Post Reply
JmillerSapp
Lurker
Posts: 2
Liked: never
Joined: Mar 28, 2018 7:16 pm
Full Name: John Miller
Contact:

LinuxFlrObject question

Post by JmillerSapp »

I'm working on automating copying of our production data into our test environment using a Veeam restore point.

So far this process has worked well. I have a power-shell script that executes on the Linux machine and creates a remote ps-session to the Windows Server running VBR. That script executes the various "get-" commands to populate variables and ultimately executes Start-VBRLinuxFileRestore. Once that spins up I'm able to rsync from it without an issue. My problem comes at the next step. By the time the Linux rsync is done (takes about 3 hours) my remote ps-session has gone idle and I've lost the $LFR variable. Powershell acts like I'm still connected to the remote server, but $LFR returns null. I suspect what's happening is PS is reconnecting in the background.
I can still open the GUI and stop the LFR; however that is a manual process. I've been looking for a way to either store the LFR or get the LFR from a get-session or similar action so that I don't have to worry about the session becoming idle. This is an awesome process and if we can do this in a purely programmatic way it would be a perfect solution as we don't have to impact production to update test.

Code: Select all

Enter-PSSession -ComputerName ServerNameHere
Add-PSSnapin VeeamPSSnapin
Connect-VBRServer -Server ServerNameHere
$BackupJob = Get-VBRBackup -Name JobNameHere
$RestorePoint = (Get-VBRRestorePoint -Backup $BackupJob | Sort-Object –Property CreationTime –Descending | Select -First 1)
$server = Get-VBRServer -Name ServerNameHere
$network  = (Get-VBRViServerNetworkInfo -Server $server | Where-Object {$_.NetworkName -eq "Managment Network"})
$Cred = (Get-VBRCredentials -name root |Sort-Object -Property ChangeTimeLocal -Descending | select -First 1)
$LFR = Start-VBRLinuxFileRestore -RestorePoint $RestorePoint -IP 172.16.25.147 -NetworkMask 255.255.255.0 -Gateway 172.16.25.254 -EnableFTP -Server $server -NetworkInfo $network -Credentials $Cred
./rsyncjob.sh
Stop-VBRLinuxFileRestore -LinuxFlrObject $LFR
veremin
Product Manager
Posts: 20283
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: LinuxFlrObject question

Post by veremin »

What if you install a console on a machine on which you execute PowerShell script and establish connection to backup server directly from it ? In this case, script will rely on Connect-VBRServer cmdlet, instead of remote PS session; might make difference. Thanks.
JmillerSapp
Lurker
Posts: 2
Liked: never
Joined: Mar 28, 2018 7:16 pm
Full Name: John Miller
Contact:

Re: LinuxFlrObject question

Post by JmillerSapp »

I've reversed my process. I'm running everything from the VRB server and SSHing into my Linux environment. I've only ran it once so far, but I think this way works. Not the SSH login is happening via keys - there are no passwords.

Code: Select all

Add-PSSnapin VeeamPSSnapin
Connect-VBRServer -Server ServerNameHere
$BackupJob = Get-VBRBackup -Name JobNameHere
$RestorePoint = (Get-VBRRestorePoint -Backup $BackupJob | Sort-Object –Property CreationTime –Descending | Select -First 1)
$server = Get-VBRServer -Name ServerNameHeret
$network  = (Get-VBRViServerNetworkInfo -Server $server | Where-Object {$_.NetworkName -eq "Managment Network"})
$Cred = (Get-VBRCredentials -name root |Sort-Object -Property ChangeTimeLocal -Descending | select -First 1)
$LFR = Start-VBRLinuxFileRestore -RestorePoint $RestorePoint -IP 172.16.25.147 -NetworkMask 255.255.255.0 -Gateway 172.16.25.254 -EnableFTP -Server $server -NetworkInfo $network -Credentials $Cred
ssh root@172.16.20.76 /NAS/scripts/nightlySync.sh
Stop-VBRLinuxFileRestore -LinuxFlrObject $LFR
veremin
Product Manager
Posts: 20283
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: LinuxFlrObject question

Post by veremin »

Great, let's see how it goes and come up with some additional workaround, if necessary. Thanks.
djustins
Novice
Posts: 6
Liked: never
Joined: May 31, 2019 1:45 pm
Full Name: Justin Davis
Contact:

Re: LinuxFlrObject question

Post by djustins »

I am doing something similar to the OP, except I MUST handle control via the linux server. I've used multiple python remote libraries and none of them are successfully maintaining the LinuxFlrObject across invokes.

I've attempted storing the object as export-clixml, but get the error:
Cannot convert the "Veeam.Backup.PowerShell.Infos.VBRLinuxFlrObject" value of type "Deserialized.Veeam.Backup.PowerShell.Infos.VBRLinuxFlrObject" to type
"Veeam.Backup.PowerShell.Infos.VBRLinuxFlrObject"

There hasto be a way to stop the Linux FLR with an API outside of the PS session from which it was invoked?
djustins
Novice
Posts: 6
Liked: never
Joined: May 31, 2019 1:45 pm
Full Name: Justin Davis
Contact:

Re: LinuxFlrObject question

Post by djustins »

Annoying, but I've found my solution. I thought we were beyond temp control files, but i guess not. Here's what you do if you're in this scenario.

1. Write a PS script that has the logic to gather your restore point and necessary info to initiate the LinuxFLR. The last step of this PS script starts the FLR session and then creates a control file and loops while the control file exists:

Code: Select all

if($Session.IsSessionSuccessfull){
        $Res = New-Item "D:\VeeamWinRM\RestoreTemp\$($Session.RestoreSession.uid)_FLRrestore.tmp"
        while (Test-Path $Res){
            Write-PSFMessage -Level Debug -Message "Control File still exists, continuing restore session"
            Start-Sleep 5
        }
        Write-PSFMessage -Level Debug -Message "Control File removed, stopping session."
        Stop-VBRLinuxFileRestore -LinuxFlrObject $Session
    }
2. Using a python library to call PS remotely (pypsrp), run something like the following. It creates a scheduled task within the task scheduler and passes the parameters to your PS script. Run this first:

Code: Select all

StartScript = '''$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File VMRestoreScript.ps1 -SrcHst {SrcHst} -sid {SID}"
$Settings = New-ScheduledTaskSettingsSet
$Task = New-ScheduledTask -Action $Action -Settings $Settings
Register-ScheduledTask -TaskName FLRrestore -InputObject $Task -User "ServiceAccountUsername" -Password "ServiceAccountPassword"
Start-ScheduledTask -TaskName FLRrestore'''.format(SrcHst=SrcHst,SID=SID)
3. The next python call is a while loop to watch for the session to start. If you don't include this, most likely the rest of your script will run while the session is starting:

Code: Select all

    output, streams, had_errors= client.execute_ps('While(-not (Test-Path "D:\VeeamWinRM\RestoreTemp\*_FLRrestore.tmp")){sleep 5}')
4. Run your restore target logic and sftp the files/folders off (pysftp)

5. Kill the restore session by removing the control file:

Code: Select all

    output, streams, had_errors= client.execute_ps('rm -force D:\VeeamWinRM\RestoreTemp\*_FLRrestore.tmp')
6. Unregister (deletes) the scheduled task with task scheduler:

Code: Select all

    output, streams, had_errors= client.execute_ps('Unregister-ScheduledTask -TaskName FLRrestore -Confirm:$false')
7. Congratulate yourself for writing a Veeam restore client for Linux, although it's clunky, which should've already existed -- and prepare yourself for a total re-write when your organization finally feels comfortable to upgrade to v11.
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: LinuxFlrObject question

Post by oleg.feoktistov »

Hi Justin,
There has to be a way to stop the Linux FLR with an API outside of the PS session from which it was invoked?
No, there isn't as we don't have neither a cmdlet to get LinuxFLRObject, nor any relevant internal class, which would offer a Get method for that.

We might as well independently obtain a CRestoreSession object for Linux FLR session , which is a LinuxFLRObject's child and call AbortSession() on its instance. It does force session stop, but it is then terminated with 'Failed' status. Not quite the way it should work.
I also tried to pass a saved LinuxFLRObject between remoting sessions in Powershell 7, but it is not serialized back correctly then.

Looks like the workaround with python library you found, unfortunately, is the most viable in this case.

Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests