可通过定期创建虚拟机还原点来保护数据并防止故障时间延长。 可以使用Azure CLI创建还原点,并在创建还原点时排除磁盘。 Azure CLI用于使用命令行或脚本创建和管理Azure资源。 或者,可以使用Azure门户或使用 PowerShell 创建 VM 还原点。
az restore-point 模块用于从命令行或脚本中创建和管理还原点。
本教程中,您将学习如何:
先决条件
如需在本地运行 CLI 参考命令,请安装 Azure CLI。 如果在 Windows 或 macOS 上运行,请考虑在 Docker 容器中运行 Azure CLI。 有关详细信息,请参阅如何在 Docker 容器中运行 Azure CLI。
如果使用本地安装,请使用 az login 命令登录到Azure CLI。 若要完成身份验证过程,请遵循终端中显示的步骤。 有关其他登录选项,请参阅使用 Azure CLI 登录。
出现提示时,请在首次使用时安装 Azure CLI 扩展。 有关扩展的详细信息,请参阅 将扩展与 Azure CLI 配合使用。
运行az version命令,以查看已安装的版本和依赖库。 若要升级到最新版本,请运行az upgrade。
步骤 1:创建 VM 还原点集合
使用 az restore-point collection create 命令创建 VM 还原点集合,如下所示:
az restore-point collection create --location "chinanorth2" --source-id "/subscriptions/{subscription-id}/resourceGroups/ExampleRg/providers/Microsoft.Compute/virtualMachines/ExampleVM" --tags myTag1="tagValue1" --resource-group "ExampleRg" --collection-name "ExampleRpc"
步骤 2:创建 VM 还原点
使用 az restore-point create 命令创建 VM 还原点,如下所示:
az restore-point create --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleRp"
若要创建崩溃一致性还原点,请将可选参数“consistency-mode”设置为“CrashConsistent”。 此功能目前处于预览状态。
创建还原点时排除磁盘
使用 --exclude-disks 参数排除您不希望包含在还原点中的磁盘,如下所示:
az restore-point create --exclude-disks "/subscriptions/{subscription-id}/resourceGroups/ExampleRg/providers/Microsoft.Compute/disks/ExampleDisk1" --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleRp"
步骤 3:跟踪 VM 还原点创建的状态
使用 az restore-point show 命令跟踪 VM 还原点创建进度。
az restore-point show --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleRp"
从虚拟机还原点还原虚拟机
若要从 VM 还原点还原 VM,请先从每个磁盘还原点还原单个磁盘。 还可以使用 ARM 模板还原完整 VM 以及所有磁盘。
# Create Disks from disk restore points
$osDiskRestorePoint = az restore-point show --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleRp" --query "sourceMetadata.storageProfile.osDisk.diskRestorePoint.id"
$dataDisk1RestorePoint = az restore-point show --resource-group "ExampleRg" --collection-name "ExampleRpcTarget" --name "ExampleRpTarget" -query "sourceMetadata.storageProfile.dataDisks[0].diskRestorePoint.id"
$dataDisk2RestorePoint = az restore-point show --resource-group "ExampleRg" --collection-name "ExampleRpcTarget" --name "ExampleRpTarget" -query "sourceMetadata.storageProfile.dataDisks[1].diskRestorePoint.id"
az disk create --resource-group "ExampleRg" --name "ExampleOSDisk" --sku Premium_LRS --size-gb 128 --source $osDiskRestorePoint
az disk create --resource-group "ExampleRg" --name "ExampleDataDisk1" --sku Premium_LRS --size-gb 128 --source $dataDisk1RestorePoint
az disk create --resource-group "ExampleRg" --name "ExampleDataDisk1" --sku Premium_LRS --size-gb 128 --source $dataDisk2RestorePoint
创建磁盘后, 创建新的 VM 并将 这些还原的磁盘附加到 新创建的 VM。
后续步骤
详细了解 Azure 中虚拟机的备份和还原选项。