Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 private static void ValidateCronSettings(CronParams cronParams)
 {
     new CronExpression(cronParams.ToString());
 }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
 private static void ValidateCronSettings(CronParams cronParams)
 {
     new CronExpression(cronParams.ToString());
 }
Exemplo n.º 6
0
        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);
            }
        }