Skip to content

Commit c5fb7ef

Browse files
committed
Add examples and test cases
1 parent ebbf66f commit c5fb7ef

File tree

5 files changed

+2748
-2
lines changed

5 files changed

+2748
-2
lines changed

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ItemTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,17 @@ public void TestAzureRestoreWithCVMOsDiskEncryptionSetId()
351351
"Test-AzureRestoreWithCVMOsDiskEncryptionSetId"
352352
);
353353
}
354+
355+
[Fact]
356+
[Trait(Category.AcceptanceType, Category.CheckIn)]
357+
[Trait(TestConstants.Workload, TestConstants.AzureVM)]
358+
public void TestAzureVMRedoProtection()
359+
{
360+
TestRunner.RunTestScript(
361+
$"Import-Module {_IaasVmcommonModule.AsAbsoluteLocation()}",
362+
$"Import-Module {_IaasVmtestModule.AsAbsoluteLocation()}",
363+
"Test-AzureVMRedoProtection"
364+
);
365+
}
354366
}
355367
}

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ItemTests.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15+
function Test-AzureVMRedoProtection
16+
{
17+
$resourceGroupName = "hiagarg"
18+
$vaultName = "hiagaVault"
19+
$targetVaultName = "hiagaVault2"
20+
$vmContainerSuffix = "hiaga-adhoc-vm"
21+
$policyName = "DefaultPolicy"
22+
23+
try
24+
{
25+
# Step 1: Move protection from hiagaVault to hiagaVault2
26+
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
27+
$items = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -VaultId $vault.ID | Where-Object { $_.ContainerName.EndsWith($vmContainerSuffix) }
28+
$targetVault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $targetVaultName
29+
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -Name $policyName -VaultId $targetVault.ID
30+
31+
$redoJob = Redo-AzRecoveryServicesBackupProtection -Item $items[-1] -TargetVaultId $targetVault.ID -TargetPolicy $policy -VaultId $vault.ID -Force -Confirm:$false
32+
Assert-True { $redoJob.Status -eq "Completed" }
33+
34+
# Step 2: Reverse - move protection back to hiagaVault
35+
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $targetVaultName
36+
$targetVault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
37+
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -Name $policyName -VaultId $targetVault.ID
38+
$items = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureVM -WorkloadType AzureVM -VaultId $vault.ID | Where-Object { $_.ContainerName.EndsWith($vmContainerSuffix) }
39+
40+
$redoJob = Redo-AzRecoveryServicesBackupProtection -Item $items[-1] -TargetVaultId $targetVault.ID -TargetPolicy $policy -VaultId $vault.ID -Force -Confirm:$false
41+
Assert-True { $redoJob.Status -eq "Completed" }
42+
}
43+
finally
44+
{
45+
# Optional cleanup if needed
46+
}
47+
}
48+
1549
function Test-AzurePERestore
1650
{
1751
$subId = "f2edfd5d-5496-4683-b94f-b3588c579009"

0 commit comments

Comments
 (0)