Home / Azure

AzureRunbookIntermediate

Sev1: Production Azure VM deleted by mistake. Recreate it from its disks or from backup

A production VM was deleted. If its disks survived, recreate the VM on them in minutes. If they didn't, restore from Azure Backup or snapshots, then rebuild the IP, identity, extensions and protection.

Deepak Bhardwaj7 min read

Applies toAzure Virtual Machines (Windows and Linux) on managed disks, Gen1/Gen2 and Trusted Launch, Azure Backup (Recovery Services vault), Azure CLI 2.60+

Symptoms

  • A server is gone from the portal; its app, database or file share is down; monitoring shows the host as unreachable.
  • The activity log has Microsoft.Compute/virtualMachines/delete, often from a cleanup script, a Terraform plan that replaced the VM, or someone deleting the wrong resource.

How fast you recover depends on what was deleted with the VM:

What survived Recovery path Typical time
OS disk, data disks and NIC Recreate the VM on the existing disks and NIC Minutes
Disks only (NIC deleted) Recreate the VM on the disks with a new NIC and the same private IP Minutes
Nothing, but Azure Backup has recovery points Restore disks or VM from the vault 30 minutes to hours
Nothing, but snapshots exist Create disks from snapshots, then recreate Under an hour
Nothing Rebuild from image and IaC, restore data from app-level backups Hours

1. Freeze and find what's left (5 minutes)

Stop the pipeline or script that deleted it, so it doesn't delete the disks or the next VM too. Then see what's left:

az monitor activity-log list -g rg-app-prod --offset 1d \
  --query "[?contains(operationName.value,'/delete')].{time:eventTimestamp, op:operationName.value, caller:caller, res:resourceId}" -o table

# Unattached disks and NICs in the resource group
az disk list -g rg-app-prod --query "[?managedBy==null].{name:name, os:osType, zone:zones[0], sku:sku.name, size:diskSizeGb, security:securityProfile.securityType}" -o table
az network nic list -g rg-app-prod --query "[?virtualMachine==null].{name:name, ip:ipConfigurations[0].privateIPAddress}" -o table

Get the old VM's settings from IaC, your CMDB, or the resource group's deployment history (az deployment group list -g rg-app-prod -o table, then az deployment group export on the deployment that created it). You need: size, zone or availability set, security type (Standard or Trusted Launch), OS type, license type, NIC, private IP and tags.

Caution

Don't run terraform apply to "put it back" without reading the plan. If the state still has the disks, Terraform may delete and recreate them empty.

2. Recreate on the existing disks

Attach the original OS disk, data disks and NIC. Match the zone, security type and generation of the original VM, or the VM won't boot.

os_disk=$(az disk show -g rg-app-prod -n vm-sql01_OsDisk_1 --query id -o tsv)
data1=$(az disk show -g rg-app-prod -n vm-sql01-data01 --query id -o tsv)
data2=$(az disk show -g rg-app-prod -n vm-sql01-log01 --query id -o tsv)

az vm create -g rg-app-prod -n vm-sql01 \
  --attach-os-disk $os_disk --os-type Windows \
  --attach-data-disks $data1 $data2 \
  --nics vm-sql01-nic \
  --size Standard_E8s_v5 --zone 1 \
  --license-type Windows_Server

For Trusted Launch disks, add:

  --security-type TrustedLaunch --enable-secure-boot true --enable-vtpm true

If the NIC was deleted, create one with the old private IP so clients and DNS records still work:

az network nic create -g rg-app-prod -n vm-sql01-nic \
  --vnet-name vnet-app-prod --subnet snet-data \
  --private-ip-address 10.20.3.10 --accelerated-networking true

If the IP was taken by another resource in the meantime, use a new one and update DNS records and firewall rules.

Warning

Data disk LUN order matters for some workloads, such as SQL Server or Linux /etc/fstab entries that use device names. --attach-data-disks assigns LUNs in the order you list them. Use the original order from IaC, or attach them one at a time with az vm disk attach --lun.

3. No disks left: restore from Azure Backup

The backup item and its recovery points stay in the vault after the VM is deleted. New backups fail, but existing points are kept per policy.

az backup item list -g rg-backup --vault-name rsv-prod --backup-management-type AzureIaasVM \
  --query "[?properties.friendlyName=='vm-sql01'].{name:name, container:properties.containerName, last:properties.lastRecoveryPoint}" -o table

az backup recoverypoint list -g rg-backup --vault-name rsv-prod \
  --container-name vm-sql01 --item-name vm-sql01 --backup-management-type AzureIaasVM \
  --query "[0:5].{name:name, time:properties.recoveryPointTime, type:properties.recoveryPointType}" -o table

Restore the disks into the original resource group. The staging storage account must be in the same region as the vault:

az backup restore restore-disks -g rg-backup --vault-name rsv-prod \
  --container-name vm-sql01 --item-name vm-sql01 --rp-name <recovery-point-name> \
  --storage-account stbackupstaging --target-resource-group rg-app-prod

az backup job list -g rg-backup --vault-name rsv-prod --operation Restore --status InProgress -o table
az backup job wait -g rg-backup --vault-name rsv-prod --name <job-name>

When the job finishes, the managed disks are in rg-app-prod. Recreate the VM on them with step 2. Recent CLI versions can also create the VM directly with --restore-mode AlternateLocation and the target VM, VNet and subnet options; check az backup restore restore-disks --help for the flags your version supports.

Restored disks get new names. Rename nothing; just use their IDs in az vm create.

From snapshots

az snapshot list -g rg-app-prod --query "[?contains(name,'sql01')].{name:name, time:timeCreated}" -o table
az disk create -g rg-app-prod -n vm-sql01-os-restored --source vm-sql01-os-snap-20261115 --zone 1 --sku Premium_LRS

For Trusted Launch, create the disk with --security-type TrustedLaunch --hyper-v-generation V2.

4. Rebuild what the VM resource carried

The disks bring back the OS and data. These belonged to the VM resource and are gone:

Item Fix
System-assigned managed identity az vm identity assign -g rg-app-prod -n vm-sql01, then re-grant its roles (new principal ID)
User-assigned identity az vm identity assign --identities <id>
Extensions (AMA, Defender, Dependency, custom script) Reinstall, or let Azure Policy remediation reapply them
Azure Backup protection az backup protection enable-for-vm -g rg-backup --vault-name rsv-prod --vm <vm-id> --policy-name DailyPolicy
Site Recovery replication Re-enable replication
Tags, locks, diagnostic settings, auto-shutdown Reapply from IaC
Load balancer backend pool membership Add the NIC IP configuration back to the pool

Tip

Domain-joined Windows VMs keep their computer account because the OS disk is the same. A VM restored from an older recovery point can have an out-of-date machine account password; if domain logons fail, run Test-ComputerSecureChannel -Repair as a domain admin.

Verify recovery

  • az vm get-instance-view -g rg-app-prod -n vm-sql01 --query "instanceView.statuses[].displayStatus" shows VM running and the guest agent reports Ready.
  • The app or database answers on its normal port from a client subnet, and all data volumes are mounted with the expected drive letters or paths.
  • Monitoring and backup show the VM again; run an on-demand backup.

Communicate

"Server was deleted at

Prevent it next time

  • Put CanNotDelete locks on production resource groups, or on the VMs and disks that hold state.
  • Set disk and NIC deleteOption to Detach so deleting a VM never takes its disks:
az vm update -g rg-app-prod -n vm-sql01 --set storageProfile.osDisk.deleteOption=Detach
  • Alert on Microsoft.Compute/virtualMachines/delete and Microsoft.Compute/disks/delete in production subscriptions.
  • Protect every stateful VM with Azure Backup, with soft delete on the vault, and test a restore every quarter.
  • Use Terraform prevent_destroy or deployment stacks with deny settings for production VMs and disks.