Site icon REBELADMIN

How to replicate Azure VM to a secondary Azure Region?

When it comes to Disaster recovery solutions, most of the time we select a different physical site as a backup/replication target. This is because if the primary site is down, we still have a copy of data safe on different site. We also can do the same with Azure VM. By using Azure Site Recovery Service, we can simply replicate existing Azure VM to a secondary Azure Region.

Let’s go ahead and see how we can do this.

For the configuration process, I will be using PowerShell as well as GUI. Therefore, please make sure you have an Azure PowerShell module installed. More info about it can find under https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.8.0

Create an Azure VM to use as Source

I like to begin the configuration process by creating a Test VM. To do that,
1. Launch PowerShell console and connect to Azure using Connect-AzAccount
2. Then create a new resource group using,

New-AzResourceGroup -Name REBELRG1 -Location “East US”

In the above, REBELRG1 is the resource group name and its created-in East US Azure region.

3. The next step is to create a new virtual network under REBELRG1 resource group.

$vmsubnet = New-AzVirtualNetworkSubnetConfig -Name vmsubnet -AddressPrefix “10.0.2.0/24”
New-AzVirtualNetwork -Name REBELVN1 -ResourceGroupName REBELRG1 -Location “East US” -AddressPrefix “10.0.0.0/16” -Subnet $vmsubnet

In the above, REBELVN1 is the new virtual network name. It has 10.0.0.0/16 address space. It also has a new subnet 10.0.2.0/24 (vmsubnet) for virtual machines.

4. As the next step of the configuration, I am going to create a new virtual machine under REBELRG1 resource group. This will be used for testing purposes.

$mylogin = Get-Credential
New-AzVm -ResourceGroupName REBELRG1 -Name “REBELTVM01” -Location “East US” -VirtualNetworkName “REBELVN1” -SubnetName “vmsubnet” -addressprefix 10.0.2.0/24 -PublicIpAddressName “REBELVM01IP1” -OpenPorts 3389 -Image win2019datacenter -Size Standard_D2s_v3 -Credential $mylogin

In the above, I am creating a virtual machine called REBELTVM01 in East US Azure region. It is running windows server 2019 data center edition. I have specified it using -Image parameter. It also using Standard_D2s_v3 vm size. For networking, it uses REBELVN1 virtual network and subnet 10.0.2.0/24.

5. Then I log in to the VM and created a folder and a file to use later for testing.

New-Item -Path ‘C:\REBELTest’ -ItemType Directory
New-Item -Path ‘C:\REBELTest\Test1.txt’ -ItemType File

Create Azure Resource Group and Azure Virtual Network for Target

In this demo, I am going to replicate Azure VM to “Canada Central” Azure region. Before I start replication, I like to create a new resource group and virtual network for it.

1. Create a new resource group using,

New-AzResourceGroup -Name RECOVERRG1 -Location “Canada Central”

In the above, RECOVERRG1 is the resource group name, and its created in “Canada Central” Azure region.

2. The next step is to create a new virtual network under RECOVERRG1 resource group.

$vmsubnet2 = New-AzVirtualNetworkSubnetConfig -Name vmsubnet2 -AddressPrefix “10.1.3.0/24”
New-AzVirtualNetwork -Name REBELVN2 -ResourceGroupName RECOVERRG1 -Location “Canada Central” -AddressPrefix “10.1.0.0/16” -Subnet $vmsubnet2

In the above, REBELVN2 is the new virtual network name. It has 10.1.0.0/16 address space. It also has a new subnet 10.1.3.0/24 (vmsubnet2) for virtual machines.

Enable Azure VM Replication

Now we have the test VM and resource group ready. Let’s go ahead and enable the replication.
To do that,

1. Log in to Azure portal (https://portal.azure.com/) as a global administrator

2. Then go to the properties page of REBELTVM01 Virtual Machine.

3. Then click on Disaster recovery

4. This will open Azure Site Recovery configuration page. In the Target region option select Canada Central

5. Then click on the Advanced settings tab.

6. Under VM resource group option select RECOVERRG1. This is the resource group we created for target resources. For the Virtual network option select REBELVN2, the virtual network we created in the previous section. Then at the end click on Review + Start replication

7. Review the configuration settings on the page and click on Start replication to complete the configuration.

Testing

Once replication is enabled, we can verify replication health by going into the virtual machine properties page | Disaster Recovery

We can test the failover process by doing a test failover. To do that, click on the Test Failover option

Then select recovery point, virtual network, and then click on OK.

After few minutes I can see Azure spin up test VM.

 

With failover, VM will not have a public IP address. We need to assign public IP manually or using a runbook after the failover (unless you have a jump box in the target network).

To assign public ip to VM, search for a network interface in the portal search box.

From the list, click on the interface belong to failover vm.

Then go to IP configuration and click on the already existing IP address.

In the properties page associate new public ip to it.

Once the allocation is completed, log in to VM using new public IP.
Then verify if the VM has the test folder and file we created on the source.

As we can see, Azure VM replication to a secondary region is working as expected.

This marks the end of this blog post. I hope now you have a better understanding of how we can replicate Azure VM to a secondary region using Azure Site Recovery Service. If you have any further questions about this feel free to contact me on rebeladm@live.com also follow me on twitter @rebeladm to get updates about new blog posts.

Exit mobile version