How to duplicate an Azure Virtual Machine
Over the course of time, there have been a number of ways to duplicate/replicate an Azure Virtual Machines. Some methods were time consuming, required an understanding of PowerShell or backup services, would require some form of reboot and would generally incur some kind of cost. However, I stumbled across a method a few days ago which allows you to take a snapshot of the virtual disk and then build a new disk with the snapshot. The result being a duplicated machine, without having to power down the machine or using a backup/restore method. All of which doesnt require an understanding of PowerShell or Backup services and doesnt incur much of a cost.
Please note that this method will require the use of Managed Disks!
Here are the steps that I took:
Summary
While this is a good way to duplicate a machine to do some testing on, or to make a repeatable server for demos, there are some obvious limitations. The one being that you have to do each server/disk one by one, which makes it a long process for large environments. Although, there are probably options to script this to make it quicker, it arguable that you might as well just right your whole environment as a script (Using JSON and DSC) and take the infrastructure as code approach. Also, from the looks of it, you can only apply a snapshot to a managed disk, and not a VHD file that is located in a storage account, further to this, you can only take a snapshot from a managed disk, so if you are not using managed disks to begin with then this method will not work for you.
While Storage Accounts do have snapshot functionality, there isn’t a way to restore this onto a new disk (even within the storage account itself), the snapshots can only be promoted to the original BLOB which allows for rollback of the original disk/file.
I hope this guide has been useful! This feature has helped me build repeatable servers for testing and demos which has saved me a lot of time and effort, rather than building and configuring a server from scratch!
Thanks for reading!
nice guide! most articles talk about using Azcopy and generalizing a VM to then redeploy, this is far simpler!
Thanks Aaron!
Generalising/Sysprepping a VM and capturing this as an image and deploying this to other VMs is the more cleaner way, as it removes machine specific details and only captures the configuration of the machine. This is needed when you deploy multiple machines in the same network. Whereas duplicating the underlying VHD will keep the user profiles, data and machine config so its good for a like for like duplication but not good for cloning a machine that would sit in the same network and cause potential conflicts.
One of the most succinct and accurate articles I have ever read. This saves anyone a lot of time and effort. I thank you very much.
Thanks Peter! Glad you liked it!
Would this work if I wanted to put the Azure copy on a vm in an on-prem environment?
I haven’t tried this, but my thoughts are you should be able to make a “copy” of the disk using a snapshot, then download the .vhdx file. I would need to investigate first!