Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

azure - Restoring from a snapshot

I have created a snapshot of my VM in Azure a few weeks ago using the script below.

$mydiskId = $(az vm show  --resource-group "myResourceGroup" --name "myVM" --query "storageProfile.osDisk.managedDisk.id")
az snapshot create --name "myTestSnapShot" --resource-group --resource-group "MW-ENGINEERING-USEAST" --source $mydiskId

Now I am looking to restore that snapshot. Googling provides many links such as this. However, these talk about creating a recovery point/storage account as well. This left me confused as to when creating the snapshot, did I miss any of those steps. None of the steps described in the document for restoring the snapshot uses any id of the snapshot I created through the commands above. Can someone please help me understand what did I miss? TIA

question from:https://stackoverflow.com/questions/66065249/restoring-from-a-snapshot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your linked document is to restore the whole VM or individual files. Before this, you need to enable Azure Backup to create recovery points that are stored in geo-redundant recovery vaults.

If you don't enable Azure Backup, consider there is a scenario where you want to get certain data from the snapshot without restoring the complete VM. In that case, one of the excellent ways is to create a VM from the snapshot and get the specific data that you need. In this way, you can create a different VM name and get the original data from the source VM. You can read this blog for more details.

To use Azure CLI to create an Azure VM from snapshots, read this for more details.

#Create snapshot
osdiskid=$(az vm show 
   -g myResourceGroupDisk 
   -n myVM 
   --query "storageProfile.osDisk.managedDisk.id" 
   -o tsv)

az snapshot create 
    --resource-group myResourceGroupDisk 
    --source "$osdiskid" 
    --name osDisk-backup

#Create disk from snapshot
az disk create 
   --resource-group myResourceGroupDisk 
   --name mySnapshotDisk 
   --source osDisk-backup

#Create a new virtual machine from the snapshot disk.
az vm create 
    --resource-group myResourceGroupDisk 
    --name myVM 
    --attach-os-disk mySnapshotDisk 
    --os-type linux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...