ערוך

שתף באמצעות


Create virtual machine restore points using PowerShell

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

You can create Virtual Machine restore points using PowerShell scripts. The Azure PowerShell Az module is used to create and manage Azure resources from the command line or in scripts.

You can protect your data and guard against extended downtime by creating VM restore points at regular intervals. This article shows you how to create VM restore points, and exclude disks from the restore point, using the Az.Compute module. Alternatively, you can create VM restore points using the Azure CLI or in the Azure portal.

In this tutorial, you learn how to:

Prerequisites

Step 1: Create a VM restore point collection

Use the New-AzRestorePointCollection cmdlet to create a VM restore point collection.

New-AzRestorePointCollection -ResourceGroupName ExampleRG -Name ExampleRPC -VmId “/subscriptions/{SubscriptionId}/resourcegroups/ ExampleRG/providers/microsoft.compute/virtualmachines/Example-vm-1” -Location “WestEurope”

Step 2: Create a VM restore point

Create a VM restore point with the New-AzRestorePoint cmdlet as shown below:

New-AzRestorePoint -ResourceGroupName ExampleRG -RestorePointCollectionName ExampleRPC -Name ExampleRP

To create a crash consistent restore point set the optional parameter "ConsistencyMode" to "CrashConsistent". This feature is currently in preview.

Exclude disks from the restore point

Exclude certain disks that you do not want to be a part of the restore point with the -DisksToExclude parameter, as follows:

New-AzRestorePoint -ResourceGroupName ExampleRG -RestorePointCollectionName ExampleRPC -Name ExampleRP -DisksToExclude “/subscriptions/{SubscriptionId}/resourcegroups/ ExampleRG/providers/Microsoft.Compute/disks/example-vm-1-data_disk_1”

Step 3: Track the status of the VM restore point creation

You can track the progress of the VM restore point creation using the Get-AzRestorePoint cmdlet, as follows:

Get-AzRestorePoint -ResourceGroupName ExampleRG -RestorePointCollectionName ExampleRPC -Name ExampleRP

Restore a VM from VM restore point

To restore a VM from a VM restore point, first restore individual disks from each disk restore point. You can also use the ARM template to restore a full VM along with all the disks.

# Create Disks from disk restore points 
$restorePoint = Get-AzRestorePoint -ResourceGroupName ExampleRG -RestorePointCollectionName ExampleRPC -Name ExampleRP 

$osDiskRestorePoint = $restorePoint.SourceMetadata.StorageProfile.OsDisk.DiskRestorePoint.Id
$dataDisk1RestorePoint = $restorePoint.sourceMetadata.storageProfile.dataDisks[0].diskRestorePoint.id
$dataDisk2RestorePoint = $restorePoint.sourceMetadata.storageProfile.dataDisks[1].diskRestorePoint.id
 
New-AzDisk -DiskName “ExampleOSDisk” (New-AzDiskConfig  -Location eastus -CreateOption Restore -SourceResourceId $osDiskRestorePoint) -ResourceGroupName ExampleRg

New-AzDisk -DiskName “ExampleDataDisk1” (New-AzDiskConfig  -Location eastus -CreateOption Restore -SourceResourceId $dataDisk1RestorePoint) -ResourceGroupName ExampleRg

New-AzDisk -DiskName “ExampleDataDisk2” (New-AzDiskConfig  -Location eastus -CreateOption Restore -SourceResourceId $dataDisk2RestorePoint) -ResourceGroupName ExampleRg

After you create the disks, create a new VM and attach these restored disks to the newly created VM.

Next steps

Learn more about Backup and restore options for virtual machines in Azure.