public static IBackupStorage GetBackupStorage(BackupStorageType type, int tenantId)
        {
            var config        = BackupConfigurationSection.GetSection();
            var webConfigPath = PathHelper.ToRootedConfigPath(config.WebConfigs.CurrentPath);

            switch (type)
            {
            case BackupStorageType.Documents:
            case BackupStorageType.ThridpartyDocuments:
                return(new DocumentsBackupStorage(tenantId, webConfigPath));

            case BackupStorageType.DataStore:
                return(new DataStoreBackupStorage(tenantId, webConfigPath));

            case BackupStorageType.CustomCloud:
                var s3Config = CoreContext.Configuration.GetSection <AmazonS3Settings>(tenantId);
                return(new S3BackupStorage(s3Config.AccessKeyId, s3Config.SecretAccessKey, s3Config.Bucket, s3Config.Region));

            case BackupStorageType.Local:
                return(new LocalBackupStorage());

            default:
                throw new InvalidOperationException("Unknown storage type.");
            }
        }
        public static IBackupStorage GetBackupStorage(BackupStorageType type, int tenantId, Dictionary <string, string> storageParams)
        {
            var config        = BackupConfigurationSection.GetSection();
            var webConfigPath = PathHelper.ToRootedConfigPath(config.WebConfigs.CurrentPath);

            switch (type)
            {
            case BackupStorageType.Documents:
            case BackupStorageType.ThridpartyDocuments:
                return(new DocumentsBackupStorage(tenantId, webConfigPath));

            case BackupStorageType.DataStore:
                return(new DataStoreBackupStorage(tenantId, webConfigPath));

            case BackupStorageType.Local:
                return(new LocalBackupStorage());

            case BackupStorageType.ThirdPartyConsumer:
                if (storageParams == null)
                {
                    return(null);
                }
                CoreContext.TenantManager.SetCurrentTenant(tenantId);
                return(new ConsumerBackupStorage(storageParams));

            default:
                throw new InvalidOperationException("Unknown storage type.");
            }
        }
        public void StartRestore(string backupId, BackupStorageType storageType, Dictionary <string, string> storageParams, bool notify)
        {
            DemandPermissionsRestore();

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

            if (Guid.TryParse(backupId, out var guidBackupId))
            {
                restoreRequest.BackupId = guidBackupId;
            }
            else
            {
                restoreRequest.StorageType  = storageType;
                restoreRequest.FilePathOrId = storageParams["filePath"];

                if (restoreRequest.StorageType == BackupStorageType.Local && !CoreBaseSettings.Standalone)
                {
                    restoreRequest.FilePathOrId = BackupFileUploadHandler.GetFilePath();
                }
            }

            BackupService.StartRestore(restoreRequest);
        }
        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);
            }
        }
Beispiel #5
0
        public BackupProgress StartRestore(string backupId, BackupStorageType storageType, Dictionary <string, string> storageParams, bool notify)
        {
            DemandPermissionsRestore();

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

            Guid guidBackupId;

            if (Guid.TryParse(backupId, out guidBackupId))
            {
                restoreRequest.BackupId = guidBackupId;
            }
            else
            {
                restoreRequest.StorageType  = storageType;
                restoreRequest.FilePathOrId = storageParams["filePath"];

                if (restoreRequest.StorageType == BackupStorageType.Local && !CoreContext.Configuration.Standalone)
                {
                    restoreRequest.FilePathOrId = BackupFileUploadHandler.GetFilePath();
                }
            }

            using (var service = new BackupServiceClient())
            {
                return(service.StartRestore(restoreRequest));
            }
        }
Beispiel #6
0
        public void StartBackup(BackupStorageType storageType, Dictionary <string, string> storageParams, bool backupMail)
        {
            DemandPermissionsBackup();
            DemandSize();

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

            switch (storageType)
            {
            case BackupStorageType.ThridpartyDocuments:
            case BackupStorageType.Documents:
                backupRequest.StorageBasePath = storageParams["folderId"];
                break;

            case BackupStorageType.Local:
                if (!CoreBaseSettings.Standalone)
                {
                    throw new Exception("Access denied");
                }
                backupRequest.StorageBasePath = storageParams["filePath"];
                break;
            }

            MessageService.Send(MessageAction.StartBackupSetting);

            BackupService.StartBackup(backupRequest);
        }
Beispiel #7
0
 public RestoreProgressItem(int tenantId, BackupStorageType storageType, string storagePath, bool notify)
 {
     Id          = Guid.NewGuid();
     TenantId    = tenantId;
     StorageType = storageType;
     StoragePath = storagePath;
     Notify      = notify;
 }
Beispiel #8
0
 public BackupProgressItem(bool isScheduled, int tenantId, Guid userId, BackupStorageType storageType, string storageBasePath)
 {
     Id              = Guid.NewGuid();
     IsScheduled     = isScheduled;
     TenantId        = tenantId;
     UserId          = userId;
     StorageType     = storageType;
     StorageBasePath = storageBasePath;
 }
Beispiel #9
0
        public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary <string, string> storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail)
        {
            if (CoreBaseSettings.Standalone)
            {
                TenantExtra.DemandControlPanelPermission();
            }

            BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
        }
Beispiel #10
0
        public void CreateBackupSchedule(BackupStorageType storageType, IEnumerable <ItemKeyValuePair <string, string> > storageParams, int backupsStored, BackupAjaxHandler.CronParams cronParams, bool backupMail)
        {
            if (CoreContext.Configuration.Standalone)
            {
                TenantExtra.DemandControlPanelPermission();
            }

            backupHandler.CreateSchedule(storageType, storageParams.ToDictionary(r => r.Key, r => r.Value), backupsStored, cronParams, backupMail);
        }
Beispiel #11
0
        public BackupProgress StartBackupRestore(string backupId, BackupStorageType storageType, IEnumerable <ItemKeyValuePair <string, string> > storageParams, bool notify)
        {
            if (CoreContext.Configuration.Standalone)
            {
                TenantExtra.DemandControlPanelPermission();
            }

            return(backupHandler.StartRestore(backupId, storageType, storageParams.ToDictionary(r => r.Key, r => r.Value), notify));
        }
Beispiel #12
0
        public void CreateBackupSchedule(BackupStorageType storageType, IEnumerable <ItemKeyValuePair <string, string> > storageParams, int backupsStored, BackupAjaxHandler.CronParams cronParams, bool backupMail)
        {
            if (CoreContext.Configuration.Standalone)
            {
                TenantExtra.DemandControlPanelPermission();
            }
            else
            {
                if (!TenantExtra.GetTenantQuota().AutoBackup)
                {
                    throw new SecurityException(Resource.ErrorNotAllowedOption);
                }
            }

            backupHandler.CreateSchedule(storageType, storageParams.ToDictionary(r => r.Key, r => r.Value), backupsStored, cronParams, backupMail);
        }
        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);
            }
        }
Beispiel #14
0
 public static BackupProgress StartRestore(int tenantId, BackupStorageType storageType, string storagePath, bool notify)
 {
     lock (tasks.SynchRoot)
     {
         var item = tasks.GetItems().OfType <RestoreProgressItem>().FirstOrDefault(t => t.TenantId == tenantId);
         if (item != null && item.IsCompleted)
         {
             tasks.Remove(item);
             item = null;
         }
         if (item == null)
         {
             item = new RestoreProgressItem(tenantId, storageType, storagePath, notify);
             tasks.Add(item);
         }
         return(ToBackupProgress(item));
     }
 }
        public void CreateSchedule(BackupStorageType storageType, Dictionary <string, string> 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,
                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);
            }
        }
Beispiel #16
0
 public static void StartScheduledBackup(int tenantId, bool backupMail, BackupStorageType storageType, string storageBasePath)
 {
     lock (schedulerTasks.SynchRoot)
     {
         var item = schedulerTasks.GetItems().OfType <BackupProgressItem>().FirstOrDefault(t => t.TenantId == tenantId);
         if (item != null && item.IsCompleted)
         {
             schedulerTasks.Remove(item);
             item = null;
         }
         if (item == null)
         {
             item = new BackupProgressItem(true, tenantId, Guid.Empty, storageType, storageBasePath)
             {
                 BackupMail = backupMail
             };
             schedulerTasks.Add(item);
         }
     }
 }
        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));
            }
        }
Beispiel #18
0
        public IBackupStorage GetBackupStorage(BackupStorageType type, int tenantId, Dictionary <string, string> storageParams)
        {
            var settings      = Configuration.GetSetting <BackupSettings>("backup");
            var webConfigPath = PathHelper.ToRootedConfigPath(settings.WebConfigs.CurrentPath);


            switch (type)
            {
            case BackupStorageType.Documents:
            case BackupStorageType.ThridpartyDocuments:
            {
                DocumentsBackupStorage.Init(tenantId, webConfigPath);
                return(DocumentsBackupStorage);
            }

            case BackupStorageType.DataStore:
            {
                DataStoreBackupStorage.Init(tenantId, webConfigPath);
                return(DataStoreBackupStorage);
            }

            case BackupStorageType.Local:
                return(LocalBackupStorage);

            case BackupStorageType.ThirdPartyConsumer:
            {
                if (storageParams == null)
                {
                    return(null);
                }
                TenantManager.SetCurrentTenant(tenantId);
                ConsumerBackupStorage.Init(storageParams);
                return(ConsumerBackupStorage);
            }

            default:
                throw new InvalidOperationException("Unknown storage type.");
            }
        }
        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));
            }
        }
Beispiel #20
0
        public BackupProgress StartBackup(BackupStorageType storageType, Dictionary <string, string> storageParams, bool backupMail)
        {
            DemandPermissionsBackup();

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

            switch (storageType)
            {
            case BackupStorageType.ThridpartyDocuments:
            case BackupStorageType.Documents:
                backupRequest.StorageBasePath = storageParams["folderId"];
                break;

            case BackupStorageType.Local:
                if (!CoreContext.Configuration.Standalone)
                {
                    throw new Exception("Access denied");
                }
                backupRequest.StorageBasePath = storageParams["filePath"];
                break;
            }

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

            using (var service = new BackupServiceClient())
            {
                return(service.StartBackup(backupRequest));
            }
        }
 public void CreateBackupSchedule(BackupStorageType storageType, IEnumerable <ItemKeyValuePair <string, string> > storageParams, int backupsStored, BackupAjaxHandler.CronParams cronParams, bool backupMail)
 {
     backupHandler.CreateSchedule(storageType, storageParams.ToDictionary(r => r.Key, r => r.Value), backupsStored, cronParams, backupMail);
 }
        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);
            }
        }
Beispiel #23
0
 protected internal BackupStorage(BackupStorageType backupStorageType, char pathSeparator)
 {
     this.BackupStorageType = backupStorageType;
     this.PathSeparator     = pathSeparator;
     this.StorageId         = Guid.NewGuid();
 }
Beispiel #24
0
 public static BackupProgress StartBackup(int tenantId, Guid userId, bool backupMail, BackupStorageType storageType, string storageBasePath)
 {
     lock (tasks.SynchRoot)
     {
         var item = tasks.GetItems().OfType <BackupProgressItem>().FirstOrDefault(t => t.TenantId == tenantId);
         if (item != null && item.IsCompleted)
         {
             tasks.Remove(item);
             item = null;
         }
         if (item == null)
         {
             item = new BackupProgressItem(false, tenantId, userId, storageType, storageBasePath)
             {
                 BackupMail = backupMail
             };
             tasks.Add(item);
         }
         return(ToBackupProgress(item));
     }
 }
Beispiel #25
0
 public void CreateBackupSchedule(BackupStorageType storageType, BackupAjaxHandler.StorageParams storageParams, int backupsStored, BackupAjaxHandler.CronParams cronParams, bool backupMail)
 {
     backupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
 }
Beispiel #26
0
 public BackupProgress StartBackup(BackupStorageType storageType, BackupAjaxHandler.StorageParams storageParams, bool backupMail)
 {
     return(backupHandler.StartBackup(storageType, storageParams, backupMail));
 }
Beispiel #27
0
 public BackupProgress StartBackupRestore(string backupId, BackupStorageType storageType, BackupAjaxHandler.StorageParams storageParams, bool notify)
 {
     return(backupHandler.StartRestore(backupId, storageType, storageParams, notify));
 }
 public BackupProgress StartBackup(BackupStorageType storageType, IEnumerable <ItemKeyValuePair <string, string> > storageParams, bool backupMail)
 {
     return(backupHandler.StartBackup(storageType, storageParams.ToDictionary(r => r.Key, r => r.Value), backupMail));
 }
        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);
            }
        }
 public BackupProgress StartBackupRestore(string backupId, BackupStorageType storageType, IEnumerable <ItemKeyValuePair <string, string> > storageParams, bool notify)
 {
     return(backupHandler.StartRestore(backupId, storageType, storageParams.ToDictionary(r => r.Key, r => r.Value), notify));
 }
Beispiel #31
0
        /// <summary>
        /// Constructor to initialize from sub class
        /// </summary>
        /// <param name="backupStorageType"></param>

        protected internal BackupStorage(BackupStorageType backupStorageType)
        {
            this.FriendlyName = String.Empty;
            this.StorageKind  = backupStorageType;
        }