Demonstrate replication and planned failover
Applies To: Windows Server 2012 R2, Windows Server 2012
This article provides a quick view of how to set up Hyper-V Replica, enable replication for a virtual machine, and run a test and planned failovers.
In this document
Read the prerequisites and then complete these steps:
Note
This topic includes sample Windows PowerShell cmdlets that you can use to automate some of the procedures described. For more information, see Using Cmdlets.
Prerequisites
For the purposes of this demonstration you’ll need two physical servers in the same or separate geographical location. The servers should be running Windows Server 2012 or 2012 R2.
If you’re using two separate sites make sure the firewall at each site is properly configured to allow communications between the servers running Hyper-V. Hyper-V Replica includes pre-configured inbound firewall rules that can be enabled depending on the authentication mechanism chosen (HTTP or HTTPS).
You’ll need enough storage to host replicated workloads.
If you’re using separate locations, you’ll need sufficient network bandwidth between the sites.
Step 1: Enable the Hyper-V Role and create a virtual machine
To enable the Hyper-V server role and create virtual machines, see Install Hyper-V and create a virtual machine.
Step 2: Configure a Replica server
A Hyper-V host server that you configure as a Replica server can receive replicated virtual machine data from primary servers. You can configure the Replica server to accept replication from only specific primary servers, from any primary server, or from a collection of primary servers defined by FQDNs with wildcard characters.
In this example, the steps will enable the Replica server to accept replication traffic using Kerberos authentication over port 8080.
Ensure that an appropriate inbound firewall rule exists that will allow incoming replication traffic. As an example, you can use the following Windows PowerShell command to create a rule with the name HVRAllowReplicaTraffic over port 8080. Enter each cmdlet on a single line, even though they may appear word-wrapped across several lines here because of formatting constraints.
Enable-Netfirewallrule -displayname "Hyper-V Replica HTTP Listener (TCP-In)”
Start Hyper-V Manager > Actions pane for the server that will be the Replica server > Hyper-V Settings.
Click Hyper-V Settings > Replication Configuration.
Select Details > Enable this computer as a Replica server.
In the Authentication and ports section, choose an authentication method and the port to be used (for this example, choose Kerberos authentication and port 8080). If you’re using Kerberos authentication, the replicated data is not encrypted over the network. Only certificate-based authentication encrypts the replicated data during transmission.
In the Authorization and storage section, specify the location to store the Replica virtual machine files (or accept the default location). By default, you specify which primary servers will be allowed to send replication data to this Replica server, along with the storage location to use for each virtual machine. To specify a server, use its fully qualified domain name (FQDN) or the international equivalent (FQIDN). You can use “*” as a wildcard character in the first octet (for example, “*.contoso.com”). You can also choose not to specify allowed primary servers and instead allow any server that successfully authenticates to replicate data to this Replica server. Click Apply or OK to finish.
Windows PowerShell equivalent commands
The following Windows PowerShell cmdlet or cmdlets perform the same function as the preceding procedure. Enter each cmdlet on a single line, even though they may appear word-wrapped across several lines here because of formatting constraints.
This sequence of cmdlets will enable the server for replication using Kerberos authentication over port 8080 and storing the Replica data on the volume D:\Example. It will allow replication from any server that successfully authenticates. All steps must be completed by a user with administrative privileges.
Enable-Netfirewallrule -displayname "Hyper-V Replica HTTP Listener (TCP-In)”
Import-Module Hyper-V
$RecoveryPort = 8080
$ReplicaStorageLocation = “D:\Example”
Set-VMReplicationServer -ReplicationEnabled $true -AllowedAuthenticationType Integrated -IntegratedAuthenticationPort $RecoveryPort -DefaultStorageLocation $ReplicaStorageLocation -ReplicationAllowedFromAnyServer $true
Step 3: Enable virtual machine replication
You can enable replication (or not) for each virtual machine, regardless of the workload the virtual machine is running.
In this example, the steps will enable a virtual machine called “CRMVM” to replicate to the previously enabled Replica server. In this example, only the latest recovery point will be maintained and the initial replication occurs over the network.
In Hyper-V Manager, right-click the virtual machine > Enable Replication… to open the Enable Replication wizard.
On the Specify Replica Server page, provide the name of the Replica server which will host the virtual machine that will replicate the current virtual machine.
On the Specify Connection Parameters page, enter the port that was configured to receive replication traffic in the port on the Replica server (in this example, 8080). If the system has been able to contact the Replica server already, these values will be pre-populated.
Choose either Kerberos or certificate-based mutual authentication to match the selection you made on the Replica server. For this example, choose Kerberos authentication (HTTP).
On the Choose Replication VHDs page, select those disks which you do not want to replicate for the virtual machine, and then click Next. Disks which contain data that is not necessary for the virtual machine to run once operations have switched to the Replica server can be excluded from replication. VHDs that contain data that is rapidly changing and not used by the Replica server after failover, such as page file disks, should be excluded from replication to conserve network bandwidth.
Use the Configure Recovery History page to specify the number of recovery points to maintain on the Replica server. If you choose not to store any additional recovery points, the Replica server maintains only the latest received replica data. These points are updated approximately every 5-15 minutes, depending on the time required for each replication operation. When you choose to maintain an additional one or more recovery points, they are created once every hour. In addition, you can also select to store application-consistent snapshots at a specified interval. These snapshots use the Volume Shadow Copy Service (VSS) and preserve the state of applications that might be running in the virtual machine that is being replicated.
Use the Choose Initial Replication Method page to specify the method you will use to transfer the initial copy of the virtual machine data to the Replica server. You have three options:
Initial replication over the network, which transfers the set of selected VHDs over the network to the Replica server either immediately or at a later time that you specify.
Using a pre-existing restored virtual machine on the Replica server (for example, if you have restored an earlier backup of the virtual machine on the Replica server) as the initial copy. With this option, only the changes that have occurred on the production virtual machine since it was stored are sent over the network.
Using external media. You can save network bandwidth by copying the initial copy to external media and then physically delivering the media to the Replica site.
For this example, choose Send initial copy over the network.
On the Completing the Enable Replication Relationship page, review the information in the Summary and then click Finish.
Windows PowerShell equivalent commands
The following Windows PowerShell cmdlet or cmdlets perform the same function as the preceding procedure. Enter each cmdlet on a single line, even though they may appear word-wrapped across several lines here because of formatting constraints.
This sequence of cmdlets will enable and start replication for two virtual machines (“CRMVM” and “IISVM”). All steps must be completed by a user with administrative privileges.
Import-Module Hyper-V
$ReplicaServer = “Recovery1.contoso.com”
$RecoveryPort = 8080
$PrimaryVM1 = “CRMVM”
$PrimaryServer = “Primary1.contoso.com”
Set-VMReplication -VMName $PrimaryVM1 -ReplicaServerName $ReplicaServer -ReplicaServerPort $RecoveryPort -AuthenticationType Integrated -CompressionEnabled $true -RecoveryHistory 0
Start-VMInitialReplication –VMName $PrimaryVM1
You can monitor replication status in Hyper-V Manager by adding the appropriate column. In the View menu, use the Add/Remove Columns option and add Replication Health to the list of Available Columns in Hyper-V Manager.You can also view replication health for a given monitoring interval. Select the virtual machine from Hyper-V Manager, right-click the replicating virtual machine, and choose View Replication Health… from the Replication option.
The health report shows the current replication state and the health of the connection. You can also view replication statistics.
Step 4: Run a test failover
To ensure that the replicated virtual machines (and applications running within them) will function properly on the Replica server just as they do on the primary server, you can conduct a test failover at any time. When you conduct a test failover, a temporary virtual machine is created on the Replica server. You can test any applications in that test virtual machine without interrupting the ongoing replication. When you conclude the test, the temporary virtual machine is deleted.
Note
This test virtual machine will not by default be connected to any network. If you need to conduct tests that require a network, you can modify the settings of this test virtual machine in the same way you would modify settings of any ordinary virtual machine.
Access the Replica server, and in Hyper-V Manager, right-click the virtual machine you want to test failover for, point to Replication…, and then point to Test Failover….
Choose a recovery point to use. This creates and starts a virtual machine with the name “<virtual machine name>-Test” (for example, “CRMVM-Test”).
Conduct your tests on the test virtual machine. For example, you might verify that the virtual machine starts, pauses, and stops, and that any applications in the virtual machine run properly.
Tip
After you have concluded your testing, discard the test virtual machine by choosing Stop Test Failover under the Replication option or simply delete the test virtual machine directly.
Windows PowerShell equivalent commands
The following Windows PowerShell cmdlet or cmdlets perform the same function as the preceding procedure. Enter each cmdlet on a single line, even though they may appear word-wrapped across several lines here because of formatting constraints.
This sequence of cmdlets will conduct a test failover of the virtual machine “CRMVM.”
$ReplicaVM1 = “CRMVM”
$TestReplicaVM1 = Start-VMFailover -AsTest -VMName $ReplicaVM1
Start-VM $TestReplicaVM1
To stop the test failover operation and discard the test virtual machine:
Stop-VMFailover –VMName $ReplicaVM1
Step 6: Run a planned failover
In a planned failover, the latest changes on the primary virtual machine are replicated to its counterpart Replica virtual machine, then the Replica virtual machine starts, effectively transferring the load from the primary server to the Replica server with no loss of data. You would perform a planned failover, for example, to demonstrate and confirm readiness for a disaster recovery scenario or anytime you need to do any maintenance or upgrades which would require shutting down the physical primary server.
If you have not already done so, follow the procedure in Step 2: Configure a Replica server to configure the primary server to receive replicated data. You may have already used the procedure to configure the Replica server, but for a planned failover, the primary server must also be enabled for replication, so you might have to repeat Step 2 for the primary server.
Start Hyper-V Manager on the primary server and choose a virtual machine to fail over. Turn off the virtual machine that you want to fail over.
Right-click the virtual machine, point to Replication, and then point to Planned Failover.
Click Fail Over to actually transfer operations to the virtual machine on the Replica server. Failover will not occur if the prerequisites have not been met, but this should not happen after following the instructions in this demonstration.
Windows PowerShell equivalent commands
The following Windows PowerShell cmdlet or cmdlets perform the same function as the preceding procedure. Enter each cmdlet on a single line, even though they may appear word-wrapped across several lines here because of formatting constraints.
This sequence of cmdlets will conduct a planned failover of the virtual machine “CRMVM,” provided you have already configured the primary server (in addition to the Replica server) to accept replication traffic using the procedure in Step 2. Run these cmdlets on the primary server:
Stop-VM $PrimaryVM1
Start-VMFailover -VMName $PrimaryVM1 –prepare
Then run these cmdlets on the Replica server:
$ReplicaVM1 = “CRMVM”
Start-VMFailover -VMName $ReplicaVM1
Set-VMReplication -reverse -VMName $ReplicaVM1
Start-VM $ReplicaVM1