Running a Replication Group Failover with PowerCLI

User Guides for VMware Solutions

Audience
Public
Content Type
User Guides
Source Type
Documentation

First is a break down of each of the processes that will be ran through in this workflow.

  • Setting the vCenter name variables and then connecting to both vCenter servers:

    $vc1 = "ac-vcenter-1.purecloud.com"
    $vc2 = "ac-vcenter-2.purecloud.com"
    
    Connect-VIServer -server $vc1,$vc2
  • Getting the VM/s to failover and setting them to a variable:

    $vm = get-vm -name "vVol-Rep-VM-*"
  • Setting the source replication group variable and then printing that information:

    $sourceGroup = $vm | Get-SpbmReplicationGroup -server $vc1
    $sourceGroup | format-table -autosize
  • Setting the target replication pair variable from the source replication group variable:

    $targetPair = get-spbmreplicationpair -source $sourceGroup
    $targetPair | format-table -autosize
  • Setting the replication group name from the target variable:

    $syncgroup = $targetPair.Target.Name
  • Running a sync replication group before stopping the VMs with a specific point in time name:

    Sync-SpbmReplicationGroup -ReplicationGroup $syncgroup -PointInTimeReplicaName 'Sync-Powered-On-VM'
  • Stopping the VMs that are going to be failed over:

    Stop-VM -VM $vm -Confirm:$false
  • Running another sync replication group job after the VMs have powered off:

    Sync-SpbmReplicationGroup -ReplicationGroup $syncgroup -PointInTimeReplicaName 'Sync-Powered-Off-VM'
  • Setting the target replication group variable from the target pair:

    $targetGroup = $targetPair.Target
  • Beginning the failover process by first running a prepare failover:

    Start-SpbmReplicationPrepareFailover -ReplicationGroup $sourceGroup
  • Failing over the replication group for the VMs and setting the operations to a variable:

    $testVms = Start-SpbmReplicationFailover -ReplicationGroup $targetGroup -Confirm:$false
  • In the event that multiple VMs were part of the replication group, a for-each loop will need to be ran against the $testVMs variable to register each one. This example just has a single VM that is being registered:

    new-vm -VMFilePath $testVms -ResourcePool Replicated-SNY -Server $vc2
  • Starting the VM. Please note that there is a question that is asked if the VM is copied or moved. This question must be answered:

    get-vm -name 'vVol-Rep-VM-*' -Server $vc2 | Start-VM
  • Running the reverse replication group operation to reverse the source and target status for the replication group:

    $new_source_group = Start-SpbmReplicationReverse -ReplicationGroup $targetGroup
  • Setting the new VM to a variable on the recovery vCenter server:

    $newvm = get-vm -name "vVol-Rep-VM-1" -Server $vc2
  • Resetting the storage policy for the VM and each virtual disk to the "VVol No Requirements Policy":

    $HD1 = $newvm | Get-HardDisk
    $newvm_policy_1 = $newvm, $HD1 | Get-SpbmEntityConfiguration
    Write-Host -ForegroundColor Cyan "Setting policy to VVol No Requirements for $vm"
    $newvm_policy_1 | Set-SpbmEntityConfiguration -StoragePolicy "VVol No Requirements Policy" -Server $vc2
  • Setting the variables for the replication group and storage policy that we want to use to re-protect the VM to the previous source/protected site:

    $policy_1 = Get-SpbmStoragePolicy -Server $vc2 -name "AC-2-vVol-20-min-replication-policy"
    $new_rg = $policy_1 | Get-SpbmReplicationGroup -Server $vc2 -Name "sn1-x70-c05-33:r-vVol-replication-group-1"
  • Applying the storage policy and replication group to the VMs to complete the re-protect process:

    Write-Host -ForegroundColor Cyan "Setting $vm storage policy to $policy_1 and replication group to $new_rg."
    $newvm_policy_1 | Set-SpbmEntityConfiguration -StoragePolicy $policy_1 -ReplicationGroup $new_rg
    Write-Host -ForegroundColor Green "$newvm's storage policy has been set"

Here is the workflow all in a single snippet:

01
## Setting the vCenter name variables and then connecting to both vCenter Servers ##
02
 
03
$vc1 = "ac-vcenter-1.purecloud.com"
04
$vc2 = "ac-vcenter-2.purecloud.com"
05
 
06
Connect-VIServer -server $vc1,$vc2
07
 
08
##Getting the VM/s to Failover and setting them to a Variable ##
09
 
10
$vm = get-vm -name "vVol-Rep-VM-*"
11
 
12
## Setting the Source Replication Group Variable and then Printing that information ##
13
 
14
$sourceGroup = $vm | Get-SpbmReplicationGroup -server $vc1
15
$sourceGroup | format-table -autosize
16
 
17
## Setting the Target Replication Pair Variable from the source replication group variable ##
18
 
19
$targetPair = get-spbmreplicationpair -source $sourceGroup
20
$targetPair | format-table -autosize
21
 
22
## Setting the Replication Group name from the Target variable ##
23
 
24
$syncgroup = $targetPair.Target.Name
25
 
26
## Running a Sync Replication Group before stopping the VMs with a specific Point in Time name ##
27
 
28
Sync-SpbmReplicationGroup -ReplicationGroup $syncgroup -PointInTimeReplicaName 'Sync-Powered-On-VM'
29
 
30
## Stopping the VMs that are going to be failed over ##
31
 
32
Stop-VM -VM $vm -Confirm:$false
33
 
34
## Running another sync replication group job after the VMs have powered off ##
35
 
36
Sync-SpbmReplicationGroup -ReplicationGroup $syncgroup -PointInTimeReplicaName 'Sync-Powered-Off-VM'
37
 
38
## Setting the target replication group variable from the target pair ##
39
 
40
$targetGroup = $targetPair.Target
41
 
42
## Beginning the Failover Process by first running a prepare Failover ##
43
 
44
Start-SpbmReplicationPrepareFailover -ReplicationGroup $sourceGroup
45
 
46
## Failing over the replication group for the VMs and setting the operations to a variable ##
47
 
48
$testVms = Start-SpbmReplicationFailover -ReplicationGroup $targetGroup -Confirm:$false
49
 
50
## In the event that multiple VMs were part of the replication group, a for-each loop will need to be ran against the $testVMs variable to register each one ##
51
## This example just has a single VM that is being registered ##
52
 
53
new-vm -VMFilePath $testVms -ResourcePool Replicated-SNY -Server $vc2
54
 
55
## Starting the VM. Please note that there is a question that is asked if the VM is copied or moved. This question must be answered ##
56
 
57
get-vm -name 'vVol-Rep-VM-*' -Server $vc2 | Start-VM
58
 
59
## Running the reverse replication group operation to reverse the source and target status for the Replication Group ##
60
 
61
$new_source_group = Start-SpbmReplicationReverse -ReplicationGroup $targetGroup
62
 
63
## Setting the New VM to a variable on the recovery vCenter Server
64
 
65
$newvm = get-vm -name "vVol-Rep-VM-1" -Server $vc2
66
 
67
## Resetting the storage policy for the VM and each virtual disk to the "VVol No Requirements Policy" ##
68
 
69
$HD1 = $newvm | Get-HardDisk
70
$newvm_policy_1 = $newvm, $HD1 | Get-SpbmEntityConfiguration
71
Write-Host -ForegroundColor Cyan "Setting policy to VVol No Requirements for $vm"
72
$newvm_policy_1 | Set-SpbmEntityConfiguration -StoragePolicy "VVol No Requirements Policy" -Server $vc2
73
 
74
## Setting the Variables for the replication group and storage policy that we want to use to re-protect the VM to the previous source/protected site ##
75
 
76
$policy_1 = Get-SpbmStoragePolicy -Server $vc2 -name "AC-2-vVol-20-min-replication-policy"
77
$new_rg = $policy_1 | Get-SpbmReplicationGroup -Server $vc2 -Name "sn1-x70-c05-33:r-vVol-replication-group-1"
78
 
79
## Applying the Storage Policy and Replication group to the VMs to complete the Re-protect process ##
80
 
81
Write-Host -ForegroundColor Cyan "Setting $vm storage policy to $policy_1 and replication group to $new_rg."
82
$newvm_policy_1 | Set-SpbmEntityConfiguration -StoragePolicy $policy_1 -ReplicationGroup $new_rg
83
Write-Host -ForegroundColor Green "$newvm's storage policy has been set"

Overall, the workflow is straightforward, but in order to fully re-protect the VMs after the reverse, there are some extra steps that can be missed or skipped accidentally.