public static List <ServiceClientModel.SubProtectionPolicy> GetServiceClientSubProtectionPolicy( SQLRetentionPolicy retentionPolicy, SQLSchedulePolicy schedulePolicy) { List <ServiceClientModel.SubProtectionPolicy> subProtectionPolicy = new List <ServiceClientModel.SubProtectionPolicy>(); if (schedulePolicy.FullBackupSchedulePolicy != null && retentionPolicy.FullBackupRetentionPolicy != null) { subProtectionPolicy.Add(new ServiceClientModel.SubProtectionPolicy("Full", GetServiceClientSimpleSchedulePolicy(schedulePolicy.FullBackupSchedulePolicy), GetServiceClientLongTermRetentionPolicy(retentionPolicy.FullBackupRetentionPolicy))); } if (schedulePolicy.DifferentialBackupSchedulePolicy != null && retentionPolicy.DifferentialBackupRetentionPolicy != null && schedulePolicy.IsDifferentialBackupEnabled) { subProtectionPolicy.Add(new ServiceClientModel.SubProtectionPolicy("Differential", GetServiceClientSimpleSchedulePolicy(schedulePolicy.DifferentialBackupSchedulePolicy), GetServiceClientSimpleRetentionPolicy(retentionPolicy.DifferentialBackupRetentionPolicy))); } if (schedulePolicy.LogBackupSchedulePolicy != null && retentionPolicy.LogBackupRetentionPolicy != null && schedulePolicy.IsLogBackupEnabled) { subProtectionPolicy.Add(new ServiceClientModel.SubProtectionPolicy("Log", GetServiceClientLogSchedulePolicy(schedulePolicy.LogBackupSchedulePolicy), GetServiceClientSimpleRetentionPolicy(retentionPolicy.LogBackupRetentionPolicy))); } return(subProtectionPolicy); }
public RetentionPolicyBase GetDefaultRetentionPolicyObject() { SQLRetentionPolicy defaultRetention = new SQLRetentionPolicy(); DateTime retentionTime = AzureWorkloadProviderHelper.GenerateRandomScheduleTime(); defaultRetention.FullBackupRetentionPolicy = new CmdletModel.LongTermRetentionPolicy(); defaultRetention.DifferentialBackupRetentionPolicy = new CmdletModel.SimpleRetentionPolicy(); defaultRetention.LogBackupRetentionPolicy = new CmdletModel.SimpleRetentionPolicy(); //Setup FullBackupRetentionPolicy //Daily Retention policy defaultRetention.FullBackupRetentionPolicy.IsDailyScheduleEnabled = true; defaultRetention.FullBackupRetentionPolicy.DailySchedule = new CmdletModel.DailyRetentionSchedule(); defaultRetention.FullBackupRetentionPolicy.DailySchedule.RetentionTimes = new List <DateTime>(); defaultRetention.FullBackupRetentionPolicy.DailySchedule.RetentionTimes.Add(retentionTime); defaultRetention.FullBackupRetentionPolicy.DailySchedule.DurationCountInDays = 180; //TBD make it const //Weekly Retention policy defaultRetention.FullBackupRetentionPolicy.IsWeeklyScheduleEnabled = true; defaultRetention.FullBackupRetentionPolicy.WeeklySchedule = new CmdletModel.WeeklyRetentionSchedule(); defaultRetention.FullBackupRetentionPolicy.WeeklySchedule.DaysOfTheWeek = new List <System.DayOfWeek>(); defaultRetention.FullBackupRetentionPolicy.WeeklySchedule.DaysOfTheWeek.Add(System.DayOfWeek.Sunday); defaultRetention.FullBackupRetentionPolicy.WeeklySchedule.DurationCountInWeeks = 104; //TBD make it const defaultRetention.FullBackupRetentionPolicy.WeeklySchedule.RetentionTimes = new List <DateTime>(); defaultRetention.FullBackupRetentionPolicy.WeeklySchedule.RetentionTimes.Add(retentionTime); //Monthly retention policy defaultRetention.FullBackupRetentionPolicy.IsMonthlyScheduleEnabled = true; defaultRetention.FullBackupRetentionPolicy.MonthlySchedule = new CmdletModel.MonthlyRetentionSchedule(); defaultRetention.FullBackupRetentionPolicy.MonthlySchedule.DurationCountInMonths = 60; //tbd: make it const defaultRetention.FullBackupRetentionPolicy.MonthlySchedule.RetentionTimes = new List <DateTime>(); defaultRetention.FullBackupRetentionPolicy.MonthlySchedule.RetentionTimes.Add(retentionTime); defaultRetention.FullBackupRetentionPolicy.MonthlySchedule.RetentionScheduleFormatType = CmdletModel.RetentionScheduleFormat.Weekly; //Initialize day based schedule defaultRetention.FullBackupRetentionPolicy.MonthlySchedule.RetentionScheduleDaily = AzureWorkloadProviderHelper.GetDailyRetentionFormat(); //Initialize Week based schedule defaultRetention.FullBackupRetentionPolicy.MonthlySchedule.RetentionScheduleWeekly = AzureWorkloadProviderHelper.GetWeeklyRetentionFormat(); //Yearly retention policy defaultRetention.FullBackupRetentionPolicy.IsYearlyScheduleEnabled = true; defaultRetention.FullBackupRetentionPolicy.YearlySchedule = new CmdletModel.YearlyRetentionSchedule(); defaultRetention.FullBackupRetentionPolicy.YearlySchedule.DurationCountInYears = 10; defaultRetention.FullBackupRetentionPolicy.YearlySchedule.RetentionTimes = new List <DateTime>(); defaultRetention.FullBackupRetentionPolicy.YearlySchedule.RetentionTimes.Add(retentionTime); defaultRetention.FullBackupRetentionPolicy.YearlySchedule.RetentionScheduleFormatType = CmdletModel.RetentionScheduleFormat.Weekly; defaultRetention.FullBackupRetentionPolicy.YearlySchedule.MonthsOfYear = new List <Month>(); defaultRetention.FullBackupRetentionPolicy.YearlySchedule.MonthsOfYear.Add(Month.January); defaultRetention.FullBackupRetentionPolicy.YearlySchedule.RetentionScheduleDaily = AzureWorkloadProviderHelper.GetDailyRetentionFormat(); defaultRetention.FullBackupRetentionPolicy.YearlySchedule.RetentionScheduleWeekly = AzureWorkloadProviderHelper.GetWeeklyRetentionFormat(); //Setup DifferentialBackupRetentionPolicy defaultRetention.DifferentialBackupRetentionPolicy.RetentionDurationType = CmdletModel.RetentionDurationType.Days; defaultRetention.DifferentialBackupRetentionPolicy.RetentionCount = 30; //Setup LogBackupRetentionPolicy defaultRetention.LogBackupRetentionPolicy.RetentionDurationType = CmdletModel.RetentionDurationType.Days; defaultRetention.LogBackupRetentionPolicy.RetentionCount = 15; return(defaultRetention); }
public static void ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy( SQLRetentionPolicy ltrPolicy, SQLSchedulePolicy schPolicy) { // for daily schedule, daily retention policy is required if (schPolicy.FullBackupSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Daily && (ltrPolicy.FullBackupRetentionPolicy.DailySchedule == null || ltrPolicy.FullBackupRetentionPolicy.IsDailyScheduleEnabled == false)) { throw new ArgumentException(Resources.DailyRetentionScheduleNullException); } // for weekly schedule, daily retention policy should be NULL // AND weekly retention policy is required if (schPolicy.FullBackupSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Weekly && (ltrPolicy.FullBackupRetentionPolicy.IsDailyScheduleEnabled != false || ltrPolicy.FullBackupRetentionPolicy.WeeklySchedule == null || (ltrPolicy.FullBackupRetentionPolicy.IsWeeklyScheduleEnabled == false))) { throw new ArgumentException(Resources.WeeklyRetentionScheduleNullException); } // validate daily retention schedule with schPolicy if (ltrPolicy.FullBackupRetentionPolicy.DailySchedule != null && ltrPolicy.FullBackupRetentionPolicy.IsDailyScheduleEnabled == true) { ValidateRetentionAndBackupTimes(schPolicy.FullBackupSchedulePolicy.ScheduleRunTimes, ltrPolicy.FullBackupRetentionPolicy.DailySchedule.RetentionTimes); } // validate weekly retention schedule with schPolicy if (ltrPolicy.FullBackupRetentionPolicy.WeeklySchedule != null && ltrPolicy.FullBackupRetentionPolicy.IsWeeklyScheduleEnabled == true) { ValidateRetentionAndBackupTimes(schPolicy.FullBackupSchedulePolicy.ScheduleRunTimes, ltrPolicy.FullBackupRetentionPolicy.WeeklySchedule.RetentionTimes); if (schPolicy.FullBackupSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Weekly) { // count of daysOfWeek should match for weekly schedule if (ltrPolicy.FullBackupRetentionPolicy.WeeklySchedule.DaysOfTheWeek.Count != schPolicy.FullBackupSchedulePolicy.ScheduleRunDays.Count) { throw new ArgumentException(Resources.DaysofTheWeekInWeeklyRetentionException); } // validate days of week ValidateRetentionAndScheduleDaysOfWeek(schPolicy.FullBackupSchedulePolicy.ScheduleRunDays, ltrPolicy.FullBackupRetentionPolicy.WeeklySchedule.DaysOfTheWeek); } } // validate monthly retention schedule with schPolicy if (ltrPolicy.FullBackupRetentionPolicy.MonthlySchedule != null && ltrPolicy.FullBackupRetentionPolicy.IsMonthlyScheduleEnabled == true) { ValidateRetentionAndBackupTimes(schPolicy.FullBackupSchedulePolicy.ScheduleRunTimes, ltrPolicy.FullBackupRetentionPolicy.MonthlySchedule.RetentionTimes); // if backupSchedule is weekly, then user cannot choose 'Daily Retention format' if (schPolicy.FullBackupSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Weekly && ltrPolicy.FullBackupRetentionPolicy.MonthlySchedule.RetentionScheduleFormatType == RetentionScheduleFormat.Daily) { throw new ArgumentException(Resources.MonthlyYearlyInvalidDailyRetentionFormatTypeException); } // for monthly and weeklyFormat, validate days of week if (ltrPolicy.FullBackupRetentionPolicy.MonthlySchedule.RetentionScheduleFormatType == RetentionScheduleFormat.Weekly && schPolicy.FullBackupSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Weekly) { ValidateRetentionAndScheduleDaysOfWeek(schPolicy.FullBackupSchedulePolicy.ScheduleRunDays, ltrPolicy.FullBackupRetentionPolicy.MonthlySchedule. RetentionScheduleWeekly.DaysOfTheWeek); } } // validate yearly retention schedule with schPolicy if (ltrPolicy.FullBackupRetentionPolicy.YearlySchedule != null && ltrPolicy.FullBackupRetentionPolicy.IsYearlyScheduleEnabled == true) { ValidateRetentionAndBackupTimes(schPolicy.FullBackupSchedulePolicy.ScheduleRunTimes, ltrPolicy.FullBackupRetentionPolicy.YearlySchedule.RetentionTimes); // if backupSchedule is weekly, then user cannot choose 'Daily Retention format' if (schPolicy.FullBackupSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Weekly && ltrPolicy.FullBackupRetentionPolicy.YearlySchedule.RetentionScheduleFormatType == RetentionScheduleFormat.Daily) { throw new ArgumentException(Resources.MonthlyYearlyInvalidDailyRetentionFormatTypeException); } // for yearly and weeklyFormat, validate days of week if (ltrPolicy.FullBackupRetentionPolicy.YearlySchedule.RetentionScheduleFormatType == RetentionScheduleFormat.Weekly && schPolicy.FullBackupSchedulePolicy.ScheduleRunFrequency == ScheduleRunType.Weekly) { ValidateRetentionAndScheduleDaysOfWeek(schPolicy.FullBackupSchedulePolicy.ScheduleRunDays, ltrPolicy.FullBackupRetentionPolicy.YearlySchedule. RetentionScheduleWeekly.DaysOfTheWeek); } } }