Skip to content

Commit 7a2299d

Browse files
authored
Merge pull request #88922 from pvrk/Aug2019P3
adding VaultID parameter
2 parents b5113ca + 5667f4f commit 7a2299d

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ When you create a Recovery Services vault, it comes with default protection and
171171
Use **[Get-AzRecoveryServicesBackupProtectionPolicy](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupprotectionpolicy)** to view the protection policies available in the vault. You can use this cmdlet to get a specific policy, or to view the policies associated with a workload type. The following example gets policies for workload type, AzureVM.
172172

173173
```powershell
174-
Get-AzRecoveryServicesBackupProtectionPolicy -WorkloadType "AzureVM"
174+
Get-AzRecoveryServicesBackupProtectionPolicy -WorkloadType "AzureVM" -VaultId $targetVault.ID
175175
```
176176

177177
The output is similar to the following example:
@@ -197,7 +197,7 @@ A backup protection policy is associated with at least one retention policy. A r
197197
By default, a start time is defined in the Schedule Policy Object. Use the following example to change the start time to the desired start time. The desired start time should be in UTC as well. The below example assumes the desired start time is 01:00 AM UTC for daily backups.
198198

199199
```powershell
200-
$schPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureVM"
200+
$schPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureVM" -VaultId $targetVault.ID
201201
$UtcTime = Get-Date -Date "2019-03-20 01:00:00Z"
202202
$UtcTime = $UtcTime.ToUniversalTime()
203203
$schpol.ScheduleRunTimes[0] = $UtcTime
@@ -209,8 +209,8 @@ $schpol.ScheduleRunTimes[0] = $UtcTime
209209
The following example stores the schedule policy and the retention policy in variables. The example uses those variables to define the parameters when creating a protection policy, *NewPolicy*.
210210

211211
```powershell
212-
$retPol = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType "AzureVM"
213-
New-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -WorkloadType "AzureVM" -RetentionPolicy $retPol -SchedulePolicy $schPol
212+
$retPol = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType "AzureVM" -VaultId $targetVault.ID
213+
New-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -WorkloadType "AzureVM" -RetentionPolicy $retPol -SchedulePolicy $schPol -VaultId $targetVault.ID
214214
```
215215

216216
The output is similar to the following example:
@@ -233,24 +233,24 @@ The following examples enable protection for the item, V2VM, using the policy, N
233233
To enable the protection on **non-encrypted Resource Manager VMs**:
234234

235235
```powershell
236-
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy"
237-
Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGroupName "RGName1"
236+
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -VaultId $targetVault.ID
237+
Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGroupName "RGName1" -VaultId $targetVault.ID
238238
```
239239

240240
To enable the protection on encrypted VMs (encrypted using BEK and KEK), you must give the Azure Backup service permission to read keys and secrets from the key vault.
241241

242242
```powershell
243243
Set-AzKeyVaultAccessPolicy -VaultName "KeyVaultName" -ResourceGroupName "RGNameOfKeyVault" -PermissionsToKeys backup,get,list -PermissionsToSecrets get,list -ServicePrincipalName 262044b1-e2ce-469f-a196-69ab7ada62d3
244-
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy"
245-
Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGroupName "RGName1"
244+
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -VaultId $targetVault.ID
245+
Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGroupName "RGName1" -VaultId $targetVault.ID
246246
```
247247

248248
To enable the protection on **encrypted VMs (encrypted using BEK only)**, you must give the Azure Backup service permission to read secrets from the key vault.
249249

250250
```powershell
251251
Set-AzKeyVaultAccessPolicy -VaultName "KeyVaultName" -ResourceGroupName "RGNameOfKeyVault" -PermissionsToSecrets backup,get,list -ServicePrincipalName 262044b1-e2ce-469f-a196-69ab7ada62d3
252-
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy"
253-
Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGroupName "RGName1"
252+
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -VaultId $targetVault.ID
253+
Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGroupName "RGName1" -VaultId $targetVault.ID
254254
```
255255

256256
> [!NOTE]
@@ -262,7 +262,7 @@ Enable-AzRecoveryServicesBackupProtection -Policy $pol -Name "V2VM" -ResourceGro
262262
You can monitor long-running operations, such as backup jobs, without using the Azure portal. To get the status of an in-progress job, use the [Get-AzRecoveryservicesBackupJob](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupjob) cmdlet. This cmdlet gets the backup jobs for a specific vault, and that vault is specified in the vault context. The following example gets the status of an in-progress job as an array, and stores the status in the $joblist variable.
263263

264264
```powershell
265-
$joblist = Get-AzRecoveryservicesBackupJob –Status "InProgress"
265+
$joblist = Get-AzRecoveryservicesBackupJob –Status "InProgress" -VaultId $targetVault.ID
266266
$joblist[0]
267267
```
268268

@@ -277,7 +277,7 @@ V2VM Backup InProgress 4/23/2016
277277
Instead of polling these jobs for completion - which is unnecessary additional code - use the [Wait-AzRecoveryServicesBackupJob](https://docs.microsoft.com/powershell/module/az.recoveryservices/wait-azrecoveryservicesbackupjob) cmdlet. This cmdlet pauses the execution until either the job completes or the specified timeout value is reached.
278278

279279
```powershell
280-
Wait-AzRecoveryServicesBackupJob -Job $joblist[0] -Timeout 43200
280+
Wait-AzRecoveryServicesBackupJob -Job $joblist[0] -Timeout 43200 -VaultId $targetVault.ID
281281
```
282282

283283
## Manage Azure VM backups
@@ -295,8 +295,8 @@ $SchPol = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureV
295295
$UtcTime = Get-Date -Date "2019-03-20 01:00:00Z" (This is the time that the customer wants to start the backup)
296296
$UtcTime = $UtcTime.ToUniversalTime()
297297
$SchPol.ScheduleRunTimes[0] = $UtcTime
298-
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy"
299-
Set-AzRecoveryServicesBackupProtectionPolicy -Policy $pol -SchedulePolicy $SchPol
298+
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -VaultId $targetVault.ID
299+
Set-AzRecoveryServicesBackupProtectionPolicy -Policy $pol -SchedulePolicy $SchPol -VaultId $targetVault.ID
300300
````
301301

302302
#### Modifying retention
@@ -306,8 +306,8 @@ The following example changes the recovery point retention to 365 days.
306306
```powershell
307307
$retPol = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType "AzureVM"
308308
$retPol.DailySchedule.DurationCountInDays = 365
309-
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy"
310-
Set-AzRecoveryServicesBackupProtectionPolicy -Policy $pol -RetentionPolicy $RetPol
309+
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "NewPolicy" -VaultId $targetVault.ID
310+
Set-AzRecoveryServicesBackupProtectionPolicy -Policy $pol -RetentionPolicy $RetPol -VaultId $targetVault.ID
311311
```
312312

313313
#### Configuring Instant restore snapshot retention
@@ -316,9 +316,9 @@ Set-AzRecoveryServicesBackupProtectionPolicy -Policy $pol -RetentionPolicy $Ret
316316
> From Az PS version 1.6.0 onwards, one can update the instant restore snapshot retention period in policy using Powershell
317317
318318
````powershell
319-
$bkpPol = Get-AzureRmRecoveryServicesBackupProtectionPolicy -WorkloadType "AzureVM"
319+
$bkpPol = Get-AzureRmRecoveryServicesBackupProtectionPolicy -WorkloadType "AzureVM" -VaultId $targetVault.ID
320320
$bkpPol.SnapshotRetentionInDays=7
321-
Set-AzureRmRecoveryServicesBackupProtectionPolicy -policy $bkpPol
321+
Set-AzureRmRecoveryServicesBackupProtectionPolicy -policy $bkpPol -VaultId $targetVault.ID
322322
````
323323

324324
The default value will be 2, user can set the value with a min of 1 and max of 5. For weekly backup policies, the period is set to 5 and cannot be changed.
@@ -328,8 +328,8 @@ The default value will be 2, user can set the value with a min of 1 and max of 5
328328
Use [Backup-AzRecoveryServicesBackupItem](https://docs.microsoft.com/powershell/module/az.recoveryservices/backup-azrecoveryservicesbackupitem) to trigger a backup job. If it's the initial backup, it is a full backup. Subsequent backups take an incremental copy. The following example takes a VM backup to be retained for 60 days.
329329

330330
```powershell
331-
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "V2VM"
332-
$item = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM"
331+
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "V2VM" -VaultId $targetVault.ID
332+
$item = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM" -VaultId $targetVault.ID
333333
$endDate = (Get-Date).AddDays(60).ToUniversalTime()
334334
$job = Backup-AzRecoveryServicesBackupItem -Item $item -VaultId $targetVault.ID -ExpiryDateTimeUTC $endDate
335335
```
@@ -352,9 +352,9 @@ V2VM Backup InProgress 4/23/2016
352352
User can either modify existing policy or change the policy of the backed-up item from Policy1 to Policy2. To switch policies for a backed-up item, fetch the relevant policy and back up item and use the [Enable-AzRecoveryServices](https://docs.microsoft.com/powershell/module/az.recoveryservices/Enable-AzRecoveryServicesBackupProtection?view=azps-1.5.0) command with backup item as the parameter.
353353

354354
````powershell
355-
$TargetPol1 = Get-AzRecoveryServicesBackupProtectionPolicy -Name <PolicyName>
356-
$anotherBkpItem = Get-AzRecoveryServicesBackupItem -WorkloadType AzureVM -BackupManagementType AzureVM -Name "<BackupItemName>"
357-
Enable-AzRecoveryServicesBackupProtection -Item $anotherBkpItem -Policy $TargetPol1
355+
$TargetPol1 = Get-AzRecoveryServicesBackupProtectionPolicy -Name <PolicyName> -VaultId $targetVault.ID
356+
$anotherBkpItem = Get-AzRecoveryServicesBackupItem -WorkloadType AzureVM -BackupManagementType AzureVM -Name "<BackupItemName>" -VaultId $targetVault.ID
357+
Enable-AzRecoveryServicesBackupProtection -Item $anotherBkpItem -Policy $TargetPol1 -VaultId $targetVault.ID
358358
````
359359

360360
The command waits until the configure backup is completed and returns the following output.
@@ -411,8 +411,8 @@ The basic steps to restore an Azure VM are:
411411
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](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupcontainer) cmdlet and pipe that to the [Get-AzRecoveryServicesBackupItem](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupitem) cmdlet.
412412

413413
```powershell
414-
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "V2VM"
415-
$backupitem = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM"
414+
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "V2VM" -VaultId $targetVault.ID
415+
$backupitem = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM" -VaultId $targetVault.ID
416416
```
417417

418418
### Choose a recovery point
@@ -424,7 +424,7 @@ In the following script, the variable, **$rp**, is an array of recovery points f
424424
```powershell
425425
$startDate = (Get-Date).AddDays(-7)
426426
$endDate = Get-Date
427-
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupitem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime()
427+
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupitem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime() -VaultId $targetVault.ID
428428
$rp[0]
429429
```
430430

@@ -451,7 +451,7 @@ Use the [Restore-AzRecoveryServicesBackupItem](https://docs.microsoft.com/powers
451451
To restore the disks and configuration information:
452452

453453
```powershell
454-
$restorejob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -StorageAccountName "DestAccount" -StorageAccountResourceGroupName "DestRG"
454+
$restorejob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -StorageAccountName "DestAccount" -StorageAccountResourceGroupName "DestRG" -VaultId $targetVault.ID
455455
$restorejob
456456
```
457457

@@ -471,7 +471,7 @@ Provide an additional parameter **TargetResourceGroupName** to specify the RG to
471471
472472

473473
```powershell
474-
$restorejob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -StorageAccountName "DestAccount" -StorageAccountResourceGroupName "DestRG" -TargetResourceGroupName "DestRGforManagedDisks"
474+
$restorejob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -StorageAccountName "DestAccount" -StorageAccountResourceGroupName "DestRG" -TargetResourceGroupName "DestRGforManagedDisks" -VaultId $targetVault.ID
475475
```
476476

477477
The **VMConfig.JSON** file will be restored to the storage account and the managed disks will be restored to the specified target RG.
@@ -493,8 +493,8 @@ Wait-AzRecoveryServicesBackupJob -Job $restorejob -Timeout 43200
493493
Once the Restore job has completed, use the [Get-AzRecoveryServicesBackupJobDetails](https://docs.microsoft.com/powershell/module/az.recoveryservices/wait-azrecoveryservicesbackupjob) cmdlet to get the details of the restore operation. The JobDetails property has the information needed to rebuild the VM.
494494

495495
```powershell
496-
$restorejob = Get-AzRecoveryServicesBackupJob -Job $restorejob
497-
$details = Get-AzRecoveryServicesBackupJobDetails -Job $restorejob
496+
$restorejob = Get-AzRecoveryServicesBackupJob -Job $restorejob -VaultId $targetVault.ID
497+
$details = Get-AzRecoveryServicesBackupJobDetails -Job $restorejob -VaultId $targetVault.ID
498498
```
499499

500500
Once you restore the disks, go to the next section to create the VM.
@@ -764,8 +764,8 @@ The basic steps to restore a file from an Azure VM backup are:
764764
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](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupcontainer) cmdlet and pipe that to the [Get-AzRecoveryServicesBackupItem](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupitem) cmdlet.
765765
766766
```powershell
767-
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "V2VM"
768-
$backupitem = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM"
767+
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "V2VM" -VaultId $targetVault.ID
768+
$backupitem = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM" -VaultId $targetVault.ID
769769
```
770770

771771
### Choose a recovery point
@@ -777,7 +777,7 @@ In the following script, the variable, **$rp**, is an array of recovery points f
777777
```powershell
778778
$startDate = (Get-Date).AddDays(-7)
779779
$endDate = Get-Date
780-
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupitem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime()
780+
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupitem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime() -VaultId $targetVault.ID
781781
$rp[0]
782782
```
783783

@@ -807,7 +807,7 @@ Use the [Get-AzRecoveryServicesBackupRPMountScript](https://docs.microsoft.com/p
807807
>
808808
809809
```powershell
810-
Get-AzRecoveryServicesBackupRPMountScript -RecoveryPoint $rp[0]
810+
Get-AzRecoveryServicesBackupRPMountScript -RecoveryPoint $rp[0] -VaultId $targetVault.ID
811811
```
812812

813813
The output is similar to the following example:
@@ -825,7 +825,7 @@ Run the script on the machine where you want to recover the files. To execute th
825825
After the required files are copied, use [Disable-AzRecoveryServicesBackupRPMountScript](https://docs.microsoft.com/powershell/module/az.recoveryservices/disable-azrecoveryservicesbackuprpmountscript) to unmount the disks. Be sure to unmount the disks so access to the files of the recovery point is removed.
826826

827827
```powershell
828-
Disable-AzRecoveryServicesBackupRPMountScript -RecoveryPoint $rp[0]
828+
Disable-AzRecoveryServicesBackupRPMountScript -RecoveryPoint $rp[0] -VaultId $targetVault.ID
829829
```
830830

831831
## Next steps

0 commit comments

Comments
 (0)