使用 Azure CLI 建立虛擬機器還原點

您可以定期建立 VM 還原點,保護資料並避免較長的停機時間。 您可以使用 Azure CLI 建立 VM 還原點,並在建立還原點時排除磁碟。 Azure CLI 用來使用命令列或指令碼建立和管理 Azure 資源。 或者,您也可以使用 Azure 入口網站 或使用 PowerShell 建立 VM 還原點。

az restore-point 模組用來從命令列或在指令碼中建立和管理還原點。

在本教學課程中,您會了解如何:

必要條件

步驟 1:建立 VM 還原點集合

使用 az restore-point collection create 命令來建立 VM 還原點集合,如下所示:

az restore-point collection create --location "norwayeast" --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

若要從 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.dataDisks[0].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[0].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 中虛擬機器的備份和還原選項。