创建快照Create a snapshot

快照是虚拟硬盘 (VHD) 的完整只读副本。A snapshot is a full, read-only copy of a virtual hard drive (VHD). 可以创建 OS 或数据磁盘 VHD 的快照以用作备份,或用于解决虚拟机 (VM) 问题。You can take a snapshot of an OS or data disk VHD to use as a backup, or to troubleshoot virtual machine (VM) issues.

如果要使用快照创建新的 VM,建议在拍摄快照前彻底关闭 VM,以清除正在运行的所有进程。If you are going to use the snapshot to create a new VM, we recommend that you cleanly shut down the VM before taking a snapshot, to clear out any processes that are in progress.

使用 Azure 门户Use the Azure portal

若要创建快照,请完成以下步骤:To create a snapshot, complete the following steps:

  1. Azure 门户中,选择“创建资源”。On the Azure portal, select Create a resource.
  2. 搜索并选择“快照”。Search for and select Snapshot.
  3. 在“快照”窗口,选择“创建” 。In the Snapshot window, select Create. 此时将显示“创建快照”窗口。The Create snapshot window appears.
  4. 输入快照的 名称Enter a Name for the snapshot.
  5. 选择现有的资源组,或键入新资源组的名称。Select an existing Resource group or enter the name of a new one.
  6. 选择 Azure 数据中心“位置” 。Select an Azure datacenter Location.
  7. 对于源磁盘,选择要获取其快照的托管磁盘。For Source disk, select the managed disk to snapshot.
  8. 选择用于存储快照的“帐户类型”。Select the Account type to use to store the snapshot. 选择“Standard_HDD”,除非需要将快照存储在高性能磁盘上。Select Standard_HDD, unless you need the snapshot to be stored on a high-performing disk.
  9. 选择“创建” 。Select Create.

使用 PowerShellUse PowerShell

以下步骤显示如何复制 VHD 磁盘并创建快照配置。The following steps show how to copy the VHD disk and create the snapshot configuration. 然后,可以使用 New-AzSnapshot cmdlet 创建磁盘快照。You can then take a snapshot of the disk by using the New-AzSnapshot cmdlet.

  1. 设置一些参数:Set some parameters:

    $resourceGroupName = 'myResourceGroup' 
    $location = 'chinaeast' 
    $vmName = 'myVM'
    $snapshotName = 'mySnapshot'  
    
  2. 获取 VM:Get the VM:

    $vm = Get-AzVM `
        -ResourceGroupName $resourceGroupName `
        -Name $vmName
    
  3. 创建快照配置。Create the snapshot configuration. 该示例中,此快照是 OS 磁盘的快照:For this example, the snapshot is of the OS disk:

    $snapshot =  New-AzSnapshotConfig `
        -SourceUri $vm.StorageProfile.OsDisk.ManagedDisk.Id `
        -Location $location `
        -CreateOption copy
    
  4. 拍摄快照:Take the snapshot:

    New-AzSnapshot `
        -Snapshot $snapshot `
        -SnapshotName $snapshotName `
        -ResourceGroupName $resourceGroupName 
    

后续步骤Next steps

通过从快照创建托管磁盘,然后将新的托管磁盘附加为 OS 磁盘,来从快照创建虚拟机。Create a virtual machine from a snapshot by creating a managed disk from a snapshot and then attaching the new managed disk as the OS disk. 有关详细信息,请参阅使用 PowerShell 从快照创建 VM 中的示例。For more information, see the sample in Create a VM from a snapshot with PowerShell.