Ejemplo n.º 1
0
        public BackupProgress StartBackup(BackupStorageType storageType, StorageParams storageParams, bool backupMail)
        {
            DemandPermissions();

            var backupRequest = new StartBackupRequest
                {
                    TenantId = GetCurrentTenantId(),
                    UserId = SecurityContext.CurrentAccount.ID,
                    BackupMail = backupMail,
                    StorageType = storageType
                };

            switch (storageType)
            {
                case BackupStorageType.ThridpartyDocuments:
                case BackupStorageType.Documents:
                    backupRequest.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())
            {
                return service.StartBackup(backupRequest);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public BackupProgress StartBackup(BackupStorageType storageType, StorageParams storageParams, bool backupMail)
        {
            DemandPermissionsBackup();
            DemandSize();

            var backupRequest = new StartBackupRequest
            {
                TenantId    = GetCurrentTenantId(),
                UserId      = SecurityContext.CurrentAccount.ID,
                BackupMail  = backupMail,
                StorageType = storageType
            };

            switch (storageType)
            {
            case BackupStorageType.ThridpartyDocuments:
            case BackupStorageType.Documents:
                backupRequest.StorageBasePath = storageParams.FolderId;
                break;

            case BackupStorageType.CustomCloud:
                backupRequest.StorageBasePath = storageParams.FilePath;
                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;
            }

            MessageService.Send(HttpContext.Current.Request, MessageAction.StartBackupSetting);

            using (var service = new BackupServiceClient())
            {
                return(service.StartBackup(backupRequest));
            }
        }
Ejemplo n.º 4
0
        public BackupProgress StartRestore(string backupId, BackupStorageType storageType, StorageParams storageParams, bool notify)
        {
            DemandPermissionsRestore();

            var restoreRequest = new StartRestoreRequest
            {
                TenantId = GetCurrentTenantId(),
                NotifyAfterCompletion = notify
            };

            Guid guidBackupId;

            if (Guid.TryParse(backupId, out guidBackupId))
            {
                restoreRequest.BackupId = guidBackupId;
            }
            else
            {
                restoreRequest.StorageType  = storageType;
                restoreRequest.FilePathOrId = storageParams.FilePath;
                if (storageType == 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
                    });
                }
            }

            using (var service = new BackupServiceClient())
            {
                return(service.StartRestore(restoreRequest));
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        public BackupProgress StartRestore(string backupId, BackupStorageType storageType, StorageParams storageParams, bool notify)
        {
            DemandPermissions();

            var restoreRequest = new StartRestoreRequest
                {
                    TenantId = GetCurrentTenantId(),
                    NotifyAfterCompletion = notify
                };

            Guid guidBackupId;
            if (Guid.TryParse(backupId, out guidBackupId))
            {
                restoreRequest.BackupId = guidBackupId;
            }
            else
            {
                restoreRequest.StorageType = storageType;
                restoreRequest.FilePathOrId = storageParams.FilePath;
                if (storageType == 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
                        });
                }
            }

            using (var service = new BackupServiceClient())
            {
                return service.StartRestore(restoreRequest);
            }
        }