Tuesday, June 30, 2020

Copy a VHD to a Storage Account on another subscription


This process was used to copy a virtual hard disk (VHD) from one Azure account/subscription to another separate account/subscription.

This is based on this article http://azurecentric.com/2018/11/how-to-migrate-azure-managed-disk-to-different-subscription-and-region-part-ii/ There is some variation such as using a different AzCopy version.
  • Prep the Managed Disk VHD as a copy source by creating a Shared Access Signature (SAS) Token URL.  Select the Managed Disk and generate the SAS URL from the Disk Export Blade.  Copy the string out for use later. You could use the string in a browser to download the VHD.  The SAS URL is temporary and only lasts a limited time.
  • Logon to the Destination account/subscription and create a storage account if necessary.  It is very likely there already is a storage account as they are created automatically with VMs.  In the Storage Account create a new container to act as the copy destination. Give it a name and set the Public Access Level to Blob (Binary Large OBject)
  • Once the container has been created check that your account has appropriate roles assigned to manage it.  Assign a role to your account if necessary.  Storage Blob Data Owner role can be used.
  • Obtain the destination URL of the container from the properties blade.  Copy the string out for use later.
  • Launch a VM and obtain the AzCopy utility here https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10
  • In a command window run AzCopy login follow the instructions to open a URL in a browser and enter a code.  The Azure account of the destination can then be authenticated.
  • To being the copy enter
    AzCopy copy "<SAS URL>" "<Destination URL>/diskname.vhd"
    The file transfer status will be shown in the command window and a log file will also be generated in the user profile.
  • Once complete view the container contents to see the newly arrived diskname.vhd file which is a page blob object
  •  Create a new managed disk, size it correctly and use Storage blob as the source.  Browse to the diskname.vhd page blob in the Storage Account container.  Then create the disk from the diskname.vhd page blob
  • Once the disk is created it can be attached to a VM.  The diskname.vhd page blob can now be deleted.
also see