How to revert an azure disk back to its former snapshot?

 ̄綄美尐妖づ 提交于 2020-02-24 11:39:41

问题


I have a VM in azure, and via the portal have selected its Disk, and created a snapshot of it. How do I now revert back to that snapshot for the Disk (via portal or CLI)?

I'm not looking to create new disks or VMs from the snapshot, just revert back.


回答1:


How do I now revert back to that snapshot for the Disk (via portal or CLI)?

Do you mean you want to use this snapshot to rollback your system?

Unfortunately, for now Azure does not support this, we can't use snapshot to revert back.

In Azure, we can't revert back Azure VM directly, we should create disk or VM from that snapshot.

By default, snapshot used for Azure backup. In Azure recovery services, we can restore VMs from the snapshot. Restore this VM was create a new VM with this OS disk, not rollback.




回答2:


I did it successfully with Azure PowerShell, using Set-AzVMOSDisk. There is a module which unfortunately can only restore the snapshots that it created, but its code demonstrates how it works.

Summarised:

Get-AzSnapshot -ResourceGroupName "..." # to find the Disk ID
$vm = Get-AzVM -Name "..."
$old_disk = Get-AzDisk -Name $vm.StorageProfile.OsDisk.name
$diskconf = New-AzDiskConfig -AccountType $old_disk.sku.name -Location $old_disk.Location -SourceResourceId "Id of the disk" -CreateOption Copy
$newdisk = NewAzDisk -Disk $diskconf -ResourceGroupName "..." -DiskName "OS_disk_$((New-Guid).ToString())"
Set-AzVMOSDisk -VM $vm -ManagedDiskId $newdisk.Id -Name $newdisk.Name
Update-AzVM -ResourceGroupName "..." -VM $vm


来源:https://stackoverflow.com/questions/46811062/how-to-revert-an-azure-disk-back-to-its-former-snapshot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!