Skip to content

Commit c8241b1

Browse files
authored
[Az.RecoveryServices.Backup] Added fix for resume protection with AzureFileshare (#27785)
1 parent 68bf8ec commit c8241b1

File tree

7 files changed

+1849
-4
lines changed

7 files changed

+1849
-4
lines changed

src/RecoveryServices/RecoveryServices.Backup.Models/AzureModels/AzureItem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public class AzureItem : ItemBase
8989
/// </summary>
9090
public System.DateTime? DeferredDeleteTimeInUtc { get; set; }
9191

92+
/// <summary>
93+
/// Gets or sets time for deferred deletion time remaining in [d.]hh:mm:ss.fffffff
94+
/// </summary>
95+
public string DeferredDeleteTimeRemaining { get; set; }
96+
9297
public AzureItem(ProtectedItemResource protectedItemResource,
9398
string containerName, ContainerType containerType, string policyName)
9499
: base(protectedItemResource, containerName, containerType)

src/RecoveryServices/RecoveryServices.Backup.Models/AzureVmWorkloadModels/AzureWorkloadSQLDatabaseProtectedItem.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
16+
using System;
1617
using CrrModel = Microsoft.Azure.Management.RecoveryServices.Backup.CrossRegionRestore.Models;
1718

1819
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
@@ -85,15 +86,23 @@ public AzureWorkloadSQLDatabaseProtectedItem(ProtectedItemResource protectedItem
8586
ProtectionStatus = EnumUtils.GetEnum<ItemProtectionStatus>(protectedItem.ProtectionStatus);
8687

8788
IsArchiveEnabled = protectedItem.IsArchiveEnabled;
88-
SoftDeleteRetentionPeriodInDays = protectedItem.SoftDeleteRetentionPeriodInDays;
89+
SoftDeleteRetentionPeriodInDays = protectedItem.SoftDeleteRetentionPeriodInDays;
8990
IsScheduledForDeferredDelete = protectedItem.IsScheduledForDeferredDelete;
9091
DeferredDeleteTimeInUtc = protectedItem.DeferredDeleteTimeInUtc;
92+
DeferredDeleteTimeRemaining = protectedItem.DeferredDeleteTimeRemaining;
9193

9294
DateOfPurge = null;
9395
DeleteState = EnumUtils.GetEnum<ItemDeleteState>("NotDeleted");
9496
if (protectedItem.IsScheduledForDeferredDelete.HasValue && protectedItem.IsScheduledForDeferredDelete.Value)
95-
{
96-
DateOfPurge = protectedItem.DeferredDeleteTimeInUtc.Value.AddDays((int)protectedItem.SoftDeleteRetentionPeriodInDays);
97+
{
98+
if (!string.IsNullOrEmpty(protectedItem.DeferredDeleteTimeRemaining))
99+
{
100+
TimeSpan timeRemaining;
101+
if (TimeSpan.TryParse(protectedItem.DeferredDeleteTimeRemaining, out timeRemaining))
102+
{
103+
DateOfPurge = protectedItem.DeferredDeleteTimeInUtc.Value.Add(timeRemaining);
104+
}
105+
}
97106
DeleteState = EnumUtils.GetEnum<ItemDeleteState>("ToBeDeleted");
98107
}
99108
}

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/AzureFilesPsBackupProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ private RestAzureNS.AzureOperationResponse<ProtectedItemResource> EnableOrModify
10651065
ProtectionPolicyResource oldPolicy = null;
10661066
ProtectionPolicyResource newPolicy = null;
10671067

1068-
if (parameterSetName != null && parameterSetName.Contains("Modify") && policy != null && policy.Id != null)
1068+
if (parameterSetName != null && parameterSetName.Contains("Modify") && policy != null && policy.Id != null && item.PolicyId != null)
10691069
{
10701070
Dictionary<UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.PolicyId);
10711071
string oldPolicyName = HelperUtils.GetPolicyNameFromPolicyId(keyValueDict, item.PolicyId);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,17 @@ public void TestAzureFSVaultRestore()
107107
"Test-AzureFSVaultRestore"
108108
);
109109
}
110+
111+
[Fact]
112+
[Trait(Category.AcceptanceType, Category.CheckIn)]
113+
[Trait(TestConstants.Workload, TestConstants.AzureFS)]
114+
public void TestAzureFSStopAndResumeProtection()
115+
{
116+
TestRunner.RunTestScript(
117+
$"Import-Module {_AzureFilescommonModule.AsAbsoluteLocation()}",
118+
$"Import-Module {_AzureFilestestModule.AsAbsoluteLocation()}",
119+
"Test-AzureFSStopAndResumeProtection"
120+
);
121+
}
110122
}
111123
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,54 @@ $newPolicyName = "NewAFSBackupPolicy"
5252
# -RetentionPolicy $retentionPolicy `
5353
# -SchedulePolicy $schedulePolicy
5454

55+
function Test-AzureFSStopAndResumeProtection
56+
{
57+
$resourceGroupName = "afs-pstest-rg"
58+
$vaultName = "afs-pstest-vault"
59+
$policyName = "afspolicy1"
60+
$storageAccountName = "afspstestsa"
61+
$fileShareFriendlyName = "donotuse-powershell-fileshare"
62+
63+
try
64+
{
65+
# Get the Recovery Services vault
66+
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
67+
Assert-NotNull $vault
68+
69+
# Get the backup protection policy
70+
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID -Name $policyName
71+
Assert-NotNull $policy
72+
73+
# Get the backup container
74+
$container = Get-AzRecoveryServicesBackupContainer -ContainerType AzureStorage -FriendlyName $storageAccountName -VaultId $vault.ID
75+
Assert-NotNull $container
76+
77+
# Get the backup item
78+
$backupItem = Get-AzRecoveryServicesBackupItem -Container $container -WorkloadType AzureFiles -VaultId $vault.ID -FriendlyName $fileShareFriendlyName
79+
Assert-NotNull $backupItem
80+
Assert-True { $backupItem.ProtectionState -eq "ProtectionStopped" }
81+
82+
# Enable protection
83+
Enable-AzRecoveryServicesBackupProtection -Item $backupItem -Policy $policy -VaultId $vault.ID
84+
85+
# Refresh backup item to get updated state
86+
$backupItem = Get-AzRecoveryServicesBackupItem -Container $container -WorkloadType AzureFiles -VaultId $vault.ID -FriendlyName $fileShareFriendlyName
87+
88+
Assert-True { $backupItem.ProtectionState -eq "IRPending" -or $backupItem.ProtectionState -eq "Protected" }
89+
}
90+
finally
91+
{
92+
# Disable protection and assert state
93+
Disable-AzRecoveryServicesBackupProtection -Item $backupItem -VaultId $vault.ID -Force
94+
95+
# Refresh backup item to get updated state
96+
$backupItem = Get-AzRecoveryServicesBackupItem -Container $container -WorkloadType AzureFiles -VaultId $vault.ID -FriendlyName $fileShareFriendlyName
97+
98+
Assert-True { $backupItem.ProtectionState -eq "ProtectionStopped" }
99+
}
100+
}
101+
102+
55103
function Test-AzureFSRestoreToAnotherRegion
56104
{
57105
# testing AFS restore to different region and resource group than the source

0 commit comments

Comments
 (0)