Our previous Hyper-V article explored Hyper-V replica as a disaster recovery replication system that provides virtual machine level replication across LAN or WAN connections. There, we reviewed Hyper-V replica structure and used PowerShell and the Hyper-V Manager to configure the Hyper-V replica server settings.

In this article we delve into the Hyper-V replica failover functionality and complete the remaining tasks of the lab that was started in Part 4. After configuring incoming replication (Phase 1), we will continue with the following three phases of our lab:

  • * Phase 2: Enable Virtual Machine replication
  • * Phase 3: Test Hyper-V replica failover
  • * Phase 4: Execute a planned failover

After you configure a Hyper-V replica server to allow incoming replication, you then need to enable replication on the virtual machines on the primary Hyper-V host. You must configure replication for each virtual machine individually, either by using the Enable Replication Wizard in Hyper-V Manager, or by using the Windows PowerShell cmdlet Enable-VMReplication. Replicated virtual machines are in a turned off state, and they will be started only if you perform a failover.

Hyper-V Replica Failover process

The failover process is manual, you must select the virtual machine and fail it over. You can also select the recovery point to restore the VM. There are three types of failover actions: test failover, planned failover and unplanned failover. Let’s review these three options.

Test Failover

Once the primary server and the replica server have been configured and replicas have been created, you can perform a test failover. A test failover allows you to test a virtual machine on the replica server while the primary virtual machine is running, and without disrupting the replication process.

When a test failover is initiated on the replica virtual machine, a new checkpoint is generated and you can select a recovery point from which the new test virtual machine is created. The test virtual machine has an identical name to the replica, but with – Test appended. For example, a replica named ScoreA, will have a test virtual machine name ScoreA – Test. The test virtual machine is not started and is disconnected by default to prevent the possibility of conflicts with the running primary virtual machine.

Planned Failover

This is a preemptive action that you may need to perform because your company is reallocating resources, performing site maintenance or moving VMs as part of a disaster recovery plan. Since this is a planned event, there is no data loss, however there is some downtime for the virtual machine. A planned failover verifies that the primary virtual machine is turned off before executing the failover. During the failover process, the primary server sends all the data that has not yet been replicated, to the replica server. Once the replication completes, Hyper-V replica fails over the virtual machine to the replica server where the virtual machine automatically starts up.

It is important to note that after the planned failover, the virtual machine is running on the replica server, and its changes are not replicated back to the primary server by default. You will need to configure reverse replication to ensure that a replica of the VM is created across the network. We will cover all these tasks in our lab.

Unplanned Failover

If the primary VM fails, you will need to manually perform a failover. This is an unplanned incident. The downside of this process is that data loss may occur because changes at the primary virtual machine might not have replicated before the primary VM failed. You initiate a failover at the replica virtual machine only if the primary virtual machine is either unavailable or turned off. During a failover the virtual machine runs on a replica server. After you recover the primary site, you can use reverse replication to reestablish replication.

Now let’s get to work. Enabling VM replication is our next phase before we can actually test and perform failover related tasks.

Phase 2: Enable Virtual Machine replication

  1. On S12R2, in Hyper-V Manager, right-click ScoreA, and then click Settings.

  2. In Settings for ScoreA, in the navigation pane on the left, expand Network Adapter, and verify that only two nodes are displayed below it: Hardware Acceleration and Advanced Features. Scroll down to the Management section and confirm that there is no Replication option there.

  3. In Hyper-V Manager, right-click ScoreA, and then click Enable Replication.

  4. In Enable Replication for ScoreA, on the Before You Begin page, click Next.

  5. On the Specify Replica Server page, in the Replica server field, type Win12R2, and then click Next.

    If Hyper-V replica had not been configured on the remote server, you would receive a message stating “The specified replica server is not configured to receive replication from this server.” See figure below. In our case, the remote server, Win12R2, has already been configured for incoming replication, so let’s move to step 6.

  6. On the Specify Connection Parameters page, confirm that Use Kerberos authentication (HTTP) is selected, that Compress the data that is transmitted over the network is enabled, and then click Next. Compressing the data improves the transmission in slow network connections.

  7. On the Choose Replication VHDs page, confirm that all ScoreA VHDs are selected, and then click Next.

  8. On the Configure Replication Frequency page, in the drop-down box, click 30 seconds, and then click Next.

  9. On the Configure Additional Recovery Points page, click the Create additional hourly recovery points option, in Coverage provided by additional recovery point (in hours) field, type 12, and then click Next.

  10. On the Choose initial Replication Method page, confirm that both the Send initial copy over the network and Start replication immediately options are selected, and then click Next.
  11. The default method is to send the initial copy over the network. In case of large virtual machines over slow networks, you can export the VM data to an external media and import it in the replica server. If the VM that you want to replicate already exists in the replica server, you can use it as the initial copy. Then, you can start the replication immediately or schedule the initial replication.

  12. On the Completing the Enable Replication wizard page, review the summary setting and click Finish.

  13. In Hyper-V Manager, in the navigation pane, click Win12R2 which is our replica server. Confirm that the ScoreA virtual machine is on Win12R2 and that it is receiving changes.
  14. After the replication process starts, the Status column in Hyper-V Manager shows replication progress as a percentage of the total replication for the configured virtual machine. After that, the virtual machine replica is in the turned off state, and you cannot start it until the failover is performed.

  15. Virtual machines for which you enable replication get an additional management setting called Replication. You use this setting to review and modify replication parameters.
  16. In Hyper-V Manager, right-click ScoreA, click Replication, and then click View Replication Health.

  17. In Replication Health for “ScoreA”, confirm that the Replication Health is Normal. You can verify other settings including the primary server and replica server.

  18. In Hyper-V Manager, right-click ScoreA, and then click Settings. In Settings for ScoreA, in the navigation pane, expand Network Adapter, and confirm the presence of two new nodes Failover TCP/IP and Test Failover.

    When replication is enabled, virtual machine network adapters get additional settings that were unavailable before. These new settings pages are Failover TCP/IP and Test Failover. Failover TCP/IP is available only for network adapters, not for legacy network adapters.

    These settings are useful when a virtual machine has a static IP address assigned, and the replica site is using different IP settings than the primary site. You can configure the TCP/IP settings that a network adapter will use after the failover is performed.

  19. In Settings for ScoreA, in the navigation pane, scroll down and confirm that there is a Replication option under the Management section.
  20. Using Windows PowerShell, confirm replication settings and status by running the following cmdlet:

    Get-VMReplication –VMName ScoreA | FL

Phase 3: Test Hyper-V Replica failover

  1. In Hyper-V Manager, verify that Win12R2 is selected in the navigation pane. Right click ScoreA and then click Settings. In Settings for ScoreA, in the navigation pane, expand Network Adapter, and then click Failover TCP/IP.

    As this VM is using a DHCP server we do not need to configure this section. To have a static IP address configure for the VM, you would click Use the following IPv4 address scheme for the virtual machine and enter the appropriate settings.

    Think about this for a moment, what would happen when a virtual machine with a static IP address fails over onto another datacenter with a different network configuration. Let’s say that the primary server is located on datacenter X, your VM sits there with IP address, default gateway, DNS settings, and other IP settings statically configured. However on datacenter Y, where the replica server is, there are different network configurations; this would cause problems on all the VMs that failover on datacenter Y because they will be running on a different network. That’s why Hyper-V allows you to add failover network configuration settings, which can be used when you failover it to the replica server.

    These settings will not work on legacy virtual network adapters, a synthetic virtual network adapter is required for this configuration.

  2. Failover TCP/IP settings can also be configured using Windows PowerShell. See the following example:

    Set-VMNetworkAdapterFailoverConfiguration -VMName ScoreA `
    -VMNetworkAdapterName Ethernet `
    -IPv4Address 192.168.7.39`
    -IPv4SubnetMask 255.255.255.0 `
    -IPv4DefaultGateway 192.168.7.254`
    -IPv4PreferredDNSServer 192.168.7.1 `
    -IPv4AlternateDNSServer 68.105.28.12

  3. In Settings for ScoreA, in the navigation pane, under Network
    Adapter, click Test Failover. In the details pane for Virtual switch, click External, and then click OK.

  4. In Hyper-V Manager, select Win12R2, right-click ScoreA, click Replication, and then click Test Failover.

  5. In Test Failover, click Test Failover. A checkpoint for the ScoreA VM is generated and a new virtual machine named ScoreA – Test is created.

  6. In Hyper-V Manager, right-click ScoreA – Test, and then click Settings.

  7. In Settings for ScoreA – Test, click Network Adapter, confirm that it is connected to the External virtual switch, and then click OK.

  8. In Hyper-V Manager, right-click ScoreA – Test, and then click Start.

  9. Right click the ScoreA -Test virtual machine and select Connect…

  10. On ScoreA – Test, sign in using your administrator credentials. In the Command Prompt window, type ipconfig /all, and confirm that the VM has received correct IP settings from a DHCP server.

  11. In Hyper-V Manager, select Win12R2, right-click ScoreA, click Replication, and then click Stop Test Failover.

  12. In Stop Test Failover, click Stop Test Failover.

  13. In Virtual Machine Connection, click Exit, and confirm that the ScoreA – Test virtual machine has been deleted.

We have successfully performed a Hyper-V replica test failover. Now it is time to step it up by performing a planned failover.

Phase 4: Perform a planned failover

  1. In Hyper-V Manager, in the navigation pane, click S12R2, right click ScoreA and select connect.

  2. In ScoreA, sign in using your administrator credentials. At the command prompt, create a new folder by typing md “c:\ “Before Failover”; verify the folder was created by typing dir c:\

  3. In Hyper-V Manager, right-click ScoreA, click Replication and then click Planned Failover.

  4. In Planned Failover, confirm that Start the replica virtual machine after failover is selected, and then click Fail Over.

  5. An error displays because the virtual machine is still running and it must be turned off before performing a planned failover. Close and cancel Planned Failover.

  6. To shut down ScoreA, at the command prompt, type powershell and then type stop-computer.

  7. In Hyper-V Manager, make sure that S12R2 is selected, right-click ScoreA, click Replication, and then click Planned Failover.

  8. In Planned Failover, confirm that Start the replica virtual machine after failover is selected, and then click Fail Over.

  9. In Hyper-V Manager, in the navigation pane, click Win12R2. Confirm that ScoreA is in the Running state.

  10. Right click ScoreA, select connect, and sign in with administrator credentials. At the command prompt type dir c:\, confirm that a directory named “before failover” exits on the root of the C drive. The planned failover permits all changes from the primary virtual machine to be replicated.

  11. At the command prompt type md “c:\before reverse replication”; verify the folder was created by typing dir c:\

  12. In Hyper-V Manager, right-click ScoreA, click Replication, and then click Reverse Replication.

  13. On the Before You Begin page, click Next.

  14. On the Specify Replica Server page, ensure that S12R2.abc.com displays as the Replica Server and then click Next.

  15. On the Specify Connection Parameters page, ensure that Use Kerberos authentication (HTTP) is selected, and Compress the data that is transmitted over the network is checked. Click Next.

  16. On the Configure Replication Frequency page, select 30 seconds and click Next.

  17. On the Configure Additional Recovery Points page, click the Create additional hourly recovery points option, in Coverage provided by additional recovery point (in hours) field, type 12, and then click Next.

  18. On the Completing the reverse Replication Wizard page, click Finish.

  19. On ScoreA, at the command prompt, type shutdown /s /t 0 and press Enter

  20. In Hyper-V Manager, select Win12R2, verify that ScoreA is in Off state. Right-click ScoreA, click Replication, and then click Planned Failover.

  21. In Planned Failover, confirm that Start the replica virtual machine after failover is selected, and then click Fail Over.

  22. In Hyper-V Manager, in the navigation pane, click S12R2. Confirm that the ScoreA state is Running. Then right click ScoreA and select Connect.

  23. On ScoreA, sign in with administrator credentials. At the command prompt type dir c:\, confirm that both directory names: “before failover” and “before reverse replication” exit on the root of the C drive.

After these steps, we have successfully demonstrated the planned failover process. As you can see with a planned failover the data is replicated from the primary server to the replica server without data loss.

Closing Remarks

Hyper-V Replica is updated regularly, and when needed, you can perform manual failover from a primary virtual machine to a replica virtual machine. There are three ways to fail over virtual machines: test, planned, unplanned failover. A test failover is a non-disruptive task that you perform on the replica server without interrupting the replication process. Planned failovers are without data loss, whereas unplanned failovers can cause loss of last changes, up to 15 minutes depending on your replication frequency configuration.

Hyper-V replica is a valuable data recovery solution built into Windows Server 2012 Hyper-V. Small businesses and larger enterprises can take advantage of this functionality as it can be implemented using non-clustered as well as clustered Hyper-V hosts. Using Windows PowerShell, the Hyper-V replica processes can be automated for hundreds or thousands of virtual machines.