|
| 1 | +--- |
| 2 | +title: Create an Azure snapshot of a virtual hard disk |
| 3 | +description: Learn how to create a copy of an Azure VM to use as a backup or for troubleshooting issues using the portal, PowerShell, or CLI. |
| 4 | +author: roygara |
| 5 | +ms.author: rogarana |
| 6 | +ms.service: storage |
| 7 | +ms.subservice: disks |
| 8 | +ms.workload: infrastructure-services |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 09/07/2021 |
| 11 | +--- |
| 12 | + |
| 13 | +# Create a snapshot of a virtual hard disk |
| 14 | + |
| 15 | +**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Windows VMs :heavy_check_mark: Flexible scale sets |
| 16 | + |
| 17 | +A snapshot is a full, read-only copy of a virtual hard disk (VHD). You can use a snapshot as a point-in-time backup, or to help troubleshoot virtual machine (VM) issues. You can take a snapshot of both operating system (OS) or data disk VHDs. |
| 18 | + |
| 19 | +## Create a snapshot of a VHD |
| 20 | + |
| 21 | +If you want to use a snapshot to create a new VM, ensure that you first cleanly shut down the VM. This action clears any processes that are in progress. |
| 22 | + |
| 23 | +# [Portal](#tab/portal) |
| 24 | + |
| 25 | +To create a snapshot using the Azure portal, complete these steps. |
| 26 | + |
| 27 | +1. In the [Azure portal](https://portal.azure.com), select **Create a resource**. |
| 28 | +1. Search for and select **Snapshot**. |
| 29 | +1. In the **Snapshot** window, select **Create**. The **Create snapshot** window appears. |
| 30 | +1. For **Resource group**, select an existing [resource group](/azure/azure-resource-manager/management/overview#resource-groups) or enter the name of a new one. |
| 31 | +1. Enter a **Name**, then select a **Region** and **Snapshot type** for the new snapshot. If you would like to store your snapshot in zone-resilient storage, you need to select a region that supports [availability zones](/azure/availability-zones/az-overview). For a list of supporting regions, see [Azure regions with availability zones](/azure/availability-zones/az-region#azure-regions-with-availability-zones). |
| 32 | +1. For **Source subscription**, select the subscription that contains the managed disk to be backed up. |
| 33 | +1. For **Source disk**, select the managed disk to snapshot. |
| 34 | +1. For **Storage type**, select **Standard HDD**, unless you require zone-redundant storage or high-performance storage for your snapshot. |
| 35 | +1. If needed, configure settings on the **Encryption**, **Networking**, and **Tags** tabs. Otherwise, default settings are used for your snapshot. |
| 36 | +1. Select **Review + create**. |
| 37 | + |
| 38 | +# [PowerShell](#tab/powershell) |
| 39 | + |
| 40 | +This example requires that you use [Cloud Shell](https://shell.azure.com/bash) or have the [Azure CLI](/cli/azure/) installed. |
| 41 | + |
| 42 | +Follow these steps to take a snapshot with the `New-AzSnapshotConfig` and `New-AzSnapshot` cmdlets. This example assumes that you have a VM called *myVM* in the *myResourceGroup* resource group. The code sample provided creates a snapshot in the same resource group and within the same region as your source VM. |
| 43 | + |
| 44 | +First, you'll use the [New-AzSnapshotConfig](/powershell/module/az.compute/new-azsnapshotconfig) cmdlet to create a configurable snapshot object. You can then use the [New-AzSnapshot](/powershell/module/az.compute/new-azsnapshot) cmdlet to take a snapshot of the disk. |
| 45 | + |
| 46 | +1. Set the required parameters. Update the values to reflect your environment. |
| 47 | + |
| 48 | + ```azurepowershell-interactive |
| 49 | + $resourceGroupName = 'myResourceGroup' |
| 50 | + $location = 'eastus' |
| 51 | + $vmName = 'myVM' |
| 52 | + $snapshotName = 'mySnapshot' |
| 53 | + ``` |
| 54 | + |
| 55 | +1. Use the [Get-AzVM](/powershell/module/az.compute/get-azvm) cmdlet to get the VM containing the VHD you want to copy. |
| 56 | + |
| 57 | + ```azurepowershell-interactive |
| 58 | + $vm = Get-AzVM ` |
| 59 | + -ResourceGroupName $resourceGroupName ` |
| 60 | + -Name $vmName |
| 61 | + ``` |
| 62 | + |
| 63 | +1. Create the snapshot configuration. In the example, the snapshot is of the OS disk. By default, the snapshot uses locally redundant standard storage. We recommend that you store your snapshots in standard storage instead of premium storage whatever the storage type of the parent disk or target disk. Premium snapshots incur additional cost. |
| 64 | + |
| 65 | + ```azurepowershell-interactive |
| 66 | + $snapshot = New-AzSnapshotConfig ` |
| 67 | + -SourceUri $vm.StorageProfile.OsDisk.ManagedDisk.Id ` |
| 68 | + -Location $location ` |
| 69 | + -CreateOption copy |
| 70 | + ``` |
| 71 | + |
| 72 | + If you want to store your snapshot in zone-resilient storage, you must create the snapshot in a region that supports [availability zones](/azure/availability-zones/az-overview and include the `-SkuName Standard_ZRS` parameter. For a list of regions that support availability zones, see [Azure regions with availability zones](/azure/availability-zones/az-region#azure-regions-with-availability-zones). |
| 73 | + |
| 74 | +1. Take the snapshot. |
| 75 | + |
| 76 | + ```azurepowershell-interactive |
| 77 | + New-AzSnapshot ` |
| 78 | + -Snapshot $snapshot ` |
| 79 | + -SnapshotName $snapshotName ` |
| 80 | + -ResourceGroupName $resourceGroupName |
| 81 | + ``` |
| 82 | + |
| 83 | +1. Use the [Get-AzSnapshot](/powershell/module/az.compute/get-azsnapshot) cmdlet to verify that your snapshot exists. |
| 84 | + |
| 85 | + ```azurepowershell-interactive |
| 86 | + Get-AzSnapshot ` |
| 87 | + -ResourceGroupName $resourceGroupName |
| 88 | + ``` |
| 89 | +
|
| 90 | +# [Azure CLI](#tab/cli) |
| 91 | +
|
| 92 | +This example requires that you use [Cloud Shell](https://shell.azure.com/bash) or have the [Azure CLI](/cli/azure/) installed. |
| 93 | +
|
| 94 | +Follow these steps to take a snapshot with the `az snapshot create` command and the `--source-disk` parameter. This example assumes that you have a VM called *myVM* in the *myResourceGroup* resource group. The code sample provided creates a snapshot in the same resource group and within the same region as your source VM. |
| 95 | +
|
| 96 | +1. Get the disk ID with [az vm show](/cli/azure/vm#az_vm_show). |
| 97 | +
|
| 98 | + ```azurecli-interactive |
| 99 | + osDiskId=$(az vm show \ |
| 100 | + -g myResourceGroup \ |
| 101 | + -n myVM \ |
| 102 | + --query "storageProfile.osDisk.managedDisk.id" \ |
| 103 | + -o tsv) |
| 104 | + ``` |
| 105 | +
|
| 106 | +1. Take a snapshot named *osDisk-backup* using [az snapshot create](/cli/azure/snapshot#az_snapshot_create). In the example, the snapshot is of the OS disk. By default, the snapshot uses locally redundant standard storage. We recommend that you store your snapshots in standard storage instead of premium storage whatever the storage type of the parent disk or target disk. Premium snapshots incur additional cost. |
| 107 | +
|
| 108 | + ```azurecli-interactive |
| 109 | + az snapshot create \ |
| 110 | + -g myResourceGroup \ |
| 111 | + --source "$osDiskId" \ |
| 112 | + --name osDisk-backup |
| 113 | + ``` |
| 114 | +
|
| 115 | + If you would like to store your snapshot in zone-resilient storage, you need to create it in a region that supports [availability zones](/azure/availability-zones/az-overview) and include the optional `--sku Standard_ZRS` parameter. A list of [availability zones](/azure/availability-zones/az-region#azure-regions-with-availability-zones) can be found here. |
| 116 | + |
| 117 | +1. Use [az snapshot list](/cli/azure/snapshot#az_snapshot_list) to verify that your snapshot exists. |
| 118 | + |
| 119 | + ```azurecli-interactive |
| 120 | + az snapshot list \ |
| 121 | + -g myResourceGroup \ |
| 122 | + - table |
| 123 | + ``` |
| 124 | +
|
| 125 | +--- |
| 126 | +
|
| 127 | +## Next steps |
| 128 | +
|
| 129 | +Deploy a virtual machine from a snapshot. Create a managed disk from a snapshot and then attach the new managed disk as the OS disk. |
| 130 | +
|
| 131 | +# [Portal](#tab/portal) |
| 132 | +
|
| 133 | +For more information, see the example in [Create a VM from a VHD by using the Azure portal](/windows/create-vm-specialized-portal). |
| 134 | +
|
| 135 | +# [PowerShell](#tab/powershell) |
| 136 | +
|
| 137 | +For more information, see the example in [Create a Windows VM from a specialized disk by using PowerShell](/windows/create-vm-specialized). |
| 138 | +
|
| 139 | +# [Azure CLI](#tab/cli) |
| 140 | +
|
| 141 | +For more information, see the example in [Create a complete Linux virtual machine with the Azure CLI](/previous-versions/azure/virtual-machines/scripts/virtual-machines-linux-cli-sample-create-vm-from-snapshot?toc=%2fcli%2fmodule%2ftoc.json). |
| 142 | +
|
| 143 | +--- |
0 commit comments