在 Azure 中还原磁盘并创建恢复的 VMRestore a disk and create a recovered VM in Azure

Azure 备份可创建恢复点,这些恢复点存储在异地冗余的恢复保管库中。Azure Backup creates recovery points that are stored in geo-redundant recovery vaults. 从恢复点还原时,可以还原整个 VM,也可以还原单个文件。When you restore from a recovery point, you can restore the whole VM or individual files. 本文介绍如何使用 CLI 还原完整的 VM。This article explains how to restore a complete VM using CLI. 本教程介绍如何执行下列操作:In this tutorial you learn how to:

  • 列出和选择恢复点List and select recovery points
  • 从恢复点还原磁盘Restore a disk from a recovery point
  • 从还原的磁盘创建 VMCreate a VM from the restored disk

有关使用 PowerShell 还原磁盘并创建已恢复的 VM 的信息,请参阅使用 PowerShell 备份和还原 Azure VMFor information on using PowerShell to restore a disk and create a recovered VM, see Back up and restore Azure VMs with PowerShell.

如果选择在本地安装并使用 CLI,本教程需要你运行 Azure CLI 2.0.18 或更高版本。If you choose to install and use the CLI locally, this tutorial requires that you are running the Azure CLI version 2.0.18 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如需进行安装或升级,请参阅安装 CLIIf you need to install or upgrade, see Install the CLI.

先决条件Prerequisites

本教程需要使用 Azure 备份所保护的 Linux VM。This tutorial requires a Linux VM that has been protected with Azure Backup. 若要模拟意外的 VM 删除和恢复过程,请从恢复点中的磁盘创建 VM。To simulate an accidental VM deletion and recovery process, you create a VM from a disk in a recovery point. 如果需要使用 Azure 备份所保护的 Linux VM,请参阅在 Azure 中使用 CLI 备份虚拟机If you need a Linux VM that has been protected with Azure Backup, see Back up a virtual machine in Azure with the CLI.

备份概述Backup overview

当 Azure 启动备份时,VM 上的备份扩展将获取时点快照。When Azure initiates a backup, the backup extension on the VM takes a point-in-time snapshot. 请求第一个备份时,将在 VM 上安装备份扩展。The backup extension is installed on the VM when the first backup is requested. 如果进行备份时 VM 未运行,则 Azure 备份可能还需要获取基础存储的快照。Azure Backup can also take a snapshot of the underlying storage if the VM is not running when the backup takes place.

默认情况下,Azure 备份采用文件系统一致的备份。By default, Azure Backup takes a file system consistent backup. Azure 备份获取快照后,数据将传输到恢复服务保管库。Once Azure Backup takes the snapshot, the data is transferred to the Recovery Services vault. 为最大限度地提高效率,Azure 备份仅标识和传输自上次备份以后已更改的数据块。To maximize efficiency, Azure Backup identifies and transfers only the blocks of data that have changed since the previous backup.

数据传输完成后,会删除快照并创建恢复点。When the data transfer is complete, the snapshot is removed and a recovery point is created.

列出可用的恢复点List available recovery points

若要还原磁盘,请选择恢复点作为恢复数据的源。To restore a disk, you select a recovery point as the source for the recovery data. 由于默认策略每天创建一个恢复点并保留 30 天,因此,可以保留一组恢复点,以便可以选择一个特定的时点用于恢复。As the default policy creates a recovery point each day and retains them for 30 days, you can keep a set of recovery points that allows you to select a particular point in time for recovery.

若要查看可用恢复点的列表,请使用 az backup recoverypoint list 命令。To see a list of available recovery points, use az backup recoverypoint list. 将使用恢复点名称恢复磁盘。The recovery point name is used to recover disks. 在本教程中,我们希望最近的恢复点可用。In this tutorial, we want the most recent recovery point available. --query [0].name 参数可选择最近的恢复点名称,如下所示:The --query [0].name parameter selects the most recent recovery point name as follows:

az backup recoverypoint list \
    --resource-group myResourceGroup \
    --vault-name myRecoveryServicesVault \
    --container-name myVM \
    --item-name myVM \
    --query [0].name \
    --output tsv

还原 VM 磁盘Restore a VM disk

若要从恢复点恢复磁盘,请先创建 Azure 存储帐户。To restore your disk from the recovery point, you first create an Azure storage account. 此存储帐户用于存储还原的磁盘。This storage account is used to store the restored disk. 在其他步骤中,将使用还原的磁盘创建 VM。In additional steps, the restored disk is used to create a VM.

  1. 若要创建存储帐户,请使用 az storage account create 命令。To create a storage account, use az storage account create. 存储帐户名称必须全部为小写,且全局唯一。The storage account name must be all lowercase, and be globally unique. 将 mystorageaccount 替换为你自己唯一的名称:Replace mystorageaccount with your own unique name:

    az storage account create \
        --resource-group myResourceGroup \
        --name mystorageaccount \
        --sku Standard_LRS
    
  2. 使用 az backup restore restore-disks 从你的恢复点还原磁盘。Restore the disk from your recovery point with az backup restore restore-disks. 将 mystorageaccount 替换为你在前一个命令中创建的存储帐户的名称。Replace mystorageaccount with the name of the storage account you created in the preceding command. 将 myRecoveryPointName 替换为你在前面的 az backup recoverypoint list 命令输出中获得的恢复点名称:Replace myRecoveryPointName with the recovery point name you obtained in the output from the previous az backup recoverypoint list command:

    az backup restore restore-disks \
        --resource-group myResourceGroup \
        --vault-name myRecoveryServicesVault \
        --container-name myVM \
        --item-name myVM \
        --storage-account mystorageaccount \
        --rp-name myRecoveryPointName
    

监视还原作业Monitor the restore job

若要监视还原作业的状态,请使用 az backup job listTo monitor the status of restore job, use az backup job list:

az backup job list \
    --resource-group myResourceGroup \
    --vault-name myRecoveryServicesVault \
    --output table

输出类似于以下示例,该示例显示还原作业处于“正在进行”状态:The output is similar to the following example, which shows the restore job is InProgress:

Name      Operation        Status      Item Name    Start Time UTC       Duration
--------  ---------------  ----------  -----------  -------------------  --------------
7f2ad916  Restore          InProgress  myvm         2017-09-19T19:39:52  0:00:34.520850
a0a8e5e6  Backup           Completed   myvm         2017-09-19T03:09:21  0:15:26.155212
fe5d0414  ConfigureBackup  Completed   myvm         2017-09-19T03:03:57  0:00:31.191807

当还原作业的“状态”报告“已完成”时,磁盘已还原到存储帐户。When the Status of the restore job reports Completed, the disk has been restored to the storage account.

将还原的磁盘转换为托管磁盘Convert the restored disk to a Managed Disk

还原作业将创建一个非托管磁盘。The restore job creates an unmanaged disk. 若要从磁盘创建 VM,必须首先将该磁盘转换为托管磁盘。In order to create a VM from the disk, it must first be converted to a managed disk.

  1. 使用 az storage account show-connection-string 命令获取存储帐户的连接信息。Obtain the connection information for your storage account with az storage account show-connection-string. 将 mystorageaccount 替换为你的存储名称帐户,如下所示:Replace mystorageaccount with the name of your storage account as follows:

    export AZURE_STORAGE_CONNECTION_STRING=$( az storage account show-connection-string \
        --resource-group myResourceGroup \
        --output tsv \
        --name mystorageaccount )
    
  2. 非托管磁盘被保护在存储帐户中。Your unmanaged disk is secured in the storage account. 以下命令可以获取有关非托管磁盘的信息,并创建名为 uri 的变量,此变量会在下一步创建托管磁盘时用到。The following commands get information about your unmanaged disk and create a variable named uri that is used in the next step when you create the Managed Disk.

    container=$(az storage container list --query [0].name -o tsv)
    blob=$(az storage blob list --container-name $container --query [0].name -o tsv)
    uri=$(az storage blob url --container-name $container --name $blob -o tsv)
    
  3. 现在,可以使用 az disk create 从恢复的磁盘创建托管磁盘。Now you can create a Managed Disk from your recovered disk with az disk create. 使用上一步创建的 uri 变量作为托管磁盘的源。The uri variable from the preceding step is used as the source for your Managed Disk.

    az disk create \
        --resource-group myResourceGroup \
        --name myRestoredDisk \
        --source $uri
    
  4. 由于你现在已从还原磁盘获得托管磁盘,请使用 az storage account delete 命令清理非托管磁盘和存储帐户。As you now have a Managed Disk from your restored disk, clean up the unmanaged disk and storage account with az storage account delete. 将 mystorageaccount 替换为你的存储名称帐户,如下所示:Replace mystorageaccount with the name of your storage account as follows:

    az storage account delete \
        --resource-group myResourceGroup \
        --name mystorageaccount
    

从还原的磁盘创建 VMCreate a VM from the restored disk

最后一步是从托管磁盘创建 VM。The final step is to create a VM from the Managed Disk.

  1. 使用 az vm create 从托管磁盘创建 VM,如下所示:Create a VM from your Managed Disk with az vm create as follows:

    az vm create \
        --resource-group myResourceGroup \
        --name myRestoredVM \
        --attach-os-disk myRestoredDisk \
        --os-type linux
    
  2. 若要确认已从恢复的磁盘创建了 VM,请使用 az vm list 列出资源组中的 VM,如下所示:To confirm that your VM has been created from your recovered disk, list the VMs in your resource group with az vm list as follows:

    az vm list --resource-group myResourceGroup --output table
    

后续步骤Next steps

在本教程中,你从恢复点还原了一个磁盘,然后从该磁盘创建了一个 VM。In this tutorial, you restored a disk from a recovery point and then created a VM from the disk. 你已了解如何:You learned how to:

  • 列出和选择恢复点List and select recovery points
  • 从恢复点还原磁盘Restore a disk from a recovery point
  • 从还原的磁盘创建 VMCreate a VM from the restored disk

请进入下一个教程了解如何从恢复点还原单个文件。Advance to the next tutorial to learn about restoring individual files from a recovery point.