Edit

Share via


Fail over a replicated virtual machine with Hyper-V Replica

After you enable Hyper-V Replica and replicate a virtual machine (VM), you can perform failover operations to switch the VM to the replica host or cluster. This article explains how to perform different types of failover operations by using Hyper-V Replica with Hyper-V Manager, Failover Cluster Manager, PowerShell, or Windows Admin Center - Virtualization mode.

For more information about Hyper-V Replica, or if you need to enable replication or replicate a VM, see the following articles:

Failover scenarios

Hyper-V Replica supports the following three failover scenarios.

  • Test failover: creates a test VM on the replica host or cluster without affecting the ongoing replication. It enables you to verify that the replica VM is functioning correctly. After testing, you can stop the test failover to remove the test VM.

    By default, the test VM is created from the latest recovery point and isn't connected to a network. If you configured extra recovery points, you can choose to create the test VM from one of those points. You can only run one test failover on a VM at a time.

  • Planned failover: use when you can gracefully shut down the primary VM. It helps you to perform an end-to-end validation of your recovery plan. It ensures that all changes are replicated to the replica before switching over, resulting in zero data loss. After the planned failover, you can optionally reverse replication back to the original primary host or cluster, then fail back the VM to the original location.

    Planned failover isn't a substitute for high availability, but it can enable you to keep your workloads running with minimal downtime without data loss. It can be useful for events such as planned maintenance of an entire site or datacenter.

  • Unplanned failover: use when the primary VM is unavailable due to a failure, such as a power outage. It enables you to switch to the replica VM by using the latest recovery point or previous recovery points, if configured. After the unplanned failover, you can complete the failover process and optionally reverse replication back to the original primary host or cluster, then fail back the VM to the original location.

    Unplanned failover is designed for disaster recovery scenarios where the primary VM can't be gracefully shut down. It might result in some data loss, depending on the recovery point selected.

Prerequisites

Before you begin, make sure you meet the following prerequisites:

  • You have a VM that you're replicating by using Hyper-V Replica.

  • The VM's replication health state is Normal. To check the replication health, see Monitor replication progress.

  • A user account that's a member of the Hyper-V Administrators security group on each host. In an Active Directory domain, you can add users or groups to this group by using Group Policy Preferences. Alternatively, the account can be a local administrator on each host. For more information about the Hyper-V Administrators group, see Active Directory Security Groups.

Fail over a virtual machine

You need to run a failover operation for each VM. You can only run one failover operation at a time for a VM. You can run each failover operation by using the following combinations:

  • Hyper-V Manager on clusters or single hosts
  • Failover Cluster Manager on clusters
  • PowerShell on clusters or single hosts
  • Windows Admin Center - Virtualization mode on single hosts only. You can only fail over by using Windows Admin Center - Virtualization mode from the primary host to the replica host. You can't perform a test failover or reverse replication at this time.

Select the relevant tab for instructions.

Failing over a virtual machine by using Hyper-V Manager depends on the type of failover you want to perform.

Test failover by using Hyper-V Manager

To run a test failover by using Hyper-V Manager, follow these steps:

  1. Open Hyper-V Manager on a device you use to manage a host in the replica cluster or a replica single host with the VM, or on the host itself where Windows Server with Desktop Experience is installed.

  2. In the resources pane, select the host that contains the replica VM for which you want to run a test failover.

  3. Right-click the VM, select Replication, then select Test Failover.

  4. In the Test Failover screen, select the recovery point you want to use for the test failover from the drop-down list, then select Test Failover.

    A screenshot of the Test Failover dialog showing the recovery point selection list in Hyper-V Manager.

  5. The host creates a duplicate VM. The VM name is the original VM name with - Test appended. The duplicate VM isn't connected to a network by default. At this point, you can start the VM and perform tests that you require to verify that it functions correctly.

  6. When you finish testing, right-click the replica VM (not the test duplicate), select Replication, then select Stop Test Failover. In the confirmation dialog, select Stop Test Failover to delete the test VM and discard its data.

Planned failover using Hyper-V Manager

To run a planned failover using Hyper-V Manager:

  1. Open Hyper-V Manager on a device you use to manage a host in the primary cluster or a primary single host with the VM, or on the host itself where Windows Server with Desktop Experience is installed.

  2. In the resources pane, select the host that contains the VM for which you want to run a planned failover.

  3. Shut down the VM if it's running. You must shut down the VM to perform a planned failover.

  4. Right-click the VM, select Replication, then select Planned Failover.

  5. In the Planned Failover screen, check the box to Reverse the replication direction after failover and optionally check the box to Start the Replica virtual machine after failover, depending on your requirements. The dialog shows a list of the prerequisite checks and actions the planned failover does. By default, the replica VM starts after failover. Don't forget to attach the VM to a network if necessary.

    A screenshot of the Planned Failover dialog displaying prerequisite checks, actions, and options to reverse replication and start the replica VM in Hyper-V Manager.

  6. Select Fail Over to begin the process.

    A screenshot confirming successful prerequisite checks and actions in the Planned Failover dialog in Hyper-V Manager.

    At this point, failover is complete. If you selected the option to reverse the replication direction, replication is automatically reconfigured to replicate changes back to the original primary host or cluster. Alternatively, right-click the replica VM, select Replication, then select Reverse Replication to manually configure replication back to the original primary host or cluster. Once reverse replication is configured, the replication health returns to Normal.

  7. Start the VM if it isn't already running by right-clicking the VM, then selecting Start. Remember to attach the VM to a network if necessary.

Unplanned failover using Hyper-V Manager

To run an unplanned failover using Hyper-V Manager:

  1. Open Hyper-V Manager on a device you use to manage a host in the replica cluster or a replica single host with the VM, or on the host itself where Windows Server with Desktop Experience is installed.

  2. In the resources pane, select the host that contains the replica VM for which you want to run an unplanned failover.

  3. Right-click the replica VM, select Replication, then select Failover.

  4. In the Failover screen, select the recovery point you want to use for the failover from the drop-down list, then select Fail Over.

    A screenshot of the Failover dialog showing available recovery points for an unplanned failover in Hyper-V Manager.

  5. The process creates a checkpoint for the replica VM and then starts the VM. You should perform tests that you require to verify that the recovery point you chose functions correctly. Don't forget to attach the VM to a network if necessary.

    If you need to select a different recovery point, you can cancel the failover by right-clicking the replica VM, select Replication, then select Cancel Failover. Then you can choose a different recovery point.

  6. Once you test the VM and don't need to revert to a different recovery point, you need to complete the failover. Right-click the replica VM, select Replication, then select Remove Recovery Points. This action removes the recovery points and merges the checkpoint, which means you can't revert to an earlier recovery point. If you want to keep extra recovery points, you can first export the replica VM before completing failover.

    A screenshot of the context menu option to remove recovery points after an unplanned failover in Hyper-V Manager.

    At this point failover is complete, however the replication health shows as Warning because that replication direction isn't configured.

Reverse replication after unplanned failover using Hyper-V Manager

Once the primary VM is available again, you should replicate the changes made to the replica VM back to the original primary VM. The process is called Reverse replication. Before you can reverse the replication, you need to mark the original primary VM as able to be a target to receive replication. You can't perform this action in Hyper-V Manager.

  1. On the original primary host that contains the original primary VM, open a PowerShell session as an administrator, or connect remotely using the Enter-PSSession cmdlet on a device you use to manage the host.

  2. Mark the original primary VM to be a target to receive replication by running the following command. Be sure to replace placeholder <VMName> with the name of the original primary VM.

    Set-VMReplication -VMName '<VM Name>' -AsReplica
    
  3. Check the status of the original primary VM by running the following command on the primary host:

    Get-VMReplication -VMName '<VM Name>' | FL VMName, ReplicationMode, ReplicationState
    

    Here's an example of the output, which shows that the primary VM is now configured as a replica and is waiting for replication:

    VMName           : contoso-vm-01
    ReplicationMode  : Replica
    ReplicationState : WaitingForInitialReplication
    
  4. On the replica host that contains the replica VM, in Hyper-V Manager right-click the replica VM, select Replication, then select Reverse Replication. In the Reverse Replication screen, if you see Before You Begin, select Next.

  5. The options in the wizard are prepopulated based on the settings of the original primary VM. If you don't need to change any settings, select Next on each screen until you reach the Summary screen, then select Finish to begin the reverse replication. Alternatively the options are the same as when you initially enabled replication for the VM.

    A screenshot of the Reverse Replication wizard summary page before starting reverse replication in Hyper-V Manager.

    At this point, any changes are replicated and the replication health returns to Normal. The primary and replica roles have now swapped. To return to the original replication direction, you can perform a planned failover, as described in the Planned failover section.