agsandrew - Fotolia
Hyper-V Replica helps in achieving availability of VMs. You keep virtual workloads running on Hyper-V hosts in the production site and replicate the same workloads to Hyper-V hosts running in disaster recovery sites. If any disaster strikes at the production site, virtual workloads at disaster recovery sites will be brought online to provide services. While you can enable Hyper-V Replica using Hyper-V Manager or System Center Virtual Machine Manager, I find it more quick and efficient to use PowerShell. Here are the PowerShell commands you need to run in order to manage Hyper-V replication.
Note that you will need at least two Hyper-V hosts running Windows Server 2012 or later in order to configure Hyper-V replication. Hyper-V hosts running in a production site will be known as primary servers and Hyper-V hosts in a disaster recovery site will be known as replica servers.
First, run the command shown below on the replica server in order to enable Hyper-V Replica:
Enable-Netfirewallrule -DisplayName "Hyper-V Replica HTTP Listener (TCP-In)" Set-VMReplicationServer -ReplicationEnabled $true “-AllowedAuthenticationType Kerberos” -KerberosAuthenticationPort 10000 “-DefaultStorageLocation "D:\ReplicatedVMs" “ -ReplicationAllowedFromAnyServer $true
This command configures Hyper-V replication on the replica server and also enables required firewall rules to accept replication from the primary server.
Next, execute the following command on the primary server to enable Hyper-V replication for a particular VM:
Enable-VMReplication -VMName "SQLVM" ` -ReplicaServerName "ReplicaServer.TechTarget.Com" ` -ReplicaServerPort 10000 -AuthenticationType Kerberos ` -CompressionEnabled $true -RecoveryHistory 5
This command enables replication for a VM named SQLVM. The VM is configured to replicate its contents with the replica server. Note that, as part of the command, we are also enabling compression and the recovery history is set to 5.
Finally, you will be required to initiate the replication of SQLVM, so the contents are replicated to the replica server, as shown in the command below:
Start-VMInitialReplication –VMName SQLVM
Once the contents of SQLVM are replicated to the replica server, SQLVM at the replica server will be turned off and SQLVM at the primary server will be running to provide required services. To get the replication status for SQLVM, what you can do is execute Measure-VMReplication on the primary server as shown in the following command:
Speed up the Hyper-V replication process
Learn about Windows Server 2016 Storage Replica
Decide between Hyper-V replication and Storage Replica
Dig Deeper on Microsoft Hyper-V management
Related Q&A from Nirmal Sharma
Use System Center Virtual Machine Manager and PowerShell to make logical network management easy. Execute a script to display network virtualization ... Continue Reading
Hyper-V replication is easy to use, but there are a number of steps you should take during Hyper-V replication setup to ensure you stay abreast of ... Continue Reading
Manage Hyper-V clusters more easily with PowerShell cmdlets and scripts that automate the retrieval and display of node information, including node ... Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.