public static void AssertBackupConfiguration(PeriodicBackupConfiguration configuration) { if (VerifyBackupFrequency(configuration.FullBackupFrequency) == null && VerifyBackupFrequency(configuration.IncrementalBackupFrequency) == null) { throw new ArgumentException("Couldn't parse the cron expressions for both full and incremental backups. " + $"full backup cron expression: {configuration.FullBackupFrequency}, " + $"incremental backup cron expression: {configuration.IncrementalBackupFrequency}"); } var localSettings = configuration.LocalSettings; if (localSettings != null && localSettings.Disabled == false) { if (localSettings.HasSettings() == false) { throw new ArgumentException( $"{nameof(localSettings.FolderPath)} and {nameof(localSettings.GetBackupConfigurationScript)} cannot be both null or empty"); } if (string.IsNullOrEmpty(localSettings.FolderPath) == false) { if (DataDirectoryInfo.CanAccessPath(localSettings.FolderPath, out var error) == false) { throw new ArgumentException(error); } } } var retentionPolicy = configuration.RetentionPolicy; if (retentionPolicy != null && retentionPolicy.Disabled == false) { if (retentionPolicy.MinimumBackupAgeToKeep != null) { if (retentionPolicy.MinimumBackupAgeToKeep.Value.Ticks <= 0) { throw new ArgumentException($"{nameof(RetentionPolicy.MinimumBackupAgeToKeep)} must be positive"); } if (SkipMinimumBackupAgeToKeepValidation == false && retentionPolicy.MinimumBackupAgeToKeep.Value < TimeSpan.FromDays(1)) { throw new ArgumentException($"{nameof(RetentionPolicy.MinimumBackupAgeToKeep)} must be bigger than one day"); } } } CrontabSchedule VerifyBackupFrequency(string backupFrequency) { return(string.IsNullOrWhiteSpace(backupFrequency) ? null : CrontabSchedule.Parse(backupFrequency)); } }
public static void AssertBackupConfigurationInternal(BackupConfiguration configuration) { var localSettings = configuration.LocalSettings; if (localSettings != null && localSettings.Disabled == false) { if (localSettings.HasSettings() == false) { throw new ArgumentException( $"{nameof(localSettings.FolderPath)} and {nameof(localSettings.GetBackupConfigurationScript)} cannot be both null or empty"); } if (string.IsNullOrEmpty(localSettings.FolderPath) == false) { if (DataDirectoryInfo.CanAccessPath(localSettings.FolderPath, out var error) == false) { throw new ArgumentException(error); } } } }