您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

创建快照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

  1. 登录到 Azure 门户Sign in to the Azure portal.
  2. 在左侧菜单中,选择“创建资源”,然后搜索并选择“快照” 。From the left menu, select Create a resource, and then 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

以下步骤演示如何使用 New-AzSnapshot cmdlet 复制 VHD 磁盘、创建快照配置以及创建磁盘的快照。The following steps show how to copy the VHD disk, create the snapshot configuration, and take a snapshot of the disk by using the New-AzSnapshot cmdlet.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

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

    $resourceGroupName = 'myResourceGroup' 
    $location = 'eastus' 
    $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
    

    备注

    如果希望将快照存储在具有区域复原能力的存储中,请在支持可用性区域的区域中创建快照并将包含 -SkuName Standard_ZRS 参数。If you would like to store your snapshot in zone-resilient storage, create it in a region that supports availability zones and include the -SkuName Standard_ZRS parameter.

  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.