From the #Cloud: How to snapshot an Azure Virtual Machine

By | March 25, 2016

If you’re looking for a way to snapshot Azure VMs you will probably have established that unlike pureplay virtualisation (such as Hyper-V or ESXi on-premises) there is no simple snapshot option for a Azure VMs.

It’s possible that Microsoft might add this as a native portal option, but for now, the closest you can get to the convenience of a snapshot is to perform a VHD based point in time restore of a VM in it’s entirety. Yes, you read it correctly – in its entirety!

The process is actually pretty simple:

  • Phase 1: Create “snapshot”
    • establish some basics (connect to your subscription, get VM information, etc.)
    • backup the VM disk(s) to a backup container
    • export the VM config to local machine (and keep safe)
      • this step can be performed before you tinker if you’re going to tinker with VM config or after if not
  • Phase 2: Do whatever you want to do that necessitated you performing a snapshot
  • Phase 3: Restore “snapshot” if required
    • blow away the existing VM (yep. BLOW IT AWAY!)
    • blow away the existing VM disk(s)
    • restore the “snapshot” VM disk(s) to the source container
    • re-provision the VM using the previously exported config file
    • wipe your brow

Although slightly long-winded when compared to the simplicity of native virtualisation snapshots this approach is working nicely for me with demo environments that I need to reset to a known state.

Couple of caveats:

  • I’ve broken the functions out across two ps1 files so it’s simpler to view
  • I’ve built in a check to ensure that a VM being exported is stopped but not deallocated, this is for my needs as I use static IP, site-to-site VPNs and cloud services for demo purposes which I want to control and re-add when restoring the “snapshot”
  • You’ll need to change anything relevant to folders, files and subscriptions, of course

As is now the norm, you fan find the goodies over in GitHub at http://github.com/sebmatthews/powershell

Use with caution, and enjoy!

more to follow…

 

Leave a Reply

Your email address will not be published. Required fields are marked *