PowerShell script exchange
Post Reply
Andreas Neufert
VP, Product Management
Posts: 6747
Liked: 1408 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Replica Failover/FailBack/FailbackCommit Example (remote PS)

Post by Andreas Neufert »

Hi everybody,

I had some trouble finding the right commands for Replica Failover, Failback and Failback commit, so I created the following examples.

The code is written for v7

They do:

Failover the VM and add it to the exclude list (v8 do this automatically).

Failback to original VM

Failback commit and add the VM back from Exclude list of the job.

Attention at failback commit you need to select the right restore point, otherwise you will end up with the VM placed in the "LockedIteam" Table of Veeam and you can not process the VM anymore.
The correct restore point for Failback is the first one (index 0) while for failback commit it is the second one (index 1) because at failback there is an new snapshot/restorepoint.

If you start Failback and Failback commit at same time, you can read out the restore point a single time before processing the command with index 0.


If you ended up with VM in the LockIteams table (you can not process the VM anymore at a B&R Job). You can use the following Script to delete the lock table with SQL Management Studio.
Please change DB Name accordingly.

Code: Select all

USE VeeamBackup
delete from [Backup.TrackedActions.Leases]
delete from [Backup.TrackedActions.LockItems]
delete from [Backup.TrackedActions.Locks]

Failover Code:

Code: Select all

#On the BRE/SQL Server
#enable-wsmancredssp -role server
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512

#On the Client
#winrm quickconfig
#enable-wsmancredssp -role client -delegatecomputer backup, backup.demoinfra.an.veeam.de
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512
#
#gpedit.msc
#Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Fresh Credentials with NTLM-only Server Authentication
#Enable and add SPN and FQDN of the Servers in the list,like this:
#WSMAN/Servername               (without #)
#WSMAN/servername.domain.tld    (without #)
#
#PS with Administrative rights "gpupdate /force"

write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Loading Input"

#Define an Backup Server + Credentials and connect to Server
$backupserver = "backup"
$username = "backup\demolab"
$password = convertto-securestring -string "Sumsi1!" -asplaintext -force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password
$session = New-PSSession $backupserver -authentication CredSSP -Credential $credentials

$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Connectiong to Backup Server" $backupserver "and processing commands..."

#Process commands directly at the Server.
invoke-command -session $session -scriptblock{


#Define Jobname and VM for failover
$Jobname = "testrep"
$VMName = "empty"


$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Connected to Backup Server (Timestamps are now on loacl time of backup server)"

#Load Veeam Powershell Plugin
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Loading Veeam Powershell Snapin"
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue


#Exclude VM from Job so that Job can run without error for the other VMs. v8 do this automatically, you can skipt this then.
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Exclude VM " $VMName " from Job."
$JobObject = Get-VBRJob -name $JobName
$ObjectToRemove = $JobObject | Get-VBRJobObject -name $VMName
$ObjectToRemove | Remove-VBRJobObject


#Process Failover
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Failover for VM " $VMName " in progress."
$RestorePoint = Get-VBRReplica -name $Jobname | Get-VBRRestorePoint | ? {$_.VmName -eq $VMName} | Sort-Object CreationTime -Descending | Select -Index 0
Start-VBRViReplicaFailover -RestorePoint $RestorePoint -Confirm:$False



#Close Session
}
Remove-PSSession $session
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Failover Job finished"
Failback:

Code: Select all

#On the BRE/SQL Server
#enable-wsmancredssp -role server
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512

#On the Client
#winrm quickconfig
#enable-wsmancredssp -role client -delegatecomputer backup, backup.demoinfra.an.veeam.de
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512
#
#gpedit.msc
#Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Fresh Credentials with NTLM-only Server Authentication
#Enable and add SPN and FQDN of the Servers in the list,like this:
#WSMAN/Servername               (without #)
#WSMAN/servername.domain.tld    (without #)
#
#PS with Administrative rights "gpupdate /force"

write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Loading Input"

#Define an Backup Server + Credentials and connect to Server
$backupserver = "backup"
$username = "backup\demolab"
$password = convertto-securestring -string "Sumsi1!" -asplaintext -force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password
$session = New-PSSession $backupserver -authentication CredSSP -Credential $credentials

$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Connectiong to Backup Server" $backupserver "and processing commands..."

#Process commands directly at the Server.
invoke-command -session $session -scriptblock{


#Define Jobname and VM for failback
$Jobname = "testrep"
$VMName = "empty"


$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Connected to Backup Server (Timestamps are now on loacl time of backup server)"

#Load Veeam Powershell Plugin
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Loading Veeam Powershell Snapin"
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

#Start Failback
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Failback to original VM for VM " $VMName " in progress."
$RestorePoint = Get-VBRReplica -name $Jobname | Get-VBRRestorePoint | ? {$_.VmName -eq $VMName} | Sort-Object CreationTime -Descending | Select -Index 0
Start-VBRViReplicaFailback -RestorePoint $RestorePoint -PowerOn

#Close Session
}
Remove-PSSession $session
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Failback Job finished"
Failback commit:

Code: Select all

#On the BRE/SQL Server
#enable-wsmancredssp -role server
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512

#On the Client
#winrm quickconfig
#enable-wsmancredssp -role client -delegatecomputer backup, backup.demoinfra.an.veeam.de
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512
#
#gpedit.msc
#Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Fresh Credentials with NTLM-only Server Authentication
#Enable and add SPN and FQDN of the Servers in the list,like this:
#WSMAN/Servername               (without #)
#WSMAN/servername.domain.tld    (without #)
#
#PS with Administrative rights "gpupdate /force"

write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
write-host " "
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Loading Input"

#Define an Backup Server + Credentials and connect to Server
$backupserver = "backup"
$username = "backup\demolab"
$password = convertto-securestring -string "Sumsi1!" -asplaintext -force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password
$session = New-PSSession $backupserver -authentication CredSSP -Credential $credentials

$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Connectiong to Backup Server" $backupserver "and processing commands..."

#Process commands directly at the Server.
invoke-command -session $session -scriptblock{


#Define Jobname and VM for failback commit
$Jobname = "testrep"
$VMName = "empty"
$VCenter = "esxi55u1"


$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Connected to Backup Server (Timestamps are now on loacl time of backup server)"

#Load Veeam Powershell Plugin
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Loading Veeam Powershell Snapin"
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

# Delete VM from Exclude list and add the VM again
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime() 
Write-host $actualtime "Information: Delete VM " $VMName " from exclude list"
$JobObject = Get-VBRJob -name $Jobname
$ObjectToDeleteFromExlude = $JobObject.GetObjectsInJob() | ?{$_.Name -eq $VMName -and $_.Type -eq "Exclude"}
$ObjectToDeleteFromExlude.Delete()  | Out-Null      #This removes also the VM Object
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime() 
Write-host $actualtime "Information: Add VM " $VMName " to job again"
$VCenterObject  = Get-VBRServer | where {$_.Name -eq $VCenter}
$VMtoAddAgainObject = Find-VBRViEntity -Server $VCenterObject -Name $VMName
Add-VBRViJobObject -Job $JobObject -Entities $VMtoAddAgainObject

#Process Failover commit 
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Failback commit to original VM for VM " $VMName " in progress."
$RestorePoint = Get-VBRReplica -name $Jobname | Get-VBRRestorePoint | ? {$_.VmName -eq $VMName} | Sort-Object CreationTime -Descending | Select -Index 1 #ATTENTION at Failover there was a snapshot added to the VM, so the restorepoint needed for Failback commit is not Index 0, it is 1 higher.
Start-VBRViReplicaFailback -RestorePoint $RestorePoint -Complete: $True



#Close Session
}
Remove-PSSession $session
$actualtime = get-date
$actualtimeformated =$actualtime.ToUniversalTime()
Write-host $actualtime "Information: Jailback Commit Job finished"
Chuels
Lurker
Posts: 1
Liked: never
Joined: Jun 11, 2015 10:45 am
Contact:

Re: Replica Failover/FailBack/FailbackCommit Example (remote

Post by Chuels »

Hi Andreas,
we have discovered in v8, that the proxy choice is automatic for a failback and we are looking for an option to add dedicated proxy servers or a choice of proxy servers to the failback. Any option available, becaue this is not outlined in the documentation?
Cheers
Vitaliy S.
VP, Product Management
Posts: 27112
Liked: 2719 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Replica Failover/FailBack/FailbackCommit Example (remote

Post by Vitaliy S. »

Can't see it in the UI and in the documentation either. Do you see that this dedicated proxy server is not selected for some reason when you run a failback process?
Andreas Neufert
VP, Product Management
Posts: 6747
Liked: 1408 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Replica Failover/FailBack/FailbackCommit Example (remote

Post by Andreas Neufert »

We have this option in our UserInterface, but not in Powershell.
We are discussing our options to help Carsten internally at the moment.
Andreas Neufert
VP, Product Management
Posts: 6747
Liked: 1408 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Replica Failover/FailBack/FailbackCommit Example (remote

Post by Andreas Neufert »

Tom Sightler created a workaround. PM me if you need it.

@Tom ... Thank you very much!
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests