How to Clone an Azure VM Instance to Another Region

Learn how to clone Azure VM instances across regions to have backup instances ready in the event of regional outages.

Patrick Londa
Author
Mar 31, 2023
 • 
6
 min read
Share this post

For your organization to have an effective failover process, it means that you are able to quickly and easily switch over to backup resources when primary resources fail.

If you want to have backup instances for your virtual machines, you can create copies from one source region to a target region. By using this copying method, you can ensure that you have backup resources to use if an instance fails in a certain region.

In this guide, we’ll show you how to copy instances from one region to another so that you can be prepared for regional outages.

How to Create a Snapshot of Your Azure VM Instance

You can’t just directly copy an instance to another region. Instead, you must create a snapshot of the instance first, copy that snapshot to a target region, and then create an instance from that snapshot.

In this first step, we’ll show you how to create a snapshot of your Azure VM instance.

Using the Azure portal:

  1. First, open up the Azure portal and go to the VM section.
  2. In the VM blade, click on the Disks tab and select the disk you want to copy.
  3. Next, click on Create snapshot.
Creating a snapshot in Azure
Source: Azure documentation
  1. Enter the name of the snapshot, the resource group, and choose Incremental for Snapshot type.
  2. In the Review + create tab, click Create.
Source: Azure documentation

It may take a few minutes for the snapshot to be created.

Using the Azure CLI:

  1. Use the az disk show command to retrieve the disk object for the VM that you want to create a snapshot of, specifying the disk name and resource group:
az disk show -g MyResourceGroup -n MyDisk --query id --output tsv
  1. Use the az snapshot create command to create the snapshot, specifying the resource group, snapshot name, and the ID of the disk:
az snapshot create -g MyResourceGroup -n MySnapshot --source /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/disks/MyDisk

In an Azure ecosystem, just as in similar cloud services, some restrictions should be noted when copying instances across regions. This is particularly important to consider if the needs of your organization exceed your set subscription plans per region.

Copying the New Snapshot to your Target Region

Next, you’ll want to copy your new snapshot over to your target region so you can use it to create an instance in that target region. We’ll show that using the recommended “Managed copy” method.

Using the Azure portal:

  1. Log in to the Azure portal using this specific link.
  2. Go to the incremental snapshot that you want to copy to another region.
  3. Click Copy snapshot.
Copying an Azure Snapshot
Source: Azure Documentation
  1. Name the new snapshot, specify your target region, and specify Incremental under Snapshot type.
Copying a Snapshot in Azure to Target Region
Source: Azure Documentation

Using the Azure CLI:

You can use the following command to copy your new snapshot over to your target region:

subscriptionId=<yourSubscriptionID>
resourceGroupName=<yourResourceGroupName>
targetSnapshotName=<name>
sourceSnapshotResourceId=<sourceSnapshotResourceId>
targetRegion=<validRegion>

sourceSnapshotId=$(az snapshot show -n $sourceSnapshotName -g $resourceGroupName --query [id] -o tsv)

az snapshot create -g $resourceGroupName -n $targetSnapshotName -l $targetRegion --source $sourceSnapshotId --incremental --copy-start

az snapshot show -n $sourceSnapshotName -g $resourceGroupName --query [completionPercent] -o tsv

Now, you have the snapshot you need in the target region. 

Before we move on, it’s a good practice to delete the snapshot in the other region if you no longer need it. You can find the portal and CLI steps for deleting unneeded Azure snapshots in one of our other how-to guides on that topic.

Creating a New Instance in a Target Region with your Copied Snapshot

Finally, let’s use our copied snapshot as the source for creating our new instance, or managed virtual disk, in our target region.

Using the Azure portal:

  1. In the Azure portal, click “Create a resource” in the left menu.
  2. Type in “managed disk” and select it from the list, then click Create.
  3. Select a resource group for the disk and give it a name.
  4. To create your managed disk from a snapshot, select Snapshot as the Source type, and choose the specific snapshot from the Source snapshot drop-down.
  5. Choose a size for the disk, either Standard (HDD) or Premium (SSD) storage.
  6. Select Create.

Using the Azure CLI:

You can run this command to create a new instance based on your new snapshot and specify your target region:

az disk create -g <RESOURCE-GROUP> -n <NEW-DISK-NAME> --source <SNAPSHOT-ID> --location <TARGET-REGION> --zone <AVAILABILITY-ZONE>

Here’s an example:

az disk create -g MyDemoGroup -n MyBackupDisk 
--source "/subscriptions/{subscriptionId}/resourceGroups/MyDemoGroup/providers/Microsoft.Compute/snapshots/mySnapshot1" 
--location eastus1 --zone 2

Now, you’ve successfully created a copy of your original instance in another region!

Creating Azure Instance Backups Easily with Blink

Preparing for regional outages is something you can do manually by following the three basic steps we’ve outlined. It is time-intensive and difficult to scale, but for rare use cases, this approach might be all you need to respond to an outage.

If you want to be able to react faster and take these actions when certain events take place, you need to leverage automation.

With Blink, you can run all of these steps by just inputting basic details into this self-service automation. Specify which instance you want to copy and this automation will execute the following steps:

You can also set up event-based triggers. For example, if VM performance dips below a certain threshold, you could use that event to kick off mitigation actions.

Use any of the 5K automations in the Blink library right away, or build your own custom automation to fit your exact use case.

Get started with Blink to create a world-class failover system today.