Skip to content

Commit 981a03b

Browse files
IannGeorgesianna1-admin
andauthored
[Az.RecoveryServices.Backup] Added support for AFS VaultStandard Backup Policy (#26367)
* initial commit - updated retention object GetBackupRetentionObject working for VaultStandard AFS backup policy, might need to refactor following discussions minor fix revert long term policy changes new vault policy model,create/get cmds are completed set/enable cmds done, initial test for policy policy test complete for # Get-AzRecoveryServicesBackupRetentionPolicyObject, New-AzRecoveryServicesBackupProtectionPolicy, Set-AzRecoveryServicesBackupProtectionPolicy, Get-AzRecoveryServicesBackupProtectionPolicy enable protection with vault policy tests updated cmdlet docs & changelog + addressed feedback refactored enable protection to wait for user confirmation when switching policy tiers fixed client-side validation for enable prot removed comments created resource strings for backup tier validation messages fixed change log & regenerated test json remove comments refactored vault retention policy to use ltr policy as base removing redundant functions after refactoring vault retention policy fix merge conflicts in changelog updated changelog fix changelog update changelog update changelog * added validation for vault standard retention policy * updated error messages * reran tests to record http json * reran failed tests to record http json * remove extra validation * change afs policy max retention constants to support vault standard * fix changelog --------- Co-authored-by: ianna1-admin <[email protected]>
1 parent 43fe7be commit 981a03b

File tree

25 files changed

+10809
-793
lines changed

25 files changed

+10809
-793
lines changed

src/RecoveryServices/RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
260260
return null;
261261
}
262262

263+
if (azureFileSharePolicy.VaultRetentionPolicy != null && azureFileSharePolicy.VaultRetentionPolicy.GetType() !=
264+
typeof(ServiceClientModel.VaultRetentionPolicy))
265+
{
266+
Logger.Instance.WriteDebug("Unknown VaultRetentionPolicy object received: " +
267+
azureFileSharePolicy.VaultRetentionPolicy.GetType());
268+
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
269+
return null;
270+
}
271+
263272
if (azureFileSharePolicy.SchedulePolicy.GetType() !=
264273
typeof(ServiceClientModel.SimpleSchedulePolicy))
265274
{
@@ -273,20 +282,27 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
273282
AzureFileSharePolicy fileSharePolicyModel = policyModel as AzureFileSharePolicy;
274283
fileSharePolicyModel.WorkloadType = WorkloadType.AzureFiles;
275284
fileSharePolicyModel.BackupManagementType = BackupManagementType.AzureStorage;
276-
285+
277286
if(azureFileSharePolicy.RetentionPolicy != null)
278287
{
279288
fileSharePolicyModel.RetentionPolicy =
280289
PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
281290
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone, backupManagementType);
282291
}
292+
293+
if (azureFileSharePolicy.VaultRetentionPolicy != null)
294+
{
295+
fileSharePolicyModel.RetentionPolicy =
296+
PolicyHelpers.GetPSVaultRetentionPolicy((ServiceClientModel.VaultRetentionPolicy)((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).VaultRetentionPolicy,
297+
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone, backupManagementType);
298+
}
283299

284300
fileSharePolicyModel.SchedulePolicy =
285301
PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
286302
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
287303
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone);
288304
fileSharePolicyModel.ProtectedItemsCount = ((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.
289-
Properties).ProtectedItemsCount;
305+
Properties).ProtectedItemsCount;
290306
return policyModel;
291307
}
292308

src/RecoveryServices/RecoveryServices.Backup.Helpers/Conversions/RecoveryPointConversions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Linq;
2020
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2121
using CrrModel = Microsoft.Azure.Management.RecoveryServices.Backup.CrossRegionRestore.Models;
22+
using System.Text.Json;
2223

2324
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2425
{
@@ -69,6 +70,11 @@ public static List<RecoveryPointBase> FilterRPsBasedOnTier(List<RecoveryPointBas
6970
return ((AzureWorkloadRecoveryPoint)recoveryPoint).RecoveryPointTier == Tier;
7071
}
7172

73+
if (recoveryPoint.GetType() == typeof(AzureFileShareRecoveryPoint))
74+
{
75+
return ((AzureFileShareRecoveryPoint)recoveryPoint).RecoveryPointTier == Tier;
76+
}
77+
7278
return false;
7379
}).ToList();
7480
}
@@ -478,7 +484,7 @@ public static RecoveryPointBase GetPSAzureFileRecoveryPoint(
478484
string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);
479485
ServiceClientModel.AzureFileShareRecoveryPoint recoveryPoint =
480486
rp.Properties as ServiceClientModel.AzureFileShareRecoveryPoint;
481-
487+
482488
DateTime recoveryPointTime = DateTime.MinValue;
483489
if (recoveryPoint.RecoveryPointTime.HasValue)
484490
{

src/RecoveryServices/RecoveryServices.Backup.Helpers/Conversions/RetentionPolicyConversions.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,52 @@ public static LongTermRetentionPolicy GetPSLongTermRetentionPolicy(
7575
return ltrPolicy;
7676
}
7777

78+
/// <summary>
79+
/// Helper function to convert ps long term retention policy from service response.
80+
/// </summary>
81+
public static VaultRetentionPolicy GetPSVaultRetentionPolicy(
82+
ServiceClientModel.VaultRetentionPolicy serviceClientRetPolicy, string timeZone, string backupManagementType = "")
83+
{
84+
if (serviceClientRetPolicy == null)
85+
{
86+
return null;
87+
}
88+
89+
VaultRetentionPolicy vaultPolicy = new VaultRetentionPolicy();
90+
91+
if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).DailySchedule != null)
92+
{
93+
vaultPolicy.IsDailyScheduleEnabled = true;
94+
vaultPolicy.DailySchedule = GetPSLTRDailySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).DailySchedule, timeZone);
95+
vaultPolicy.DailySchedule.BackupManagementType = backupManagementType;
96+
}
97+
98+
if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).WeeklySchedule != null)
99+
{
100+
vaultPolicy.IsWeeklyScheduleEnabled = true;
101+
vaultPolicy.WeeklySchedule = GetPSLTRWeeklySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).WeeklySchedule, timeZone);
102+
vaultPolicy.WeeklySchedule.BackupManagementType = backupManagementType;
103+
}
104+
105+
if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).MonthlySchedule != null)
106+
{
107+
vaultPolicy.IsMonthlyScheduleEnabled = true;
108+
vaultPolicy.MonthlySchedule = GetPSLTRMonthlySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).MonthlySchedule, timeZone);
109+
vaultPolicy.MonthlySchedule.BackupManagementType = backupManagementType;
110+
}
111+
112+
if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).YearlySchedule != null)
113+
{
114+
vaultPolicy.IsYearlyScheduleEnabled = true;
115+
vaultPolicy.YearlySchedule = GetPSLTRYearlySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).YearlySchedule, timeZone);
116+
vaultPolicy.YearlySchedule.BackupManagementType = backupManagementType;
117+
}
118+
119+
vaultPolicy.SnapshotRetentionInDays = serviceClientRetPolicy.SnapshotRetentionInDays;
120+
vaultPolicy.BackupManagementType = backupManagementType;
121+
return vaultPolicy;
122+
}
123+
78124
public static SimpleRetentionPolicy GetPSSimpleRetentionPolicy(
79125
ServiceClientModel.SimpleRetentionPolicy hydraRetPolicy, string timeZone, string provider)
80126
{
@@ -442,7 +488,6 @@ public static ServiceClientModel.LongTermRetentionPolicy GetServiceClientLongTer
442488
{
443489
serviceClientRetPolicy.YearlySchedule = GetServiceClientLTRYearlySchedule(psRetPolicy.YearlySchedule);
444490
}
445-
446491
return serviceClientRetPolicy;
447492
}
448493

src/RecoveryServices/RecoveryServices.Backup.Models/AzureFileShareModels/AzureFileShareRecoveryPoint.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
1919
/// </summary>
2020
public class AzureFileShareRecoveryPoint : AzureRecoveryPoint
2121
{
22+
/// <summary>
23+
/// Recovery Type information for Recovery point: "Vault", "Snapshot", "Snapshot and Vault"
24+
/// </summary>
25+
public RecoveryPointTier RecoveryPointTier;
26+
2227
/// <summary>
2328
/// Url to the snapshot of fileshare
2429
/// </summary>

src/RecoveryServices/RecoveryServices.Backup.Models/CmdletParamEnums.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public enum PolicyParams
139139
IsSmartTieringEnabled,
140140
BackupSnapshotResourceGroup,
141141
BackupSnapshotResourceGroupSuffix,
142-
SnapshotConsistencyType
142+
SnapshotConsistencyType,
143+
BackupTier
143144
}
144145

145146
public enum ItemParams

src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Enums.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,13 @@ public enum ProtectableItemType
465465
SQLInstance,
466466
SQLAvailabilityGroup
467467
}
468+
469+
/// <summary>
470+
/// Options to select the Backup Tier type
471+
/// </summary>
472+
public enum BackupTierType
473+
{
474+
Snapshot = 1,
475+
VaultStandard
476+
}
468477
}

src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public override void Validate()
4747
/// </summary>
4848
public class LongTermRetentionPolicy : RetentionPolicyBase
4949
{
50+
5051
/// <summary>
5152
/// Specifies if daily schedule is enabled.
5253
/// </summary>
@@ -104,7 +105,7 @@ public LongTermRetentionPolicy(string backupManagementType = "")
104105
public override void Validate()
105106
{
106107
// redirecting to overloaded method
107-
Validate(0);
108+
Validate(0);
108109
}
109110

110111
/// <summary>
@@ -113,7 +114,7 @@ public override void Validate()
113114
public void Validate(ScheduleRunType ScheduleRunFrequency = 0)
114115
{
115116
base.Validate();
116-
117+
117118
if (IsDailyScheduleEnabled == false && IsWeeklyScheduleEnabled == false &&
118119
IsMonthlyScheduleEnabled == false && IsYearlyScheduleEnabled == false)
119120
{
@@ -187,6 +188,61 @@ public override string ToString()
187188
}
188189
}
189190

191+
/// <summary>
192+
/// Backup vault retention policy class.
193+
/// </summary>
194+
public class VaultRetentionPolicy : LongTermRetentionPolicy
195+
{
196+
/// <summary>
197+
/// Object defining the retention days for a snapshot
198+
/// </summary>
199+
public int SnapshotRetentionInDays { get; set; }
200+
201+
public VaultRetentionPolicy(string backupManagementType = "")
202+
{
203+
SnapshotRetentionInDays = 5;
204+
IsDailyScheduleEnabled = false;
205+
IsWeeklyScheduleEnabled = false;
206+
IsMonthlyScheduleEnabled = false;
207+
IsYearlyScheduleEnabled = false;
208+
this.BackupManagementType = backupManagementType;
209+
}
210+
211+
public override void Validate()
212+
{
213+
// redirecting to overloaded method
214+
Validate(0);
215+
}
216+
217+
/// <summary>
218+
/// Validates null values and other possible combinations
219+
/// </summary>
220+
public new void Validate(ScheduleRunType ScheduleRunFrequency = 0)
221+
{
222+
base.Validate(ScheduleRunFrequency);
223+
224+
int MinDurationCountInDays = 1, MaxDurationCountInDays = PolicyConstants.AfsSnapshotRetentionDaysMax;
225+
226+
if (SnapshotRetentionInDays < MinDurationCountInDays || SnapshotRetentionInDays > MaxDurationCountInDays)
227+
{
228+
throw new ArgumentException(Resources.SnapshotRetentionInDaysInvalidException);
229+
}
230+
}
231+
232+
public override string ToString()
233+
{
234+
return string.Format("SnapshotRetentionInDays:{0}, IsDailyScheduleEnabled:{1}, IsWeeklyScheduleEnabled:{2}, " +
235+
"IsMonthlyScheduleEnabled:{3}, IsYearlyScheduleEnabled:{4} " +
236+
"DailySchedule: {5}, WeeklySchedule: {6}, MonthlySchedule:{7}, YearlySchedule:{8}",
237+
SnapshotRetentionInDays, IsDailyScheduleEnabled, IsWeeklyScheduleEnabled,
238+
IsMonthlyScheduleEnabled, IsYearlyScheduleEnabled,
239+
DailySchedule == null ? "NULL" : DailySchedule.ToString(),
240+
WeeklySchedule == null ? "NULL" : WeeklySchedule.ToString(),
241+
MonthlySchedule == null ? "NULL" : MonthlySchedule.ToString(),
242+
YearlySchedule == null ? "NULL" : YearlySchedule.ToString());
243+
}
244+
}
245+
190246
public class SQLRetentionPolicy : RetentionPolicyBase
191247
{
192248
/// <summary>
@@ -242,7 +298,7 @@ public override string ToString()
242298
}
243299

244300
/// <summary>
245-
/// Daily rentention schedule.
301+
/// Daily retention schedule.
246302
/// </summary>
247303
public class DailyRetentionSchedule : RetentionScheduleBase
248304
{
@@ -258,7 +314,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
258314
if(BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
259315
{
260316
MinDurationCountInDays = PolicyConstants.AfsDailyRetentionDaysMin;
261-
MaxDurationCountInDays = PolicyConstants.AfsDailyRetentionDaysMax;
317+
MaxDurationCountInDays = PolicyConstants.AfsVaultDailyRetentionDaysMax;
262318
}
263319
if (DurationCountInDays < MinDurationCountInDays || DurationCountInDays > MaxDurationCountInDays)
264320
{
@@ -295,7 +351,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
295351
if(BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
296352
{
297353
MinDurationCountInWeeks = PolicyConstants.AfsWeeklyRetentionMin;
298-
MaxDurationCountInWeeks = PolicyConstants.AfsWeeklyRetentionMax;
354+
MaxDurationCountInWeeks = PolicyConstants.AfsVaultWeeklyRetentionMax;
299355
}
300356
if (DurationCountInWeeks < MinDurationCountInWeeks || DurationCountInWeeks > MaxDurationCountInWeeks)
301357
{
@@ -355,7 +411,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
355411
if (BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
356412
{
357413
MinDurationCountInMonths = PolicyConstants.AfsMonthlyRetentionMin;
358-
MaxDurationCountInMonths = PolicyConstants.AfsMonthlyRetentionMax;
414+
MaxDurationCountInMonths = PolicyConstants.AfsVaultMonthlyRetentionMax;
359415
}
360416

361417
if (DurationCountInMonths < MinDurationCountInMonths || DurationCountInMonths > MaxDurationCountInMonths)
@@ -439,7 +495,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
439495
if (BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
440496
{
441497
MinDurationCountInYears = PolicyConstants.AfsYearlyRetentionMin;
442-
MaxDurationCountInYears = PolicyConstants.AfsYearlyRetentionMax;
498+
MaxDurationCountInYears = PolicyConstants.AfsVaultYearlyRetentionMax;
443499
}
444500
if (DurationCountInYears < MinDurationCountInYears || DurationCountInYears > MaxDurationCountInYears)
445501
{

src/RecoveryServices/RecoveryServices.Backup.Models/CommonModels/Utils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ public class PolicyConstants
3333
public const int MaxAllowedRetentionDurationCountMonthly = 1188;
3434
public const int MaxAllowedRetentionDurationCountYearly = 99;
3535

36+
public const int AfsSnapshotRetentionDaysMax = 30;
37+
public const int AfsVaultDailyRetentionDaysMax = 9999;
3638
public const int AfsDailyRetentionDaysMax = 200;
3739
public const int AfsDailyRetentionDaysMin = 1;
40+
public const int AfsVaultWeeklyRetentionMax = 5163;
3841
public const int AfsWeeklyRetentionMax = 200;
3942
public const int AfsWeeklyRetentionMin = 1;
43+
public const int AfsVaultMonthlyRetentionMax = 1188;
4044
public const int AfsMonthlyRetentionMax = 120;
4145
public const int AfsMonthlyRetentionMin = 1;
46+
public const int AfsVaultYearlyRetentionMax = 99;
4247
public const int AfsYearlyRetentionMax = 10;
4348
public const int AfsYearlyRetentionMin = 1;
4449

src/RecoveryServices/RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)