|
2 | 2 | title: Back up and recover Azure VMs with PowerShell
|
3 | 3 | description: Describes how to back up and recover Azure VMs using Azure Backup with PowerShell
|
4 | 4 | ms.topic: conceptual
|
5 |
| -ms.date: 01/04/2022 |
| 5 | +ms.date: 04/25/2022 |
6 | 6 | ms.custom: devx-track-azurepowershell
|
7 | 7 | author: v-amallick
|
8 | 8 | ms.service: backup
|
@@ -439,6 +439,8 @@ The basic steps to restore an Azure VM are:
|
439 | 439 | * Restore the disks.
|
440 | 440 | * Create the VM from stored disks.
|
441 | 441 |
|
| 442 | +Now, you can also use PowerShell to directly restore the backup content to a VM (original/new), without performing the above steps separately. For more information, see [Restore data to virtual machine using PowerShell](#restore-data-to-virtual-machine-using-powershell). |
| 443 | + |
442 | 444 | ### Select the VM (when restoring files)
|
443 | 445 |
|
444 | 446 | To get the PowerShell object that identifies the right backup item, start from the container in the vault, and work your way down the object hierarchy. To select the container that represents the VM, use the [Get-AzRecoveryServicesBackupContainer](/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupcontainer) cmdlet and pipe that to the [Get-AzRecoveryServicesBackupItem](/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupitem) cmdlet.
|
@@ -982,6 +984,48 @@ After the required files are copied, use [Disable-AzRecoveryServicesBackupRPMoun
|
982 | 984 | Disable-AzRecoveryServicesBackupRPMountScript -RecoveryPoint $rp[0] -VaultId $targetVault.ID
|
983 | 985 | ```
|
984 | 986 |
|
| 987 | +## Restore data to virtual machine using PowerShell |
| 988 | + |
| 989 | +You can now directly restore data to original/alternate VM without performing multiple steps. |
| 990 | + |
| 991 | +### Restore data to original VM |
| 992 | + |
| 993 | +```powershell-interactive |
| 994 | +$vault = Get-AzRecoveryServicesVault -ResourceGroupName "resourceGroup" -Name "vaultName" |
| 995 | +$BackupItem = Get-AzRecoveryServicesBackupItem -BackupManagementType "AzureVM" -WorkloadType "AzureVM" -Name "V2VM" -VaultId $vault.ID |
| 996 | +$StartDate = (Get-Date).AddDays(-7) |
| 997 | +$EndDate = Get-Date |
| 998 | +$RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartDate $StartDate.ToUniversalTime() -EndDate $EndDate.ToUniversalTime() -VaultId $vault.ID |
| 999 | +$OriginalLocationRestoreJob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $RP[0] -StorageAccountName "DestStorageAccount" -StorageAccountResourceGroupName "DestStorageAccRG" -VaultId $vault.ID -VaultLocation $vault.Location |
| 1000 | +``` |
| 1001 | + |
| 1002 | +```output |
| 1003 | +WorkloadName Operation Status StartTime EndTime |
| 1004 | +------------ --------- ------ --------- ------- |
| 1005 | +V2VM Restore InProgress 26-Apr-16 1:14:01 PM 01-Jan-01 12:00:00 AM |
| 1006 | +``` |
| 1007 | + |
| 1008 | +The last command triggers an original location restore operation to restore the data in-place in the existing VM. |
| 1009 | + |
| 1010 | +### Restore data to a newly created VM |
| 1011 | + |
| 1012 | +```powershell-interactive |
| 1013 | +$vault = Get-AzRecoveryServicesVault -ResourceGroupName "resourceGroup" -Name "vaultName" |
| 1014 | +$BackupItem = Get-AzRecoveryServicesBackupItem -BackupManagementType "AzureVM" -WorkloadType "AzureVM" -Name "V2VM" -VaultId $vault.ID |
| 1015 | +$StartDate = (Get-Date).AddDays(-7) |
| 1016 | +$EndDate = Get-Date |
| 1017 | +$RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartDate $StartDate.ToUniversalTime() -EndDate $EndDate.ToUniversalTime() -VaultId $vault.ID |
| 1018 | +$AlternateLocationRestoreJob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $RP[0] -TargetResourceGroupName "Target_RG" -StorageAccountName "DestStorageAccount" -StorageAccountResourceGroupName "DestStorageAccRG" -TargetVMName "TagetVirtualMachineName" -TargetVNetName "Target_VNet" -TargetVNetResourceGroup "" -TargetSubnetName "subnetName" -VaultId $vault.ID -VaultLocation $vault.Location |
| 1019 | +``` |
| 1020 | + |
| 1021 | +```output |
| 1022 | +WorkloadName Operation Status StartTime EndTime |
| 1023 | +------------ --------- ------ --------- ------- |
| 1024 | +V2VM Restore InProgress 26-Apr-16 1:14:01 PM 01-Jan-01 12:00:00 AM |
| 1025 | +``` |
| 1026 | + |
| 1027 | +The last command triggers an alternate location restore operation to create a new VM in *Target_RG* resource group as per the inputs specified by parameters *TargetVMName*, *TargetVNetName*, *TargetVNetResourceGroup*, *TargetSubnetName*. This ensures that the data is restored in the required VM, virtual network and subnet. |
| 1028 | + |
985 | 1029 | ## Next steps
|
986 | 1030 |
|
987 | 1031 | If you prefer to use PowerShell to engage with your Azure resources, see the PowerShell article, [Deploy and Manage Backup for Windows Server](backup-client-automation.md). If you manage DPM backups, see the article, [Deploy and Manage Backup for DPM](backup-dpm-automation.md).
|
0 commit comments