Managing Demo environment with Managed Disk Snapshot

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

Hello folks,

 

I have been doing some setups for demos on migrating VM to Azure.  In good “cooking show” fashion I needed to have my environment ready to be reset so I can run the demo again.  Well, instead of redeploying the entire environment I decided to use VM snapshots to help me out.  Turns out it was a lot faster than re-deploying and very easy to setup.

NOTE:  This is not a new feature.  This has been available since early 2020.

 

My VMs are all using managed disks since Managed Disks are block-level storage volumes that are managed by Azure.  With managed disks, all you do is specify the disk size, the disk type, and provision the disk. Once you provision the disk, Azure handles the rest.  The available types of disks are ultra-disks, premium solid-state drives (SSD), standard SSDs, and standard hard disk drives (HDD).  For information about each individual disk type, see Select a disk type for IaaS VMs.

 

Managed disks are designed for 99.999% availability.  Managed disks achieve this by providing you with three replicas of your data.  If one or even two replicas experience issues, the remaining replicas help ensure persistence of your data.

Incremental Snapshots

Using snapshots in your production environments allows you to setup a backup and disaster recovery solutions for Managed Disks that fits your needs.  You can copy only changed data between two snapshots across regions, thus reducing time and cost for backup and disaster recovery.

 

When using incremental snapshots, you can read the data of incremental snapshots or restore disks from them as soon as they are created. Which make my life a lot easier to reset my demo environment.

 

snapshot-1.png

Creating My Snapshots

Once I’ve setup my environment to mimic an on-prem situation I want to migrate o simply execute a PowerShell script to create a snapshot for all the disks in my resource groups.  The process is simple, and it can be done using

  • Azure CLI
  • PowerShell
  • The Portal
  • Or through an ARM template.

Here is my VERY simple script.  I could have done it in the portal, but I found that I would miss some disks.  This way I can’t miss any.

 

 

 

 

$managedDisks = Get-AzDisk foreach ($md in $managedDisks) { $resourceGroupName = "Azure-Managed-Disk-Demo" $snapshotName = "$($md.name)_Snapshot" # Get the disk that you need to backup by creating an incremental snapshot $yourDisk = Get-AzDisk -DiskName $md.name -ResourceGroupName $resourceGroupName Write-Host "Creating Snapshot for Managed Disk: $($md.name)" $snapshotConfig=New-AzSnapshotConfig -SourceUri $yourDisk.Id -Location $yourDisk.Location -CreateOption Copy -Incremental $null = New-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -Snapshot $snapshotConfig }

 

 

 

 

 

Restoring from a Snapshot

Now, the whole point of this was to allow me to walk-back changes I made to my environment so I could do it again.  This requirement presumes that I will need to restore these snapshots.  I purposely did not script that part so I could pick and choose what disk I restore from the snapshot. 

Now I used the portal for this.  However, as for the creation of the snapshot, you can use your preferred method from the following:

  • Azure CLI
  • PowerShell
  • The Portal

1- In my Resource Group I simply create a new disk from the snapshot I need restoring

 

snapshot-2.png

 

snapshot-3.png

 

 

2- Once the disk is created, all is needed it to “swap” the disk on the running VM (again this can be done using your preferred method).  I use the portal (for now).  You need to navigate to your VM, select Disk from the management blade, and click on “Swap OS disk” and pick the disk we created earlier.  The VM will shut down and will be deallocated (so you will have to restart it manually) and the disk will replace the current disk.

 

snapshot-4.png

snapshot-5.png

snapshot-6.png

Anyways, I just thought this was easier than redeploying VMs over and over.  Let me know if you have any questions or scenarios, you’d like us to cover.

 

Cheers!

 

Pierre

 

 

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.