Skip to content

Commit afe6a6b

Browse files
authored
Merge pull request #196002 from v-amallick/Apr-25-2022-VM-Automation
VM - Automation updates
2 parents 6acd6aa + cdfbe99 commit afe6a6b

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

articles/backup/backup-azure-vms-automation.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Back up and recover Azure VMs with PowerShell
33
description: Describes how to back up and recover Azure VMs using Azure Backup with PowerShell
44
ms.topic: conceptual
5-
ms.date: 01/04/2022
5+
ms.date: 04/25/2022
66
ms.custom: devx-track-azurepowershell
77
author: v-amallick
88
ms.service: backup
@@ -439,6 +439,8 @@ The basic steps to restore an Azure VM are:
439439
* Restore the disks.
440440
* Create the VM from stored disks.
441441

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+
442444
### Select the VM (when restoring files)
443445

444446
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
982984
Disable-AzRecoveryServicesBackupRPMountScript -RecoveryPoint $rp[0] -VaultId $targetVault.ID
983985
```
984986

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+
9851029
## Next steps
9861030

9871031
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).

articles/backup/tutorial-restore-disk.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Tutorial - Restore a VM with Azure CLI
33
description: Learn how to restore a disk and create a recover a VM in Azure with Backup and Recovery Services.
44
ms.topic: tutorial
5-
ms.date: 01/05/2022
5+
ms.date: 04/25/2022
66
ms.custom: mvc, devx-track-azurecli
77
author: v-amallick
88
ms.service: backup
@@ -21,6 +21,8 @@ Azure Backup creates recovery points that are stored in geo-redundant recovery v
2121
2222
For information on using PowerShell to restore a disk and create a recovered VM, see [Back up and restore Azure VMs with PowerShell](backup-azure-vms-automation.md#restore-an-azure-vm).
2323

24+
Now, you can also use CLI 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 CLI](#restore-data-to-virtual-machine-using-cli).
25+
2426
[!INCLUDE [azure-cli-prepare-your-environment.md](../../includes/azure-cli-prepare-your-environment.md)]
2527

2628
- This tutorial requires version 2.0.18 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
@@ -310,6 +312,53 @@ To confirm that your VM has been created from your recovered disk, list the VMs
310312
az vm list --resource-group myResourceGroup --output table
311313
```
312314

315+
## Restore data to virtual machine using CLI
316+
317+
You can now directly restore data to original/alternate VM without performing multiple steps.
318+
319+
### Restore data to original VM
320+
321+
```azurecli-interactive
322+
az backup restore restore-disks \
323+
--resource-group myResourceGroup \
324+
--vault-name myRecoveryServicesVault \
325+
--container-name myVM \
326+
--item-name myVM \
327+
--restore-mode OriginalLocation
328+
--storage-account mystorageaccount \
329+
--rp-name myRecoveryPointName \
330+
```
331+
332+
```output
333+
Name Operation Status Item Name Start Time UTC Duration
334+
-------- --------------- ---------- ----------- ------------------- --------------
335+
7f2ad916 Restore InProgress myVM 2017-09-19T19:39:52 0:00:34.520850
336+
```
337+
338+
The last command triggers an original location restore operation to restore the data in-place in the existing VM.
339+
340+
341+
### Restore data to a newly created VM
342+
343+
```azurecli-interactive
344+
az backup restore restore-disks \
345+
--resource-group myResourceGroup \
346+
--vault-name myRecoveryServicesVault \
347+
--container-name myVM \
348+
--item-name myVM \
349+
--restore-mode OriginalLocation
350+
--storage-account mystorageaccount \
351+
--rp-name myRecoveryPointName \
352+
```
353+
354+
```output
355+
Name Operation Status Item Name Start Time UTC Duration
356+
-------- --------------- ---------- ----------- ------------------- --------------
357+
7f2ad916 Restore InProgress myVM 2017-09-19T19:39:52 0:00:34.520850
358+
```
359+
360+
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 the data is restored in the required VM, virtual network, and subnet.
361+
313362
## Next steps
314363

315364
In this tutorial, you restored a disk from a recovery point and then created a VM from the disk. You learned how to:

0 commit comments

Comments
 (0)