whoami
whoami

Reputation: 1899

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

Upvotes: 1

Views: 1240

Answers (1)

Nancy Xiong
Nancy Xiong

Reputation: 28204

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

Upvotes: 2

Related Questions