Forum Discussion
Revert to Azure Managed Disk snapshot on Azure VM
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.
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
- Sign in to the https://portal.azure.com/.
- Starting in the upper-left, click Create a resource and search for snapshot.
- In the Snapshot blade, click Create.
- Enter a Name for the snapshot.
- Select an existing https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview#resource-groups or type the name for a new one.
- Select an Azure datacenter Location.
- For Source disk, select the Managed Disk to snapshot.
- Select the Account type to use to store the snapshot. We recommend Standard_LRS unless you need it stored on a high performing disk.
- Click Create.
- Darrell LowranceSep 13, 2018Copper Contributor
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-sample-create-vm-from-snapshot?toc=%2fpowershell%2fmodule%2ftoc.json
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.
- Ravi shankar NallasamyOct 24, 2018Copper Contributor
Hope this helps,
https://www.francoisdelport.com/2017/12/creating-and-restoring-azure-virtual-machine-snapshots-for-managed-disks/
- Tom HarveySep 19, 2018Copper Contributor
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****************************************"