Moving Azure Managed Disks between regions and subscriptions

I just had a scenario, where a customer is using VMs in Azure, with Managed Disks. Now, due to different events, they wanted to move their VMs to a different region.  Normally that’s an easy task, copying the blobs from one Storage Account to another. It’s actually the same way to do it Managed Disks just a few different steps. Go to your PowerShell prompt!

Using Grant-AzureRmDiskAccess we can create a SAS URL to export our disk from. You can also do this from the portal, but since we’re using PowerShell for the rest…

I started by creating a new Storage Account in the region they wanted to move to – West Europe:

[powershell]
$rgName = “<resource group name>”
$location = “West Europe”
New-AzureRmStorageAccount -Name $storageAccountName -Location $location -SkuName Premium_LRS -ResourceGroupName
[/powershell]

Next I needed the keys for this Storage Account:

[powershell]
$saKey = Get-AzureRmStorageAccountKey -ResourceGroupName $rgName -Name $storageAccountName
[/powershell]

Next, create a Storage Context, which is just a PowerShell object to encapsulate credentials for a Storage Account:

[powershell]
$storageContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $saKey[0].Value
[/powershell]

And a container for the vhd files:

[powershell]
New-AzureStorageContainer -Context $storageContext -Name vhds
[/powershell]

From there I can create the SAS URL for my Managed Disk:

[powershell]
$diskName = “<diskname>”
$sas = Grant-AzureRmDiskAccess -ResourceGroupName $rgName -DiskName $diskName -DurationInSecond 3600 -Access Read
[/powershell]

Now I have 1 hour to copy my disk, which is fine for me. Using Start-AzureStorageBlobCopy I can then use the SAS URL I just got as my source, and the Storage Context to access the destination:

[powershell]
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer vhds -DestContext $storageContext -DestBlob $diskName
[/powershell]

This will finish *quick*, but don’t be fooled. The command only starts a job to copy the blob. To get a status, you can use:

[powershell]
Get-AzureStorageBlobCopyState -Context $storageContext -Blob $diskName -Container vhds
[/powershell]

It will output something like:

CopyId            : 38ad189f-9c91-4d2d-ba42-2eb248a42d37
CompletionTime    :
Status            : Pending
Source            : https://md-sradasdasdad.blob.core.windows.net/fmmv24slnk1t/abcd?sv=2016-05-31&sr=b&si=c0493f74-f65f-4bfd-82a0-8e1b64fdd9e4&sig=rx5tEwcpP8c
BytesCopied       : 817053696
TotalBytes        : 137438953984
StatusDescription :

Now it’s just a matter of waiting for it to finish, and you can create the VM in the destination region. All of the above can also be used to move between subscriptions, a feature that is not yet available for Managed Disks.

2 comments

  1. The procedure you describe in this post will move a Managed Disk to a storage account, can’t I move a Managed Disks to another Managed Disks in another subscription? Thank you, nice post.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s