Forum Discussion
Tom Harvey
May 18, 2017Copper Contributor
Revert to Azure Managed Disk snapshot on Azure VM
Hi All,
Looking for some assistance in reverting a Managed disk snapshot to an OS disk of the VM. Idealy i would like to do the following:
1. Detach existing OS managed disk from VM
2. Convert the snapshot to a managed disk
3. Attach new managed disk to VM
I'm struggling at point 1. The Remove-AzureRMDisk cmdlet doesnt like the fact its currently attached.
The current way im achieving this is by deleting / recreating the VM with the new disk. Seems to work well but is getting complicated when more services are setup against this VM.
Any suggestions?
- MayankagarCopper ContributorYou my refer to this powershell script to take the azure vm snapshot and to restore a vm from the snapshot
https://www.magicpowershell.com/2022/10/azure-vm-snapshot-and-restore-with-powershell.html - Shane CurtisCopper Contributor
Tom Harvey These instructions worked well for me: https://www.makak.ch/azure-restore-vm-disk-from-a-snapshot/
- Tom HarveyCopper Contributor
Shane Curtis Thanks Shane, The swap OS function was not in place when i wrote this procedure. We have now reverted back to un-managed disks as managed was becoming too expensive for the amount we had.
- Panos TsapralisCopper Contributor
Hi Tom. I have a similar problem and I came across your message. I think that the proper thing to do would be to first stop/deallocate the VM. Then you should be allowed to detach the old OS disk from its configuration and attach the new OS disk to it (the one, that you have created from the snapshot) and startup the VM. I have not had time to test this yet since my problem is more complicated than yours (my VM is a rather "fat" SQL Server instance with two -2- data disks attached to it in addition to its OS disk) - I hope that I will be able to test it some time later - please, let me know of your findings if you use this approach.
- Tom HarveyCopper ContributorHi Panos,
I haven't spent any more time on this since my post. I wrote a script that will recreate the Disk from the snapshot and then recreate the VM using the new Disk. It deletes the VM but retains the VM components, nic, pip etc. The whole process takes about 5 minutes which isn't too bad. Sometimes when the VM comes back up its lost its domain account although it's an easy fix and happens 1 out of every 10 restores old say. Needless to say, the process is working for us I'm just surprised there isn't an easier option. On your note, I'm not sure you can detach / attach an os Disk from a VM, not sure I've tried that although could be a better option.
I'm happy to share my script for anyone interested, been a few comments on here since my last post.- Deleted
Hi Can you please send me the script too.
- Sunit PatilBrass ContributorHi, Do you want to use this VM as master Image? are you going to create multiple VM from this image? Best Sunit Patil
- Tom HarveyCopper Contributor
Hi Sunit,
Actually no. I'm attempting to restore the snapshot in a similar way you would apply a Hyper-V checkpoint. I would prefer not to delete and recreate the Azure VM from the snapshot. Instead i was wondering if there is a way i can convert the snapshot to a disk and attach it back to the existing VM....
- Sunit PatilBrass Contributor
Hi Tom,
in this scenario use backup feature to take Snapshot backup you may have to pay some more money for backup Feature.
Check this URL for more details
https://docs.microsoft.com/en-us/azure/backup/backup-azure-vms
Best
Sunit Patil
Skype: Sunitonline