Search This Blog

Tuesday, January 13, 2015

Azure - Copy VM disk from one Azure Storage account to another (across regions)

OK, its been a while... A quick article written at work so forgive bad english etc... as I have not reread/proof read etc... it... :p

Recently had to move a VM from a US Azure region to an Australian Region... Thought this would have been an easy task from within the Azure web portal (be it the current manage.windowsazure.com or the preview portal portal.azure.com), however whilst not complicated its a little more involved than just copying/moving the vhd from one storage account to another.

Below is a quick account of this process, it is summarised as I want to ensure I can quickly refresh myself next time, I include all references I used at the end.

Some background...
When you create a VM you actually are using 2 azure services, virtual networking and storage. Now to improve performance these are hosted in the same region.

Steps
1. Stop the VM
2. Review the disks the VM uses in the azure portal (on the dashboard tab), you will need this info later on.
3. Delete the VM, but retain the disks. - Important!! :)
4. Kick off a server side copy
5. Create disk from copied blob. (after a copy the vhd file is just a blob, azure does not see it as a disk initially) - this part screwed me over, as I did the copy once and thought I had done something wrong as the vhd would not appear in the "my disks" section of the VM image gallery, and I actually deleted the vhds... :(   Its all a learning experience!
6. Create VM from newly copied files.

There are 3 ways I found to perform this process

  • Powershell
  • azcopy
  • Azure Explorer (by cerebata) - free at the time of writing this article. There maybe other 3rd party tools that can achieve the same 

I am going to skip the powershell, as that was too convoluted for me to repeat for a number of files. I provide reference to an microsoft article that includes powershell scripts, please note that I didnot try this so I don't know if it works. I used the azcopy on this page and it didnot work, so whether the powershell script works I can't say.
http://azure.microsoft.com/blog/2014/10/22/migrate-azure-virtual-machines-between-storage-accounts/

Steps 1,2,3
Ok, I am assuming you have some familiarity with Azure portal, and can stop and review the disks used by a VM. So once you have done this delete the VM but retain the disks (important :) )


Step 4
azcopy
Now as I state above I used the article for a starter, but the version of azcopy i got didnot like the syntax in that article. I include the syntax that worked for me below.
azcopy is a downloadable command line tool, once installed you can add the installation folder to the path environment variable and use azcopy easily from the command prompt.

azcopy /Source:[containerurl] /Dest:[containerurl] /SourceKey:[access key] /DestKey:[access key] /Pattern: [filename] 
(/S recursive optional, please see note below)

note: Using wilcards is dependent on the source (if local filesystem then wildcards can be used), if a blob container then pattern mathching is exact, except when using recursive (/S) then the pattern is used as a prefix match. i.e /Pattern abc /S will match abc.txt, abcd.txt, abcFDKF.txt.

The access keys you can get from the primary page of the storage tab in azure portal (Manage Access Keys link at bottom of page).
The container urls can be copied from the containers tab of the individual storage accounts.
The filename, is the name of the disk you looked at earlier.

azcopy will sit active, and give you updates on the progress (in terms of number of files) so in this case if you are just doing one file then you will just get the copy speed updated, until the file is copied.

Azure Explorer
http://www.cerebrata.com/products/azure-explorer/introduction
Download and install the tool.
Run the application, and under the file menu click "Add Connection"
Enter the storage account name and the access key.
Repeat for both the source and destination accounts.

Once added you should be able to use the tool in a similar manner to Windows Explorer. Copying moving files between accounts and also to your local machine

note: If you try to move a file, then you may need to break the lease, to get it to complete the move. I had the move error with a lease error. It actually copied the file, so I assume the last part of the move is to delete the source, with failed due to the lease.

Step 5
The copy of all necessary disks is now complete. We need to make the copied files into disks (otherwise they will not be listed under the "My Disks" section in the VM image gallery.

Go to the Virtual Machine section in Azure portal, and select disks. Now click create (down the bottom of the page). Give the disk s name, then use the browse tool (click on the image of the folder) and browse to the copied vhd. If its the OS disk tick the checkbox to indicate it contains an OS.
Repeat for any other files you want to tell azure storage are disks...

Step 6
Now go through the normal process of creating a Virtual machine, however in the image gallery select "My Disks", any unassociated disks with an OS should be listed and if all has gone well the new disks should be available.


References:
http://azure.microsoft.com/blog/2014/10/22/migrate-azure-virtual-machines-between-storage-accounts/
http://azure.microsoft.com/en-us/documentation/articles/storage-use-azcopy/#install
http://blogs.msdn.com/b/windowsazurestorage/archive/2012/06/12/introducing-asynchronous-cross-account-copy-blob.aspx
http://www.cerebrata.com/products/azure-explorer/introduction

Share/Bookmark

No comments:

Post a Comment