Skip to content

Commit d8b54f2

Browse files
author
Anil Kumar Yelam
committed
Adding more validation for backup settings when backupscheduletype is manual. Added description for new parameters in help file.
1 parent 167dca3 commit d8b54f2

File tree

2 files changed

+8166
-7667
lines changed

2 files changed

+8166
-7667
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/SqlServer/NewAzureRmVMSqlServerAutoBackupConfig.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public string FullBackupFrequency
157157
ValueFromPipelineByPropertyName = true,
158158
HelpMessage = "Hour of the day (0-23) when the Sql Server Full Backup should start")]
159159
[ValidateRange(0, 23)]
160-
public int FullBackupStartHour
160+
public int? FullBackupStartHour
161161
{
162162
get;
163163
set;
@@ -169,7 +169,7 @@ public int FullBackupStartHour
169169
ValueFromPipelineByPropertyName = true,
170170
HelpMessage = "Sql Server Full Backup window in hours")]
171171
[ValidateRange(1, 23)]
172-
public int FullBackupWindowInHours
172+
public int? FullBackupWindowInHours
173173
{
174174
get;
175175
set;
@@ -181,7 +181,7 @@ public int FullBackupWindowInHours
181181
ValueFromPipelineByPropertyName = true,
182182
HelpMessage = "Sql Server Log Backup frequency, once every 1-60 minutes")]
183183
[ValidateRange(1, 60)]
184-
public int LogBackupFrequencyInMinutes
184+
public int? LogBackupFrequencyInMinutes
185185
{
186186
get;
187187
set;
@@ -225,7 +225,10 @@ protected override void ProcessRecord()
225225
autoBackupSettings.BackupScheduleType = BackupScheduleType;
226226

227227
// Set other Backup schedule settings only if BackUpSchedule type is Manual.
228-
if (!string.IsNullOrEmpty(BackupScheduleType) && string.Equals(BackupScheduleType, ValidateSetValues.Manual, StringComparison.InvariantCultureIgnoreCase)) {
228+
if (!string.IsNullOrEmpty(BackupScheduleType) && string.Equals(BackupScheduleType, ValidateSetValues.Manual, StringComparison.InvariantCultureIgnoreCase))
229+
{
230+
ValidateBackupScheduleSettings();
231+
229232
autoBackupSettings.FullBackupFrequency = FullBackupFrequency;
230233
autoBackupSettings.FullBackupStartTime = FullBackupStartHour;
231234
autoBackupSettings.FullBackupWindowHours = FullBackupWindowInHours;
@@ -288,5 +291,31 @@ private static string ConvertToUnsecureString(SecureString securePassword)
288291
Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
289292
}
290293
}
294+
295+
/// <summary>
296+
/// Validates Backup schedule settings when schedule type is Manual.
297+
/// </summary>
298+
private void ValidateBackupScheduleSettings()
299+
{
300+
if (FullBackupFrequency == null)
301+
{
302+
throw new Exception("FullBackupFrequency cannot be null when BackupScheduleType is set to Manual");
303+
}
304+
305+
if (FullBackupStartHour == null)
306+
{
307+
throw new Exception("FullBackupStartTime cannot be null when BackupScheduleType is set to Manual");
308+
}
309+
310+
if (FullBackupWindowInHours == null)
311+
{
312+
throw new Exception("FullBackupStartHour cannot be null when BackupScheduleType is set to Manual");
313+
}
314+
315+
if (LogBackupFrequencyInMinutes == null || LogBackupFrequencyInMinutes % 5 != 0)
316+
{
317+
throw new Exception("LogBackupFrequencyInMinutes cannot be null or should be multiple of 5 when BackupScheduleType is set to Manual");
318+
}
319+
}
291320
}
292321
}

0 commit comments

Comments
 (0)