Hyper-V Replication makes for a great built in feature to sync mission critical VMs to another host for warm standby. This feature allows for quick easy failover and takes minimal effort to setup. While this is intended to allow for failover and failback I have also utilized this replication methodology to migrate a 7 hosts worth of VMs from a datacenter on one side of the country to another. Generally speaking this process works best in a domain environment where both the source and replica server are joined to the same domain. You will also need to configure vSwitches on the replica server to match those on the source server, or ensure you reconfigure the vSwitches associated with the NICs on individual VMs.
The first step to setting up replication is enabling the destination server (replica server) to receive replicas and ensure that the proper firewall ports are opened on both the Windows firewall and any firewall appliance that sits between the source Hyper-V server and the replica server. From the Hyper-V MMC choose Hyper-V settings on the right. Once the dialog Window appears click Replication Configuration, then check boxes to enable this computer as a replica server using Kerberos and HTTP.
Next we will need to ensure that our inbound rules allow for inbound replication. From control panel open Windows Firewall with Advanced Security and allow the following rules (if not already enabled)
Enabling Replication on VMs
Now that we have setup the replica server we can proceed to the source Hyper-V host and setup VM replication. To enable VM replication right click the VM and choose enabled replication. At this point you will get a enable replication wizard, proceed through the wizard entering the hostname of the replica server, choosing to HTTP port 80 with Kerberos, choose to sync all VHDs or only specific ones, set replication frequency, and choose the initial replication method. Once this occurs your initial replica will begin to sync. Once the initial replication is done the VM will then sync deltas at the replication window you specified in the wizard to enable replication. From this point you can keep tabs on the replication in the replication tab at the bottom of the hyper-v MMC window for the VM you have highlighted.
To initiate a planned failover event (either for testing, DR needs, or migration) you will want to make sure a few things are in place. Setup the Hyper-V source server as a replica server following the steps above, this step is needed if you will need to failback to the source server. Next shutdown the VM you are failing over, then right click the VM, choose replication, and then planned failover.
Next you will see a planned failover screen, click the failover button to begin failing over.
If you are performing a one way migration you can safely ignore warnings about failback, once the last replication window is complete after shutdown, you can disable replication from the replica side and start the VM.
To failback from the replica server to the source Hyper-V host, you can shutdown the VM, then once shutdown you can right click the VM on the replica server, choose replication then reverse replication and proceed through the prompts. This will perform a last data sync before failing back so any changes made since the failover event will be sync’d back to your production server.
Hyper-V replication is a fantastic tool that is super simple to setup and makes setting up a warm standby painless. A few notes of caution, the first being that replication is not a suitable replacement for backups. Replication is good for DR in the sense that your RTO will be low with minimal data loss, however this doesn’t change the need to be able to retrieve old files, or restore data in the event of a catastrophic server failure or attack, as these changes are quickly replicated from the source server to the replica server. The second note of caution is that if you are using Microsoft Failover Clustering with Hyper-V you will need to setup a Hyper-V Replica Broker as a failover cluster role (only one needed per cluster) in order to act on behalf of the cluster to replicate VMs and in and out of the failover cluster. There are some caveats to this that I will document in a future blog post, however despite the extra steps needed for this it is still a fairly painless process and Hyper-V clusters can replicate to standalone Hyper-V hosts and vice versa.