PowerShell script exchange
Post Reply
Filippo1975
Service Provider
Posts: 28
Liked: never
Joined: May 11, 2018 3:23 pm
Full Name: Filippo M
Contact:

Automate Disaster Recovery with veeam and ansible

Post by Filippo1975 »

Goodmorning everybody,
in these days we are working to automatate the disaster recovery plan with Ansible, and powershell. The idea is starting a new different veeam standby server, adding a new smb share as repository and starting a live mount of a backupped vm. Till now we had reached the goals and we are happy, we were able to start the vms with the command "Start-VBRInstantRecovery " with a read and write cache, and the vm is poweron... But in this moment we aren't able to attach to vm a different network as the default one, thus there are some switch with the command ""Start-VBRInstantRecovery " that should accomplish this.
So what's wrong?

here is the code:

Code: Select all

$backup = Get-VBRBackup
$restorepoint = Get-VBRRestorePoint -Backup $backup | Sort-Object –Property CreationTime –Descending | Select -First 1
$EsxServer = Get-VBRServer -Type ESXi -Name Esx01.domain.local
$pool = Find-VBRViResourcePool -Name "Recovery Resource Pool" -Server $server
$folder = Find-VBRViFolder -Name "ADR" -Server $server
$VMName = "itxxxxxx"
$store = Find-VBRViDatastore -Name "Volume001" -server $ESXServer

$SourceNetwork = Get-VBRViServerNetworkInfo -server "esxdmz25.itservice.local" | Where { $_.name -eq "tenant.xxxx.vlan1012" }
$TargetNetwork = $SourceNetwork
Start-VBRInstantRecovery -RestorePoint $restorepoint -VMName $VMName -Server $Esxserver -Datastore $store -ResourcePool $pool  -Folder $folder  -PowerUp:$true -NICsEnabled:$true -Reason "Data recovery" -RunAsync -SourceNetwork $SourceNetwork -TargetNetwork $targetNetwork -Verbose
david.domask
Veeam Software
Posts: 2603
Liked: 607 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by david.domask »

Hi Filippo1975,

Are there any errors returned during the instant recovery session in Veeam? I just tried your code and it worked without issue, so I would advise start with checking the History tab in Veeam and see if there were errors with the network mapping.

> $SourceNetwork = Get-VBRViServerNetworkInfo -server "esxdmz25.itservice.local" | Where { $_.name -eq "tenant.xxxx.vlan1012" }
> $TargetNetwork = $SourceNetwork

Just to confirm, you intended to connect the instant recovered VM to the same network as source, correct? I tested both like this and with a new network for $TargetNetwork, and no issues, so my guess is something is not working when trying to set the mapping, but cannot tell what immediately. Code should work as written.
David Domask | Product Management: Principal Analyst
Filippo1975
Service Provider
Posts: 28
Liked: never
Joined: May 11, 2018 3:23 pm
Full Name: Filippo M
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by Filippo1975 »

Hello David,
you are right.. I've found some issue on the code... and I've fixed them.. now there are no error, in the veem logs as well vcenter server, but nothing change on the livemount vm session.. the network card i connected to VMnetwork, but this is not what we woudl like to get.. anyway..can you please confirm the command I'm sending is correct? because during a livemount session started from user in the gui, there is no option to set a custom network card....
Thank you...
david.domask
Veeam Software
Posts: 2603
Liked: 607 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by david.domask »

When you say "custom network card", you're discussing networks in VMware or how do you mean? I'm just worried you're meaning something specific.

With your code above, the cmdlet Get-VBRViServerNetworkInfo will return virtual networks from VMware and you can set the network manually in Powershell as opposed to the UI.

So the code will work as expected and I was able to change the VM network just fine, but I think I'm not understanding what you're trying to accomplish correctly.
David Domask | Product Management: Principal Analyst
Filippo1975
Service Provider
Posts: 28
Liked: never
Joined: May 11, 2018 3:23 pm
Full Name: Filippo M
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by Filippo1975 »

Hello,
I mean exactly what you wrote: I've got vm1 with network card attached to network "Vm-network" and I want to change it to "DMZ-Network"
david.domask
Veeam Software
Posts: 2603
Liked: 607 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by david.domask »

Got it, then code works, so I would check the instant recovery session in the History tab like I mentioned and see if there was a warning/error, and if all else fails, open a Support case and allow Support to review the logs and understand the behavior.

Please share the case number once created, thanks!
David Domask | Product Management: Principal Analyst
Filippo1975
Service Provider
Posts: 28
Liked: never
Joined: May 11, 2018 3:23 pm
Full Name: Filippo M
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by Filippo1975 »

Hello David,
I was able to successfully change the network on the vm without open a ticket.. Anyway if a vm has multiple network adapter ?
thank you
david.domask
Veeam Software
Posts: 2603
Liked: 607 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by david.domask »

>Anyway if a vm has multiple network adapter ?

I wasn't sure on this one so tested quick with a fresh backup of a VM with multiple networks and passed an array of networks for the -TargetNetwork parameter, but regrettably it did not work, only the first network passed to -TargetNetwork gets assigned to the first network adapter.

Let's consider it a feature request, and for a workaround, consider including PowerCLI into your ansible scripting to adjust the networks after restore.
David Domask | Product Management: Principal Analyst
Filippo1975
Service Provider
Posts: 28
Liked: never
Joined: May 11, 2018 3:23 pm
Full Name: Filippo M
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by Filippo1975 »

Hi David,
today I've found a similar post on the veeam forums about the start-vbrrestorevm

post477406.html#p477406

and it seeems that this guy was able to accomplish this.. I've tried to apply on myscript and on my enviroment but it didn't work.
So I think it should be work with the Start-VBRInstantRecovery too.
Maybe it just only to understand how to pass the parameters...

I've tried to pass parameter with this format:
Start-VBRInstantRecovery -VMName $VMName ..... -SourceNetwork $SourceNetwork -TargetNetwork $targetNetwork01, $targetNetwork02

Then
$targetNetwork = @($targetnetwork01, $targetnetwork02)
Start-VBRInstantRecovery -VMName $VMName ..... -SourceNetwork $SourceNetwork -TargetNetwork $targetNetwork

Again, as wrote by you even the vm start successfully the second vmcard is still attached to Targetnetwork01
Why was that guy able to do the trick?
I do not understand but I hope with these further messages..
Thank you
david.domask
Veeam Software
Posts: 2603
Liked: 607 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by david.domask »

I will need some time to research this, it's a good find but I'm not able to reproduce it in my lab. I'll update once I have more information, though perhaps someone else is already familiar with it and can comment.
David Domask | Product Management: Principal Analyst
Filippo1975
Service Provider
Posts: 28
Liked: never
Joined: May 11, 2018 3:23 pm
Full Name: Filippo M
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by Filippo1975 »

Hello,
as requested by you, meanwhile I've opened a ticket..
here it is:

ticket number: 07673976

Thank you again for your support..
Filippo1975
Service Provider
Posts: 28
Liked: never
Joined: May 11, 2018 3:23 pm
Full Name: Filippo M
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by Filippo1975 »

Hello David, hello everybody,
I would like to share the veeam support answer to my question..

"
I've tested this cmdlet, it is possible to add more than 1 network to the restored VM.
You use arrays indeed, but you need it both for the SourceNetwork and the TargetNetwork Parameters.
These 2 Params are related and they both need to be used.
The logic is that a SourceNetwork is mapped to a TargetNetwork.
For ex (I paste here more just so that we're on the same page) :
$SourceNetwork1 = Get-VBRViServerNetworkInfo -Server $prodserver | Where-Object {$_.Name -eq "source_net1"}
$SourceNetwork2 = Get-VBRViServerNetworkInfo -Server $prodserver | Where-Object {$_.Name -eq "source_net12"}
$SourceNetwork3 = ..
$TargetNetwork1 = Get-VBRViServerNetworkInfo -Server $esxi | Where-Object {$_.Name -eq "target_net1"}
$TargetNetwork2 = Get-VBRViServerNetworkInfo -Server $esxi | Where-Object {$_.Name -eq "target_net2"}
$TargetNetwork3 = ..
$SourceNetworks = @($SourceNetwork1, $SourceNetwork2, $SourceNetwork3..)
$TargetNetworks = @($TargetNetwork1, $TargetNetwork2, $TargetNetwork3..)
Start-VBRInstantRecovery .. -SourceNetwork $SourceNetworks -TargetNetwork $TargetNetworks

So in this example, SourceNetwork1 would be mapped to TargetNetwork1, 2 to 2 etc.
The SourceNetwork info is taken from the VM .vmx file (according to the specific restore point which is being restored).
So the map is strict and needs to be defined in advance. "
david.domask
Veeam Software
Posts: 2603
Liked: 607 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Automate Disaster Recovery with veeam and ansible

Post by david.domask »

Hi Filippo,

Thank you very much for sharing the result and glad Support was able to give you the right directions.

I had testing something similar, but couldn't get it working but probably it's unrelated to the process.

Glad you got a working solution!
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests