Home

Revert to Azure Managed Disk snapshot on Azure VM

%3CLINGO-SUB%20id%3D%22lingo-sub-71250%22%20slang%3D%22en-US%22%3ERevert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-71250%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELooking%20for%20some%20assistance%20in%20reverting%20a%20Managed%20disk%20snapshot%20to%20an%20OS%20disk%20of%20the%20VM.%20Idealy%20i%20would%20like%20to%20do%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Detach%20existing%20OS%20managed%20disk%20from%20VM%3C%2FP%3E%3CP%3E2.%20Convert%20the%20snapshot%20to%20a%20managed%20disk%3C%2FP%3E%3CP%3E3.%20Attach%20new%20managed%20disk%20to%20VM%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20struggling%20at%20point%201.%20The%20Remove-AzureRMDisk%20cmdlet%20doesnt%20like%20the%20fact%20its%20currently%20attached.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20current%20way%20im%20achieving%20this%20is%20by%20deleting%20%2F%20recreating%20the%20VM%20with%20the%20new%20disk.%20Seems%20to%20work%20well%20but%20is%20getting%20complicated%20when%20more%20services%20are%20setup%20against%20this%20VM.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20suggestions%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-71250%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-277341%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-277341%22%20slang%3D%22en-US%22%3E%3CP%3EHope%20this%20helps%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.francoisdelport.com%2F2017%2F12%2Fcreating-and-restoring-azure-virtual-machine-snapshots-for-managed-disks%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.francoisdelport.com%2F2017%2F12%2Fcreating-and-restoring-azure-virtual-machine-snapshots-for-managed-disks%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-254192%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-254192%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20off%20-%20sorry%20for%20the%20late%20response.%20I've%20had%20a%20lot%20of%20requests%20for%20this%20script%20so%20hopefully%20it%20helps.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20the%20scripts%20we%20use.%20We%20do%20it%20slightly%20differently%20to%20the%20Microsoft%20docs%20by%20retaining%20the%20original%20components%2C%20nic%20%2F%20pip%20etc.%20Its%20also%20tailored%20to%20allow%20for%20one%20data%20disk%20as%20an%20automatic%20restore.%20You%20can%20amend%20as%20suits.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20sure%20this%20could%20be%20refined%20more%20but%20it%20does%20what%20we%20need%20it%20to.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Update%20Variables%3CBR%20%2F%3E%24location%20%3D%20%22Location%22%20%23Update%20if%20required%3CBR%20%2F%3E%24resourceGroupName%20%3D%20%22ResourceGroupName%22%20%23Update%20if%20required%3CBR%20%2F%3E%24vmName%20%3D%20%22VMName%22%20%23Update%20VMName%3CBR%20%2F%3E%24diagStorageAcc%20%3D%20%22DiagStorageAcct%22%20%23Update%20if%20required%3CBR%20%2F%3E%24snapshotName%20%3D%20%22OSDiskSnapshotNAme%22%20%23Update%20OS%20Disk%20SnapshotName%3CBR%20%2F%3E%24DataSnapshotName%20%3D%20%22DataDiskSnapshotName%22%20%23Update%20Data%20Disk%20SnapshotName%3CBR%20%2F%3E%24vmSize%20%3D%20'VMSize'%20%23Update%20if%20required%3CBR%20%2F%3E%3CBR%20%2F%3E%23Get%20Target%20VM%3CBR%20%2F%3E%24vm%20%3D%20Get-AzureRMVM%20-ResourceGroupName%20%24resourceGroupName%20-Name%20%24vmName%3CBR%20%2F%3E%23Shutdown%20the%20target%20VM%3CBR%20%2F%3EStop-AzureRmVM%20-ResourceGroupName%20%24resourceGroupName%20-Name%20%24vmName%20-Force%3CBR%20%2F%3E%3CBR%20%2F%3E%23Get%20existing%20NIC%20to%20use%20during%20re-create%3CBR%20%2F%3E%24NicID%20%3D%20%24vm.NetworkProfile.NetworkInterfaces.Id%3CBR%20%2F%3E%24VmId%20%3D%20%24vm.VmId%20%23Gets%20and%20sets%20VMId%20-%20Used%20to%20remove%20the%20diagnostics%20storage%20account.%3CBR%20%2F%3E%3CBR%20%2F%3E%23Get%20Boot%20Diagnostic%20storage%20container%20to%20be%20deleted%3CBR%20%2F%3ESet-AzureRmCurrentStorageAccount%20%E2%80%93ResourceGroupName%20%24resourceGroupName%20%E2%80%93StorageAccountName%20%24diagStorageAcc%3CBR%20%2F%3E%24diagContainer%20%3D%20Get-AzureStorageContainer%20%7C%20Where-Object%20%7B%20%24_.Name%20-like%20%22*%24VmId%22%20%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%23Get%20Managed%20OS%20Disk%20if%20Exists%3CBR%20%2F%3E%24ManagedDiskName%20%3D%20%24vm.StorageProfile.OsDisk.Name%3CBR%20%2F%3E%24ManagedDisk%20%3D%20Get-AzureRMDisk%20-ResourceGroupName%20%24resourceGroupName%20-DiskName%20%24ManagedDiskName%3CBR%20%2F%3E%3CBR%20%2F%3E%23Get%20Managed%20Data%20Disk%20if%20Exists%3CBR%20%2F%3E%24ManagedDataDiskName%20%3D%20%24vm.StorageProfile.DataDisks.Name%3CBR%20%2F%3EIf%20(%24ManagedDataDiskName)%20%7B%3CBR%20%2F%3E%24ManagedDataDisk%20%3D%20Get-AzureRMDisk%20-ResourceGroupName%20%24resourceGroupName%20-DiskName%20%24ManagedDataDiskName%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%23Remove%20VM%3CBR%20%2F%3ERemove-AzureRMVM%20-ResourceGroupName%20%24resourceGroupName%20-Name%20%24vmName%20-Force%3CBR%20%2F%3E%3CBR%20%2F%3E%23Remove%20boot%20Diagnostics%20storage%3CBR%20%2F%3EIf%20(%24diagContainer.Name)%20%7B%3CBR%20%2F%3ERemove-AzureStorageContainer%20-Name%20%24diagContainer.Name%20-Force%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%23Remove%20and%20Re-Create%20Managed%20OS%20Disk%3CBR%20%2F%3EIf%20(%24ManagedDisk)%20%7B%3CBR%20%2F%3ERemove-AzureRMDisk%20-ResourceGroupName%20%24resourceGroupName%20-DiskName%20%24ManagedDiskName%20-Force%3CBR%20%2F%3E%23Create%20New%20Disk%20Procedure%3CBR%20%2F%3E%24snapshot%20%3D%20Get-AzureRmSnapshot%20-SnapshotName%20%24snapshotName%20-ResourceGroupName%20%24resourceGroupName%3CBR%20%2F%3E%24snapshotID%20%3D%20%24snapshot.Id%3CBR%20%2F%3E%24diskConfig%20%3D%20New-AzureRmDiskConfig%20-AccountType%20Standard_LRS%20-Location%20%24location%20-CreateOption%20Copy%20-SourceResourceId%20%24snapshotID%3CBR%20%2F%3E%24diskName%20%3D%20%22%24vmName-osdisk%22%3CBR%20%2F%3E%24NewDisk%20%3D%20New-AzureRmDisk%20-DiskName%20%24diskName%20-Disk%20%24diskConfig%20-ResourceGroupName%20%24resourceGroupName%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%23Remove%20and%20Re-Create%20Managed%20Data%20Disk%3CBR%20%2F%3EIf%20(%24ManagedDataDiskName)%20%7B%3CBR%20%2F%3ERemove-AzureRMDisk%20-ResourceGroupName%20%24resourceGroupName%20-DiskName%20%24ManagedDataDiskName%20-Force%3CBR%20%2F%3E%23Create%20New%20Disk%20Procedure%3CBR%20%2F%3E%24DataSnapshot%20%3D%20Get-AzureRmSnapshot%20-SnapshotName%20%24DataSnapshotName%20-ResourceGroupName%20%24resourceGroupName%3CBR%20%2F%3E%24DataSnapshotID%20%3D%20%24DataSnapshot.Id%3CBR%20%2F%3E%24DataDiskConfig%20%3D%20New-AzureRmDiskConfig%20-AccountType%20Standard_LRS%20-Location%20%24location%20-CreateOption%20Copy%20-SourceResourceId%20%24DataSnapshotID%3CBR%20%2F%3E%24DataDiskName%20%3D%20%22%24vmName-datadisk%22%3CBR%20%2F%3E%24NewDataDisk%20%3D%20New-AzureRmDisk%20-DiskName%20%24DataDiskName%20-Disk%20%24DataDiskConfig%20-ResourceGroupName%20%24resourceGroupName%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%23Create%20New%20VM%20Procedure%3CBR%20%2F%3E%24Newvm%20%3D%20New-AzureRmVMConfig%20-VMName%20%24vmName%20-VMSize%20%24vmSize%3CBR%20%2F%3E%24Newvm%20%3D%20Add-AzureRmVMNetworkInterface%20-VM%20%24Newvm%20-Id%20%24NicID%3CBR%20%2F%3E%24osDisk%20%3D%20Get-AzureRMDisk%20-ResourceGroupName%20%24resourceGroupName%20-DiskName%20%24diskName%3CBR%20%2F%3E%24Newvm%20%3D%20Set-AzureRmVMOSDisk%20-VM%20%24Newvm%20-Name%20%24diskName%20-ManagedDiskId%20%24osDisk.Id%20-CreateOption%20Attach%20-Windows%20-Caching%20ReadWrite%3CBR%20%2F%3EIf%20(%24ManagedDataDiskName)%20%7B%3CBR%20%2F%3E%24dataDisk%20%3D%20Get-AzureRMDisk%20-ResourceGroupName%20%24resourceGroupName%20-DiskName%20%24DataDiskName%3CBR%20%2F%3E%24Newvm%20%3D%20Add-AzureRmVMDataDisk%20-VM%20%24Newvm%20-Name%20%24DataDiskName%20-CreateOption%20Attach%20-ManagedDiskId%20%24dataDisk.Id%20-Lun%200%20-Caching%20ReadOnly%3CBR%20%2F%3E%7D%3CBR%20%2F%3ENew-AzureRmVM%20-ResourceGroupName%20%24resourceGroupName%20-Location%20%24location%20-VM%20%24Newvm%3CBR%20%2F%3E%3CBR%20%2F%3EEcho%20%22****************************Complete****************************************%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-252470%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-252470%22%20slang%3D%22en-US%22%3E%3CP%3EYes%2C%20I've%20seen%20it.%26nbsp%3B%26nbsp%3BHowever%2C%20in%20order%20to%20revert%20back%20to%20the%20VM's%20original%20state%2C%20you%20must%20delete%20the%20original%20VM%2C%20then%20create%20a%20new%20VM%20from%20the%20snapshot%26nbsp%3Bby%20running%20a%20PS%20script%20and%20manually%20entering%20many%20required%20parameters.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fscripts%2Fvirtual-machines-windows-powershell-sample-create-vm-from-snapshot%3Ftoc%3D%252fpowershell%252fmodule%252ftoc.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Fscripts%2Fvirtual-machines-windows-powershell-sample-create-vm-from-snapshot%3Ftoc%3D%252fpowershell%252fmodule%252ftoc.json%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20process%20seems%20awfully%20involved%2C%20even%20risky%20and%20prone%20for%20mistakes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20we're%20looking%20for%20is%20something%20similar%20to%20VMWare%20where%20you%20can%20take%20a%20quick%20snapshot%20just%20before%20making%20changes%20to%20the%20VM%20(e.g.%20upgrade%20the%20OS%2Fapps%2C%20make%20config%20changes%2C%20etc).%26nbsp%3B%20If%20something%20fails%2C%20you%20can%20easily%20revert%20back%20to%20the%20VM's%20original%20Snapshot%20state%20by%20simple%20clicking%20a%20button.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20considering.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-217761%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-217761%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Can%20you%20please%20send%20me%20the%20script%20too.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-213810%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-213810%22%20slang%3D%22en-US%22%3ETom%20Harvey%2C%20Please%20send%20me%20your%20script.%3CBR%20%2F%3EI%20appreciate%20it%3CBR%20%2F%3ERobin%20Hood%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-198062%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-198062%22%20slang%3D%22en-US%22%3EHi%20Panos%2C%3CBR%20%2F%3EI%20haven't%20spent%20any%20more%20time%20on%20this%20since%20my%20post.%20I%20wrote%20a%20script%20that%20will%20recreate%20the%20Disk%20from%20the%20snapshot%20and%20then%20recreate%20the%20VM%20using%20the%20new%20Disk.%20It%20deletes%20the%20VM%20but%20retains%20the%20VM%20components%2C%20nic%2C%20pip%20etc.%20The%20whole%20process%20takes%20about%205%20minutes%20which%20isn't%20too%20bad.%20Sometimes%20when%20the%20VM%20comes%20back%20up%20its%20lost%20its%20domain%20account%20although%20it's%20an%20easy%20fix%20and%20happens%201%20out%20of%20every%2010%20restores%20old%20say.%20Needless%20to%20say%2C%20the%20process%20is%20working%20for%20us%20I'm%20just%20surprised%20there%20isn't%20an%20easier%20option.%20On%20your%20note%2C%20I'm%20not%20sure%20you%20can%20detach%20%2F%20attach%20an%20os%20Disk%20from%20a%20VM%2C%20not%20sure%20I've%20tried%20that%20although%20could%20be%20a%20better%20option.%3CBR%20%2F%3E%3CBR%20%2F%3EI'm%20happy%20to%20share%20my%20script%20for%20anyone%20interested%2C%20been%20a%20few%20comments%20on%20here%20since%20my%20last%20post.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-196843%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-196843%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Tom.%20I%20have%20a%20similar%20problem%20and%20I%20came%20across%20your%20message.%20I%20think%20that%20the%20proper%20thing%20to%20do%20would%20be%20to%20first%20stop%2Fdeallocate%20the%20VM.%20Then%20you%20should%20be%20allowed%20to%20detach%20the%20old%20OS%20disk%20from%20its%20configuration%20and%20attach%20the%20new%20OS%20disk%20to%20it%20(the%20one%2C%20that%20you%20have%20created%20from%20the%20snapshot)%20and%20startup%20the%20VM.%20I%20have%20not%20had%20time%20to%20test%20this%20yet%20since%20my%20problem%20is%20more%20complicated%20than%20yours%20(my%20VM%20is%20a%20rather%20%22fat%22%20SQL%20Server%20instance%20with%20two%20-2-%20data%20disks%20attached%20to%20it%20in%20addition%20to%20its%20OS%20disk)%20-%20I%20hope%20that%20I%20will%20be%20able%20to%20test%20it%20some%20time%20later%20-%20please%2C%20let%20me%20know%20of%20your%20findings%20if%20you%20use%20this%20approach.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192624%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192624%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--1327772845%22%20id%3D%22toc-hId-1704826431%22%3EHave%20you%20guys%20seen%20this%3F%20but%20this%20only%20available%20in%20Managed%20Disk%3C%2FH2%3E%3CH2%20id%3D%22toc-hId--440269164%22%20id%3D%22toc-hId--847330530%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Flinux%2Fsnapshot-copy-managed-disk%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-machines%2Flinux%2Fsnapshot-copy-managed-disk%3C%2FA%3E%3C%2FH2%3E%3CH2%20id%3D%22toc-hId-447234517%22%20id%3D%22toc-hId-895479805%22%3EUse%20Azure%20portal%3C%2FH2%3E%3COL%3E%3CLI%3ESign%20in%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20portal%3C%2FA%3E.%3C%2FLI%3E%3CLI%3EStarting%20in%20the%20upper-left%2C%20click%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ECreate%20a%20resource%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20search%20for%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Esnapshot%3C%2FSTRONG%3E.%3C%2FLI%3E%3CLI%3EIn%20the%20Snapshot%20blade%2C%20click%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ECreate%3C%2FSTRONG%3E.%3C%2FLI%3E%3CLI%3EEnter%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EName%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efor%20the%20snapshot.%3C%2FLI%3E%3CLI%3ESelect%20an%20existing%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-resource-manager%2Fresource-group-overview%23resource-groups%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EResource%20group%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eor%20type%20the%20name%20for%20a%20new%20one.%3C%2FLI%3E%3CLI%3ESelect%20an%20Azure%20datacenter%20Location.%3C%2FLI%3E%3CLI%3EFor%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESource%20disk%3C%2FSTRONG%3E%2C%20select%20the%20Managed%20Disk%20to%20snapshot.%3C%2FLI%3E%3CLI%3ESelect%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAccount%20type%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20use%20to%20store%20the%20snapshot.%20We%20recommend%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EStandard_LRS%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eunless%20you%20need%20it%20stored%20on%20a%20high%20performing%20disk.%3C%2FLI%3E%3CLI%3EClick%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ECreate%3C%2FSTRONG%3E.%3C%2FLI%3E%3C%2FOL%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-176957%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-176957%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EI%20came%20here%20looking%20for%20the%20exact%20same%20solution%20to%20the%20original%20poster's%20question%3A%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%22Actually%20no.%20I'm%20attempting%20to%20restore%20the%20snapshot%20in%20a%20similar%20way%20you%20would%20apply%20a%20Hyper-V%20checkpoint.%20I%20would%20prefer%20not%20to%20delete%20and%20recreate%20the%20Azure%20VM%20from%20the%20snapshot.%20Instead%20i%20was%20wondering%20if%20there%20is%20a%20way%20i%20can%20convert%20the%20snapshot%20to%20a%20disk%20and%20attach%20it%20back%20to%20the%20existing%20VM....%22%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3ELeft%20disappointed.%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EWhy%20does%20Microsoft%20make%20it%20easy%20to%20create%20a%20snapshot%20of%20disks%20in%20the%20Azure%20portal%2C%20but%20not%20provide%20any%20obvious%20way%20to%20revert%20to%20these%20snapshots%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-72111%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-72111%22%20slang%3D%22en-US%22%3E%3CP%3EThats%20what%20i%20love%20about%20azure%2C%20so%20many%20ways%20to%20achieve%20the%20same%20thing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20Sunit%2C%20i%20think%20Azure%20Backup%20is%20a%20bit%20excessive%20for%20my%20needs.%20The%20VM%3Bs%20in%20question%20are%20all%20DEV%20boxes%2C%20we%20need%20a%20quick%20procedure%20to%20take%20a%20point%20in%20time%20backup%20pre-deployment.%20This%20would%20also%20serve%20as%20a%20fast%20restore%20point%20if%20required.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20we%20are%20currently%20doing%20by%20using%20managed%20disks%20with%20snapshot%20capabilities%2C%20then%20recreating%20a%20disk%20from%20the%20snapshot%20and%20then%20re-creating%20the%20VM%20from%20the%20new%20disk%20is%20serving%20its%20purpose.%20I%20think%20we%20will%20stick%20with%20this%20approach%20for%20now%20as%20to%20not%20introduce%20additional%20costs.%20Its%20actually%20a%20fast%20process%20when%20the%20powershell%20scripts%20are%20all%20in%20order%20too.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-71900%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-71900%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Tom%2C%3C%2FP%3E%3CP%3Ein%20this%20scenario%26nbsp%3Buse%20backup%20feature%20to%20take%20Snapshot%20backup%20you%20may%20have%20to%20pay%20some%20more%20money%20for%20backup%20Feature.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheck%20this%20URL%20for%20more%20details%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbackup%2Fbackup-azure-vms%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fbackup%2Fbackup-azure-vms%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F14897iCA9AFF979796912F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EBest%3C%2FP%3E%3CP%3ESunit%20Patil%3C%2FP%3E%3CP%3ESkype%3A%20Sunitonline%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-71779%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-71779%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sunit%2C%3C%2FP%3E%3CP%3EActually%20no.%20I'm%20attempting%20to%20restore%20the%20snapshot%20in%20a%20similar%20way%20you%20would%20apply%20a%20Hyper-V%20checkpoint.%20I%20would%20prefer%20not%20to%20delete%20and%20recreate%20the%20Azure%20VM%20from%20the%20snapshot.%20Instead%20i%20was%20wondering%20if%20there%20is%20a%20way%20i%20can%20convert%20the%20snapshot%20to%20a%20disk%20and%20attach%20it%20back%20to%20the%20existing%20VM....%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-71347%22%20slang%3D%22en-US%22%3ERe%3A%20Revert%20to%20Azure%20Managed%20Disk%20snapshot%20on%20Azure%20VM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-71347%22%20slang%3D%22en-US%22%3EHi%2C%20Do%20you%20want%20to%20use%20this%20VM%20as%20master%20Image%3F%20are%20you%20going%20to%20create%20multiple%20VM%20from%20this%20image%3F%20Best%20Sunit%20Patil%3C%2FLINGO-BODY%3E
Tom Harvey
Occasional Contributor

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?

13 Replies
Hi, Do you want to use this VM as master Image? are you going to create multiple VM from this image? Best Sunit Patil

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....

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

image.png

Best

Sunit Patil

Skype: Sunitonline

Thats what i love about azure, so many ways to achieve the same thing.

 

Thanks Sunit, i think Azure Backup is a bit excessive for my needs. The VM;s in question are all DEV boxes, we need a quick procedure to take a point in time backup pre-deployment. This would also serve as a fast restore point if required.

 

What we are currently doing by using managed disks with snapshot capabilities, then recreating a disk from the snapshot and then re-creating the VM from the new disk is serving its purpose. I think we will stick with this approach for now as to not introduce additional costs. Its actually a fast process when the powershell scripts are all in order too.

Highlighted

I came here looking for the exact same solution to the original poster's question:

"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...."


Left disappointed.

 


Why does Microsoft make it easy to create a snapshot of disks in the Azure portal, but not provide any obvious way to revert to these snapshots?


 

 

Have you guys seen this? but this only available in Managed Disk

https://docs.microsoft.com/en-us/azure/virtual-machines/linux/snapshot-copy-managed-disk

Use Azure portal

  1. Sign in to the Azure portal.
  2. Starting in the upper-left, click Create a resource and search for snapshot.
  3. In the Snapshot blade, click Create.
  4. Enter a Name for the snapshot.
  5. Select an existing Resource group or type the name for a new one.
  6. Select an Azure datacenter Location.
  7. For Source disk, select the Managed Disk to snapshot.
  8. Select the Account type to use to store the snapshot. We recommend Standard_LRS unless you need it stored on a high performing disk.
  9. Click Create.

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.

Hi 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.
Tom Harvey, Please send me your script.
I appreciate it
Robin Hood

Hi Can you please send me the script too.

Yes, I've seen it.  However, in order to revert back to the VM's original state, you must delete the original VM, then create a new VM from the snapshot by running a PS script and manually entering many required parameters. 

 

https://docs.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-windows-powershell-...

 

This process seems awfully involved, even risky and prone for mistakes.

 

What we're looking for is something similar to VMWare where you can take a quick snapshot just before making changes to the VM (e.g. upgrade the OS/apps, make config changes, etc).  If something fails, you can easily revert back to the VM's original Snapshot state by simple clicking a button.

 

Thanks for considering.

 

First off - sorry for the late response. I've had a lot of requests for this script so hopefully it helps.

 

Here's the scripts we use. We do it slightly differently to the Microsoft docs by retaining the original components, nic / pip etc. Its also tailored to allow for one data disk as an automatic restore. You can amend as suits.

 

I'm sure this could be refined more but it does what we need it to.

 

#Update Variables
$location = "Location" #Update if required
$resourceGroupName = "ResourceGroupName" #Update if required
$vmName = "VMName" #Update VMName
$diagStorageAcc = "DiagStorageAcct" #Update if required
$snapshotName = "OSDiskSnapshotNAme" #Update OS Disk SnapshotName
$DataSnapshotName = "DataDiskSnapshotName" #Update Data Disk SnapshotName
$vmSize = 'VMSize' #Update if required

#Get Target VM
$vm = Get-AzureRMVM -ResourceGroupName $resourceGroupName -Name $vmName
#Shutdown the target VM
Stop-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName -Force

#Get existing NIC to use during re-create
$NicID = $vm.NetworkProfile.NetworkInterfaces.Id
$VmId = $vm.VmId #Gets and sets VMId - Used to remove the diagnostics storage account.

#Get Boot Diagnostic storage container to be deleted
Set-AzureRmCurrentStorageAccount –ResourceGroupName $resourceGroupName –StorageAccountName $diagStorageAcc
$diagContainer = Get-AzureStorageContainer | Where-Object { $_.Name -like "*$VmId" }

#Get Managed OS Disk if Exists
$ManagedDiskName = $vm.StorageProfile.OsDisk.Name
$ManagedDisk = Get-AzureRMDisk -ResourceGroupName $resourceGroupName -DiskName $ManagedDiskName

#Get Managed Data Disk if Exists
$ManagedDataDiskName = $vm.StorageProfile.DataDisks.Name
If ($ManagedDataDiskName) {
$ManagedDataDisk = Get-AzureRMDisk -ResourceGroupName $resourceGroupName -DiskName $ManagedDataDiskName
}

#Remove VM
Remove-AzureRMVM -ResourceGroupName $resourceGroupName -Name $vmName -Force

#Remove boot Diagnostics storage
If ($diagContainer.Name) {
Remove-AzureStorageContainer -Name $diagContainer.Name -Force
}

#Remove and Re-Create Managed OS Disk
If ($ManagedDisk) {
Remove-AzureRMDisk -ResourceGroupName $resourceGroupName -DiskName $ManagedDiskName -Force
#Create New Disk Procedure
$snapshot = Get-AzureRmSnapshot -SnapshotName $snapshotName -ResourceGroupName $resourceGroupName
$snapshotID = $snapshot.Id
$diskConfig = New-AzureRmDiskConfig -AccountType Standard_LRS -Location $location -CreateOption Copy -SourceResourceId $snapshotID
$diskName = "$vmName-osdisk"
$NewDisk = New-AzureRmDisk -DiskName $diskName -Disk $diskConfig -ResourceGroupName $resourceGroupName
}

#Remove and Re-Create Managed Data Disk
If ($ManagedDataDiskName) {
Remove-AzureRMDisk -ResourceGroupName $resourceGroupName -DiskName $ManagedDataDiskName -Force
#Create New Disk Procedure
$DataSnapshot = Get-AzureRmSnapshot -SnapshotName $DataSnapshotName -ResourceGroupName $resourceGroupName
$DataSnapshotID = $DataSnapshot.Id
$DataDiskConfig = New-AzureRmDiskConfig -AccountType Standard_LRS -Location $location -CreateOption Copy -SourceResourceId $DataSnapshotID
$DataDiskName = "$vmName-datadisk"
$NewDataDisk = New-AzureRmDisk -DiskName $DataDiskName -Disk $DataDiskConfig -ResourceGroupName $resourceGroupName
}

#Create New VM Procedure
$Newvm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$Newvm = Add-AzureRmVMNetworkInterface -VM $Newvm -Id $NicID
$osDisk = Get-AzureRMDisk -ResourceGroupName $resourceGroupName -DiskName $diskName
$Newvm = Set-AzureRmVMOSDisk -VM $Newvm -Name $diskName -ManagedDiskId $osDisk.Id -CreateOption Attach -Windows -Caching ReadWrite
If ($ManagedDataDiskName) {
$dataDisk = Get-AzureRMDisk -ResourceGroupName $resourceGroupName -DiskName $DataDiskName
$Newvm = Add-AzureRmVMDataDisk -VM $Newvm -Name $DataDiskName -CreateOption Attach -ManagedDiskId $dataDisk.Id -Lun 0 -Caching ReadOnly
}
New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $location -VM $Newvm

Echo "****************************Complete****************************************"

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
16 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
11 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies