Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Az.RecoveryServices.Backup] Added support for AFS VaultStandard Backup Policy #26367

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
return null;
}

if (azureFileSharePolicy.VaultRetentionPolicy != null && azureFileSharePolicy.VaultRetentionPolicy.GetType() !=
typeof(ServiceClientModel.VaultRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown VaultRetentionPolicy object received: " +
azureFileSharePolicy.VaultRetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

if (azureFileSharePolicy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Expand All @@ -273,20 +282,27 @@ public static PolicyBase GetPolicyModelForAzureFileShare(ServiceClientModel.Prot
AzureFileSharePolicy fileSharePolicyModel = policyModel as AzureFileSharePolicy;
fileSharePolicyModel.WorkloadType = WorkloadType.AzureFiles;
fileSharePolicyModel.BackupManagementType = BackupManagementType.AzureStorage;

if(azureFileSharePolicy.RetentionPolicy != null)
{
fileSharePolicyModel.RetentionPolicy =
PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone, backupManagementType);
}

if (azureFileSharePolicy.VaultRetentionPolicy != null)
{
fileSharePolicyModel.RetentionPolicy =
PolicyHelpers.GetPSVaultRetentionPolicy((ServiceClientModel.VaultRetentionPolicy)((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).VaultRetentionPolicy,
IannGeorges marked this conversation as resolved.
Show resolved Hide resolved
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone, backupManagementType);
}

fileSharePolicyModel.SchedulePolicy =
PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).TimeZone);
fileSharePolicyModel.ProtectedItemsCount = ((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.
Properties).ProtectedItemsCount;
Properties).ProtectedItemsCount;
return policyModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Linq;
using ServiceClientModel = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
using CrrModel = Microsoft.Azure.Management.RecoveryServices.Backup.CrossRegionRestore.Models;
using System.Text.Json;

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

if (recoveryPoint.GetType() == typeof(AzureFileShareRecoveryPoint))
{
return ((AzureFileShareRecoveryPoint)recoveryPoint).RecoveryPointTier == Tier;
}

return false;
}).ToList();
}
Expand Down Expand Up @@ -478,7 +484,7 @@ public static RecoveryPointBase GetPSAzureFileRecoveryPoint(
string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);
ServiceClientModel.AzureFileShareRecoveryPoint recoveryPoint =
rp.Properties as ServiceClientModel.AzureFileShareRecoveryPoint;

DateTime recoveryPointTime = DateTime.MinValue;
if (recoveryPoint.RecoveryPointTime.HasValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,52 @@ public static LongTermRetentionPolicy GetPSLongTermRetentionPolicy(
return ltrPolicy;
}

/// <summary>
/// Helper function to convert ps long term retention policy from service response.
/// </summary>
public static VaultRetentionPolicy GetPSVaultRetentionPolicy(
ServiceClientModel.VaultRetentionPolicy serviceClientRetPolicy, string timeZone, string backupManagementType = "")
{
if (serviceClientRetPolicy == null)
{
return null;
}

VaultRetentionPolicy vaultPolicy = new VaultRetentionPolicy();

if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).DailySchedule != null)
{
vaultPolicy.IsDailyScheduleEnabled = true;
vaultPolicy.DailySchedule = GetPSLTRDailySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).DailySchedule, timeZone);
vaultPolicy.DailySchedule.BackupManagementType = backupManagementType;
}

if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).WeeklySchedule != null)
{
vaultPolicy.IsWeeklyScheduleEnabled = true;
vaultPolicy.WeeklySchedule = GetPSLTRWeeklySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).WeeklySchedule, timeZone);
vaultPolicy.WeeklySchedule.BackupManagementType = backupManagementType;
}

if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).MonthlySchedule != null)
{
vaultPolicy.IsMonthlyScheduleEnabled = true;
vaultPolicy.MonthlySchedule = GetPSLTRMonthlySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).MonthlySchedule, timeZone);
vaultPolicy.MonthlySchedule.BackupManagementType = backupManagementType;
}

if (((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).YearlySchedule != null)
{
vaultPolicy.IsYearlyScheduleEnabled = true;
vaultPolicy.YearlySchedule = GetPSLTRYearlySchedule(((ServiceClientModel.LongTermRetentionPolicy)serviceClientRetPolicy.VaultRetention).YearlySchedule, timeZone);
vaultPolicy.YearlySchedule.BackupManagementType = backupManagementType;
}

vaultPolicy.SnapshotRetentionInDays = serviceClientRetPolicy.SnapshotRetentionInDays;
vaultPolicy.BackupManagementType = backupManagementType;
return vaultPolicy;
}

public static SimpleRetentionPolicy GetPSSimpleRetentionPolicy(
ServiceClientModel.SimpleRetentionPolicy hydraRetPolicy, string timeZone, string provider)
{
Expand Down Expand Up @@ -442,7 +488,6 @@ public static ServiceClientModel.LongTermRetentionPolicy GetServiceClientLongTer
{
serviceClientRetPolicy.YearlySchedule = GetServiceClientLTRYearlySchedule(psRetPolicy.YearlySchedule);
}

return serviceClientRetPolicy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
/// </summary>
public class AzureFileShareRecoveryPoint : AzureRecoveryPoint
{
/// <summary>
/// Recovery Type information for Recovery point: "Vault", "Snapshot", "Snapshot and Vault"
/// </summary>
public RecoveryPointTier RecoveryPointTier;

/// <summary>
/// Url to the snapshot of fileshare
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public enum PolicyParams
IsSmartTieringEnabled,
BackupSnapshotResourceGroup,
BackupSnapshotResourceGroupSuffix,
SnapshotConsistencyType
SnapshotConsistencyType,
BackupTier
}

public enum ItemParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,13 @@ public enum ProtectableItemType
SQLInstance,
SQLAvailabilityGroup
}

/// <summary>
/// Options to select the Backup Tier type
/// </summary>
public enum BackupTierType
{
Snapshot = 1,
VaultStandard
IannGeorges marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public override void Validate()
/// </summary>
public class LongTermRetentionPolicy : RetentionPolicyBase
{

/// <summary>
/// Specifies if daily schedule is enabled.
/// </summary>
Expand Down Expand Up @@ -104,7 +105,7 @@ public LongTermRetentionPolicy(string backupManagementType = "")
public override void Validate()
{
// redirecting to overloaded method
Validate(0);
Validate(0);
}

/// <summary>
Expand All @@ -113,7 +114,7 @@ public override void Validate()
public void Validate(ScheduleRunType ScheduleRunFrequency = 0)
{
base.Validate();

if (IsDailyScheduleEnabled == false && IsWeeklyScheduleEnabled == false &&
IsMonthlyScheduleEnabled == false && IsYearlyScheduleEnabled == false)
{
Expand Down Expand Up @@ -187,6 +188,61 @@ public override string ToString()
}
}

/// <summary>
/// Backup vault retention policy class.
/// </summary>
public class VaultRetentionPolicy : LongTermRetentionPolicy
{
/// <summary>
/// Object defining the retention days for a snapshot
/// </summary>
public int SnapshotRetentionInDays { get; set; }

public VaultRetentionPolicy(string backupManagementType = "")
{
SnapshotRetentionInDays = 5;
IsDailyScheduleEnabled = false;
IsWeeklyScheduleEnabled = false;
IsMonthlyScheduleEnabled = false;
IsYearlyScheduleEnabled = false;
this.BackupManagementType = backupManagementType;
}

public override void Validate()
{
// redirecting to overloaded method
Validate(0);
}

/// <summary>
/// Validates null values and other possible combinations
/// </summary>
public new void Validate(ScheduleRunType ScheduleRunFrequency = 0)
{
base.Validate(ScheduleRunFrequency);

int MinDurationCountInDays = 1, MaxDurationCountInDays = PolicyConstants.AfsSnapshotRetentionDaysMax;

if (SnapshotRetentionInDays < MinDurationCountInDays || SnapshotRetentionInDays > MaxDurationCountInDays)
{
throw new ArgumentException(Resources.SnapshotRetentionInDaysInvalidException);
}
}

public override string ToString()
{
return string.Format("SnapshotRetentionInDays:{0}, IsDailyScheduleEnabled:{1}, IsWeeklyScheduleEnabled:{2}, " +
"IsMonthlyScheduleEnabled:{3}, IsYearlyScheduleEnabled:{4} " +
"DailySchedule: {5}, WeeklySchedule: {6}, MonthlySchedule:{7}, YearlySchedule:{8}",
SnapshotRetentionInDays, IsDailyScheduleEnabled, IsWeeklyScheduleEnabled,
IsMonthlyScheduleEnabled, IsYearlyScheduleEnabled,
DailySchedule == null ? "NULL" : DailySchedule.ToString(),
WeeklySchedule == null ? "NULL" : WeeklySchedule.ToString(),
MonthlySchedule == null ? "NULL" : MonthlySchedule.ToString(),
YearlySchedule == null ? "NULL" : YearlySchedule.ToString());
}
}

public class SQLRetentionPolicy : RetentionPolicyBase
{
/// <summary>
Expand Down Expand Up @@ -242,7 +298,7 @@ public override string ToString()
}

/// <summary>
/// Daily rentention schedule.
/// Daily retention schedule.
/// </summary>
public class DailyRetentionSchedule : RetentionScheduleBase
{
Expand All @@ -258,7 +314,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
if(BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
{
MinDurationCountInDays = PolicyConstants.AfsDailyRetentionDaysMin;
MaxDurationCountInDays = PolicyConstants.AfsDailyRetentionDaysMax;
MaxDurationCountInDays = PolicyConstants.AfsVaultDailyRetentionDaysMax;
}
if (DurationCountInDays < MinDurationCountInDays || DurationCountInDays > MaxDurationCountInDays)
{
Expand Down Expand Up @@ -295,7 +351,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
if(BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
{
MinDurationCountInWeeks = PolicyConstants.AfsWeeklyRetentionMin;
MaxDurationCountInWeeks = PolicyConstants.AfsWeeklyRetentionMax;
MaxDurationCountInWeeks = PolicyConstants.AfsVaultWeeklyRetentionMax;
}
if (DurationCountInWeeks < MinDurationCountInWeeks || DurationCountInWeeks > MaxDurationCountInWeeks)
{
Expand Down Expand Up @@ -355,7 +411,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
if (BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
{
MinDurationCountInMonths = PolicyConstants.AfsMonthlyRetentionMin;
MaxDurationCountInMonths = PolicyConstants.AfsMonthlyRetentionMax;
MaxDurationCountInMonths = PolicyConstants.AfsVaultMonthlyRetentionMax;
}

if (DurationCountInMonths < MinDurationCountInMonths || DurationCountInMonths > MaxDurationCountInMonths)
Expand Down Expand Up @@ -439,7 +495,7 @@ public override void Validate(ScheduleRunType ScheduleRunFrequency = 0)
if (BackupManagementType == Management.RecoveryServices.Backup.Models.BackupManagementType.AzureStorage)
{
MinDurationCountInYears = PolicyConstants.AfsYearlyRetentionMin;
MaxDurationCountInYears = PolicyConstants.AfsYearlyRetentionMax;
MaxDurationCountInYears = PolicyConstants.AfsVaultYearlyRetentionMax;
}
if (DurationCountInYears < MinDurationCountInYears || DurationCountInYears > MaxDurationCountInYears)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ public class PolicyConstants
public const int MaxAllowedRetentionDurationCountMonthly = 1188;
public const int MaxAllowedRetentionDurationCountYearly = 99;

public const int AfsSnapshotRetentionDaysMax = 30;
public const int AfsVaultDailyRetentionDaysMax = 9999;
public const int AfsDailyRetentionDaysMax = 200;
public const int AfsDailyRetentionDaysMin = 1;
public const int AfsVaultWeeklyRetentionMax = 5163;
public const int AfsWeeklyRetentionMax = 200;
public const int AfsWeeklyRetentionMin = 1;
public const int AfsVaultMonthlyRetentionMax = 1188;
public const int AfsMonthlyRetentionMax = 120;
public const int AfsMonthlyRetentionMin = 1;
public const int AfsVaultYearlyRetentionMax = 99;
public const int AfsYearlyRetentionMax = 10;
public const int AfsYearlyRetentionMin = 1;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading