Skip to content

Commit 1ef51f5

Browse files
authored
Added smart tiering for SQL and IaasVM (#19281)
1 parent c8da9a5 commit 1ef51f5

File tree

32 files changed

+5856
-8478
lines changed

32 files changed

+5856
-8478
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public static List<BackupEngineBase> GetBackupEngineModelList(
138138
/// </summary>
139139
public static PolicyBase GetPolicyModelForAzureIaaSVM(ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
140140
PolicyBase policyModel)
141-
{
141+
{
142142
string backupManagementType = Management.RecoveryServices.Backup.Models.BackupManagementType.AzureIaasVM;
143143
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType() !=
144144
typeof(ServiceClientModel.LongTermRetentionPolicy))
@@ -190,7 +190,22 @@ public static PolicyBase GetPolicyModelForAzureIaaSVM(ServiceClientModel.Protect
190190
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).InstantRPDetails.AzureBackupRGNamePrefix;
191191
iaasPolicyModel.AzureBackupRGNameSuffix =
192192
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).InstantRPDetails.AzureBackupRGNameSuffix;
193-
193+
194+
// fetch the smart tiering details
195+
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TieringPolicy != null &&
196+
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TieringPolicy.ContainsKey(ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()))
197+
{
198+
iaasPolicyModel.TieringPolicy = new TieringPolicy();
199+
200+
string tieringMode = ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TieringPolicy[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].TieringMode;
201+
202+
iaasPolicyModel.TieringPolicy.TieringMode = (tieringMode == "TierRecommended") ? TieringMode.TierRecommended : ((tieringMode == "TierAfter") ? TieringMode.TierAllEligible : ((tieringMode == "DoNotTier") ? TieringMode.DoNotTier : 0));
203+
204+
iaasPolicyModel.TieringPolicy.TierAfterDuration = ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TieringPolicy[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].Duration;
205+
206+
iaasPolicyModel.TieringPolicy.TierAfterDurationType = ((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TieringPolicy[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].DurationType;
207+
}
208+
194209
return policyModel;
195210
}
196211

@@ -293,7 +308,7 @@ public static PolicyBase GetPolicyModelForAzureVmWorkload(ServiceClientModel.Pro
293308
policy.RetentionPolicy.GetType());
294309
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
295310
return null;
296-
}
311+
}
297312
}
298313
else if (string.Compare(policy.PolicyType, "Differential") == 0)
299314
{
@@ -347,6 +362,7 @@ public static PolicyBase GetPolicyModelForAzureVmWorkload(ServiceClientModel.Pro
347362
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
348363
azureVmWorkloadPolicyModel.ProtectedItemsCount = ((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.
349364
Properties).ProtectedItemsCount;
365+
350366
return policyModel;
351367
}
352368

@@ -812,6 +828,21 @@ public static void GetPSSubProtectionPolicy(AzureVmWorkloadPolicy azureVmWorkloa
812828
azureVmWorkloadPolicyModel.FullBackupRetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy(
813829
(ServiceClientModel.LongTermRetentionPolicy)subProtectionPolicy.RetentionPolicy,
814830
((ServiceClientModel.AzureVmWorkloadProtectionPolicy)serviceClientResponse.Properties).Settings.TimeZone);
831+
832+
// fetch the smart tiering details
833+
if (subProtectionPolicy.TieringPolicy != null &&
834+
subProtectionPolicy.TieringPolicy.ContainsKey(ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()))
835+
{
836+
azureVmWorkloadPolicyModel.FullBackupTieringPolicy = new TieringPolicy();
837+
838+
string tieringMode = subProtectionPolicy.TieringPolicy[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].TieringMode;
839+
840+
azureVmWorkloadPolicyModel.FullBackupTieringPolicy.TieringMode = (tieringMode == "TierRecommended") ? TieringMode.TierRecommended : ((tieringMode == "TierAfter") ? TieringMode.TierAllEligible : ((tieringMode == "DoNotTier") ? TieringMode.DoNotTier : 0));
841+
842+
azureVmWorkloadPolicyModel.FullBackupTieringPolicy.TierAfterDuration = subProtectionPolicy.TieringPolicy[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].Duration;
843+
844+
azureVmWorkloadPolicyModel.FullBackupTieringPolicy.TierAfterDurationType = subProtectionPolicy.TieringPolicy[ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString()].DurationType;
845+
}
815846
}
816847
else if (string.Compare(subProtectionPolicy.PolicyType, "Differential") == 0)
817848
{

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,47 @@ private static ServiceClientModel.WeeklyRetentionFormat GetServiceClientLTRWeekl
627627

628628
#endregion
629629

630+
#region Tiering Policy conversions
631+
632+
/// <summary>
633+
/// Helper function to convert service tiering policy from ps tiering policy.
634+
/// </summary>
635+
public static IDictionary<string, ServiceClientModel.TieringPolicy> GetServiceClientTieringPolicy(
636+
TieringPolicy tierPolicy, bool isSmartTieringEnabled = false)
637+
{
638+
IDictionary<string, ServiceClientModel.TieringPolicy> tieringPolicy = null;
639+
640+
if (isSmartTieringEnabled)
641+
{
642+
tieringPolicy = new Dictionary<string, ServiceClientModel.TieringPolicy>();
643+
ServiceClientModel.TieringPolicy newTeringPolicy = new ServiceClientModel.TieringPolicy();
644+
if (tierPolicy != null)
645+
{
646+
// tierPolicy.Validate();
647+
648+
newTeringPolicy.TieringMode = (tierPolicy.TieringMode == TieringMode.TierAllEligible) ? ServiceClientModel.TieringMode.TierAfter.ToString() : tierPolicy.TieringMode.ToString();
649+
newTeringPolicy.DurationType = tierPolicy.TierAfterDurationType;
650+
newTeringPolicy.Duration = tierPolicy.TierAfterDuration;
651+
652+
tieringPolicy.Add(ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString(), newTeringPolicy);
653+
}
654+
else // DO NOT TIER
655+
{
656+
newTeringPolicy.TieringMode = ServiceClientModel.TieringMode.DoNotTier.ToString();
657+
tieringPolicy.Add(ServiceClientModel.RecoveryPointTierType.ArchivedRP.ToString(), newTeringPolicy);
658+
}
659+
}
660+
else if (tierPolicy != null)
661+
{
662+
throw new ArgumentException(Resources.SmartTieringNotSupportedForSubscription);
663+
}
664+
665+
return tieringPolicy;
666+
}
667+
668+
#endregion
669+
670+
630671
private static int GetIntegerFromNullableIntgerValue(int? value)
631672
{
632673
return (value.HasValue ? (int)value : default(int));

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public partial class PolicyHelpers
2626
{
2727
public static List<ServiceClientModel.SubProtectionPolicy> GetServiceClientSubProtectionPolicy(
2828
SQLRetentionPolicy retentionPolicy,
29-
SQLSchedulePolicy schedulePolicy)
29+
SQLSchedulePolicy schedulePolicy,
30+
TieringPolicy tieringPolicy, bool isSmartTieringEnabled = false)
3031
{
3132
List<ServiceClientModel.SubProtectionPolicy> subProtectionPolicy =
3233
new List<ServiceClientModel.SubProtectionPolicy>();
@@ -35,7 +36,8 @@ public partial class PolicyHelpers
3536
{
3637
subProtectionPolicy.Add(new ServiceClientModel.SubProtectionPolicy("Full",
3738
GetServiceClientSimpleSchedulePolicy(schedulePolicy.FullBackupSchedulePolicy),
38-
GetServiceClientLongTermRetentionPolicy(retentionPolicy.FullBackupRetentionPolicy)));
39+
GetServiceClientLongTermRetentionPolicy(retentionPolicy.FullBackupRetentionPolicy),
40+
GetServiceClientTieringPolicy(tieringPolicy, isSmartTieringEnabled)));
3941
}
4042
if (schedulePolicy.DifferentialBackupSchedulePolicy != null &&
4143
retentionPolicy.DifferentialBackupRetentionPolicy != null &&
@@ -57,7 +59,7 @@ public partial class PolicyHelpers
5759
}
5860

5961
public static List<ServiceClientModel.SubProtectionPolicy> GetServiceClientSubProtectionPolicy(
60-
AzureVmWorkloadPolicy policy)
62+
AzureVmWorkloadPolicy policy, bool isSmartTieringEnabled = false)
6163
{
6264
List<ServiceClientModel.SubProtectionPolicy> subProtectionPolicy =
6365
new List<ServiceClientModel.SubProtectionPolicy>();
@@ -66,7 +68,8 @@ public partial class PolicyHelpers
6668
{
6769
subProtectionPolicy.Add(new ServiceClientModel.SubProtectionPolicy("Full",
6870
GetServiceClientSimpleSchedulePolicy((SimpleSchedulePolicy)policy.FullBackupSchedulePolicy),
69-
GetServiceClientLongTermRetentionPolicy((LongTermRetentionPolicy)policy.FullBackupRetentionPolicy)));
71+
GetServiceClientLongTermRetentionPolicy((LongTermRetentionPolicy)policy.FullBackupRetentionPolicy),
72+
GetServiceClientTieringPolicy(policy.FullBackupTieringPolicy, isSmartTieringEnabled)));
7073
}
7174
if (policy.DifferentialBackupSchedulePolicy != null &&
7275
policy.DifferentialBackupRetentionPolicy != null &&

src/RecoveryServices/RecoveryServices.Backup.Helpers/Validations/PolicyValidations.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,104 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
2424
/// </summary>
2525
public partial class PolicyHelpers
2626
{
27+
28+
public static void ValidateLongTermRetentionPolicyWithTieringPolicy(LongTermRetentionPolicy ltrPolicy, TieringPolicy tieringPolicy, bool isPreviousTieringPolicy = false) // check resx messages
29+
{
30+
// To enable Archive(either TierRecommended or TierAfter), Monthly or Yearly retention needs to be set
31+
if(tieringPolicy != null && tieringPolicy.TieringMode != TieringMode.DoNotTier )
32+
{
33+
if (!ltrPolicy.IsMonthlyScheduleEnabled && !ltrPolicy.IsYearlyScheduleEnabled)
34+
{
35+
if (!isPreviousTieringPolicy)
36+
{
37+
throw new ArgumentException(Resources.MissingMonthlyOrYearlyRetention);
38+
}
39+
else
40+
{
41+
throw new ArgumentException(Resources.IncompatibleRetentionAndTieringPolicy);
42+
}
43+
}
44+
45+
// For TierRecommended policy: At least one of monthly or yearly retention should be >= 9 months.
46+
if (tieringPolicy.TieringMode == TieringMode.TierRecommended)
47+
{
48+
if ((!ltrPolicy.IsMonthlyScheduleEnabled || ltrPolicy.MonthlySchedule == null || ltrPolicy.MonthlySchedule.DurationCountInMonths < 9) && (!ltrPolicy.IsYearlyScheduleEnabled || ltrPolicy.YearlySchedule == null || (ltrPolicy.YearlySchedule.DurationCountInYears * 12) < 9))
49+
{
50+
if (!isPreviousTieringPolicy)
51+
{
52+
throw new ArgumentException(Resources.IncompatibleRetentionPolicyForTierRecommended);
53+
}
54+
else
55+
{
56+
throw new ArgumentException(Resources.RetentionShouldBeGreaterThan9MonthsOrDisableSmartTiering);
57+
}
58+
}
59+
}
60+
61+
// For TierAfter policy: TierAfter duration needs to be >= 3 months, At least one of monthly or yearly retention should be >= (TierAfter + 6) months.
62+
// e.g. if TierAfter is specified as 6 months, at least one of monthly or yearly retention should be at least 12 months.
63+
if(tieringPolicy.TieringMode == TieringMode.TierAllEligible)
64+
{
65+
// TierAfterDuration for AzureVM should be in Months
66+
if (tieringPolicy.TierAfterDurationType != "Months" && !isPreviousTieringPolicy)
67+
{
68+
throw new ArgumentException(Resources.InvalidDurationTypeForAzureVM);
69+
}
70+
71+
if(tieringPolicy.TierAfterDuration < 3 || ((ltrPolicy.MonthlySchedule == null || ltrPolicy.MonthlySchedule.DurationCountInMonths < tieringPolicy.TierAfterDuration + 6) && (ltrPolicy.YearlySchedule == null || (ltrPolicy.YearlySchedule.DurationCountInYears * 12) < tieringPolicy.TierAfterDuration + 6)))
72+
{
73+
if (!isPreviousTieringPolicy)
74+
{
75+
throw new ArgumentException(Resources.InvalidDurationForTierAllEligiblePolicy);
76+
}
77+
else
78+
{
79+
throw new ArgumentException(Resources.IncompatibleRetentionDurationWithTierAfterDuration);
80+
}
81+
}
82+
}
83+
}
84+
}
85+
86+
public static void ValidateFullBackupRetentionPolicyWithTieringPolicy(LongTermRetentionPolicy ltrPolicy, TieringPolicy tieringPolicy, bool isPreviousTieringPolicy = false) // check resx messages
87+
{
88+
if (tieringPolicy != null && tieringPolicy.TieringMode != TieringMode.DoNotTier)
89+
{
90+
// To enable Archive, Full Backup Policy needs to be set.
91+
if (ltrPolicy == null && !isPreviousTieringPolicy)
92+
{
93+
throw new ArgumentException(Resources.FullBackupRetentionPolicyCantBeNull);
94+
}
95+
96+
// For TierAfter policy: TierAfter duration needs to be >= 45 days, at least one retention policy for full backup (daily / weekly / monthly / yearly) should be >= (TierAfter + 180) days.
97+
// e.g. if TierAfter is specified as 100 days, at least one retention policy for Full Backup needs to be greater than or equal to 280 days.
98+
if (tieringPolicy.TieringMode == TieringMode.TierAllEligible)
99+
{
100+
// TierAfterDuration for AzureWorkload should be in Days
101+
if (tieringPolicy.TierAfterDurationType != "Days" && !isPreviousTieringPolicy)
102+
{
103+
throw new ArgumentException(Resources.InvalidDurationTypeForAzureWorkload);
104+
}
105+
106+
if (tieringPolicy.TierAfterDuration < 45 ||
107+
((!ltrPolicy.IsDailyScheduleEnabled || ltrPolicy.DailySchedule == null || ltrPolicy.DailySchedule.DurationCountInDays < tieringPolicy.TierAfterDuration + 180)
108+
&& (!ltrPolicy.IsWeeklyScheduleEnabled || ltrPolicy.WeeklySchedule == null || (ltrPolicy.WeeklySchedule.DurationCountInWeeks * 7) < tieringPolicy.TierAfterDuration + 180)
109+
&& (!ltrPolicy.IsMonthlyScheduleEnabled || ltrPolicy.MonthlySchedule == null || (ltrPolicy.MonthlySchedule.DurationCountInMonths * 30) < tieringPolicy.TierAfterDuration + 180)
110+
&& (!ltrPolicy.IsYearlyScheduleEnabled || ltrPolicy.YearlySchedule == null || (ltrPolicy.YearlySchedule.DurationCountInYears * 365) < tieringPolicy.TierAfterDuration + 180)))
111+
{
112+
if (!isPreviousTieringPolicy)
113+
{
114+
throw new ArgumentException(Resources.IncompatibleRetentionPolicyWithTierAfterDuration);
115+
}
116+
else
117+
{
118+
throw new ArgumentException(Resources.TierAfterDurationCheckFailedWithRetentionDuration);
119+
}
120+
}
121+
}
122+
}
123+
}
124+
27125
/// <summary>
28126
/// Helper function to validate long term rentention policy and simple schedule policy.
29127
/// </summary>

src/RecoveryServices/RecoveryServices.Backup.Models/AzureDbModels/AzureDbPolicy.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public class AzureDbPolicy : PolicyBase
6464
/// </summary>
6565
public RetentionPolicyBase LogBackupRetentionPolicy { get; set; }
6666

67+
/// <summary>
68+
/// Object defining the tiering policy for full backup.
69+
/// </summary>
70+
public TieringPolicy FullBackupTieringPolicy { get; set; }
71+
6772
public override void Validate()
6873
{
6974
base.Validate();
@@ -87,6 +92,11 @@ public override void Validate()
8792
{
8893
LogBackupRetentionPolicy.Validate();
8994
}
95+
96+
if(FullBackupTieringPolicy != null)
97+
{
98+
FullBackupTieringPolicy.Validate();
99+
}
90100
}
91101
}
92102

0 commit comments

Comments
 (0)