@@ -157,7 +157,7 @@ public string FullBackupFrequency
157
157
ValueFromPipelineByPropertyName = true ,
158
158
HelpMessage = "Hour of the day (0-23) when the Sql Server Full Backup should start" ) ]
159
159
[ ValidateRange ( 0 , 23 ) ]
160
- public int FullBackupStartHour
160
+ public int ? FullBackupStartHour
161
161
{
162
162
get ;
163
163
set ;
@@ -169,7 +169,7 @@ public int FullBackupStartHour
169
169
ValueFromPipelineByPropertyName = true ,
170
170
HelpMessage = "Sql Server Full Backup window in hours" ) ]
171
171
[ ValidateRange ( 1 , 23 ) ]
172
- public int FullBackupWindowInHours
172
+ public int ? FullBackupWindowInHours
173
173
{
174
174
get ;
175
175
set ;
@@ -181,7 +181,7 @@ public int FullBackupWindowInHours
181
181
ValueFromPipelineByPropertyName = true ,
182
182
HelpMessage = "Sql Server Log Backup frequency, once every 1-60 minutes" ) ]
183
183
[ ValidateRange ( 1 , 60 ) ]
184
- public int LogBackupFrequencyInMinutes
184
+ public int ? LogBackupFrequencyInMinutes
185
185
{
186
186
get ;
187
187
set ;
@@ -225,7 +225,10 @@ protected override void ProcessRecord()
225
225
autoBackupSettings . BackupScheduleType = BackupScheduleType ;
226
226
227
227
// 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
+
229
232
autoBackupSettings . FullBackupFrequency = FullBackupFrequency ;
230
233
autoBackupSettings . FullBackupStartTime = FullBackupStartHour ;
231
234
autoBackupSettings . FullBackupWindowHours = FullBackupWindowInHours ;
@@ -288,5 +291,31 @@ private static string ConvertToUnsecureString(SecureString securePassword)
288
291
Marshal . ZeroFreeGlobalAllocUnicode ( unmanagedString ) ;
289
292
}
290
293
}
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
+ }
291
320
}
292
321
}
0 commit comments