private bool CreateBackupSchedule(BackupSchedule backupSchedule) { if (CoreBaseSettings.Standalone) { TenantExtra.DemandControlPanelPermission(); } var storageType = backupSchedule.StorageType == null ? BackupStorageType.Documents : (BackupStorageType)Int32.Parse(backupSchedule.StorageType); var storageParams = backupSchedule.StorageParams == null ? new Dictionary <string, string>() : backupSchedule.StorageParams.ToDictionary(r => r.Key.ToString(), r => r.Value.ToString()); var backupStored = backupSchedule.BackupsStored == null ? 0 : Int32.Parse(backupSchedule.BackupsStored); var cron = new CronParams() { Period = backupSchedule.CronParams.Period == null ? BackupPeriod.EveryDay : (BackupPeriod)Int32.Parse(backupSchedule.CronParams.Period), Hour = backupSchedule.CronParams.Hour == null ? 0 : Int32.Parse(backupSchedule.CronParams.Hour), Day = backupSchedule.CronParams.Day == null ? 0 : Int32.Parse(backupSchedule.CronParams.Day), }; BackupHandler.CreateSchedule(storageType, storageParams, backupStored, cron, backupSchedule.BackupMail); return(true); }
private static void ValidateCronSettings(CronParams cronParams) { new CronExpression(cronParams.ToString()); }
public void CreateSchedule(BackupStorageType storageType, Dictionary <string, string> storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissionsBackup(); if (!SetupInfo.IsVisibleSettings("AutoBackup")) { throw new InvalidOperationException(Resource.ErrorNotAllowedOption); } ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType, StorageParams = storageParams }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams["folderId"]; break; case BackupStorageType.Local: if (!CoreContext.Configuration.Standalone) { throw new Exception("Access denied"); } scheduleRequest.StorageBasePath = storageParams["filePath"]; break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }
public void CreateSchedule(BackupStorageType storageType, StorageParams storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissionsBackup(); DemandSize(); if (!SetupInfo.IsVisibleSettings("AutoBackup")) { throw new InvalidOperationException(Resource.ErrorNotAllowedOption); } ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams.FolderId; break; case BackupStorageType.CustomCloud: ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection( new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }
public void CreateSchedule(BackupStorageType storageType, StorageParams storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissions(); ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams.FolderId; break; case BackupStorageType.CustomCloud: ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection( new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }