使用 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" 

建立一個具備即時存取權限的虛擬機還原點集合

即時存取為選配功能,僅適用於使用 Premium SSD v2 或 Ultra Disks 作為資料磁碟的虛擬機。 它支援應用程式一致性及多磁碟當機一致性(預覽版)還原點。 當你在還原點收集中啟用即時存取時,磁碟還原可以立即從還原點開始,無需等待完全水化。 此功能大幅減少RTOs。 欲了解更多,請參閱 即時存取。

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" --instant-access true

步驟 2:建立 VM 還原點

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

az restore-point create --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleRp"

如要建立當機一致還原點,請將--consistency-mode設為CrashConsistent。

建立一個具特定即時存取時間的虛擬機還原點

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

az restore-point create --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleRp" --instant-access-duration "120"

註: 即時存取時間是可選參數。 這是每個還原點設定的整數屬性。 指定即時存取持續有效的時間,以分鐘計。 有效時間範圍:60–300分鐘。 預設值:300(5小時)。

若要使用具備即時存取功能(預覽版)的多磁碟當機一致性還原點,請使用步驟 1 中已啟用即時存取的集合,並指定一致性模式和持續時間:

az restore-point create --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleCrashConsistentRp" --consistency-mode CrashConsistent --instant-access-duration 120

建立還原點時排除磁碟

使用 --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"

如果還原點集合啟用了即時存取,請檢查 instantAccessState 還原點內所有磁碟還原點的整合存取狀態。

az restore-point show --resource-group "ExampleRg" --collection-name "ExampleRpc" --name "ExampleRp" --instance-view --query "instanceView.statuses[1]" -o tsv

值為 InstantAccess 或 AvailableWithInstantAccess 表示還原點已準備好進行快速磁碟還原。

從 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。

停用未來還原點的即時存取功能

以下以 az restore-point collection update 指令更新虛擬機還原點集合:

az restore-point collection update -g MyResourceGroup --collection-name ExampleRpc --tags myTag1="tagValue1" --instant-access false

下一步

深入了解 Azure 中虛擬機器的備份和還原選項。
了解更多 關於即時存取還原點的資訊。