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."); } }
protected override void RunInternal() { var config = BackupConfigurationSection.GetSection(); var pathToWebConfig = FileUtility.GetRootedPath(config.WebConfigs.GetCurrentConfig()); var tempFolderPath = FileUtility.GetRootedPath(config.TempFolder); if (!pathToWebConfig.EndsWith(".config", StringComparison.InvariantCultureIgnoreCase)) { pathToWebConfig = Path.Combine(pathToWebConfig, "web.config"); } if (!Directory.Exists(tempFolderPath)) { Directory.CreateDirectory(tempFolderPath); } var backupFile = CreateBackupFilePath(tempFolderPath); try { var backuper = new BackupManager(backupFile, pathToWebConfig); backuper.ProgressChanged += (sender, args) => { if (args.Progress > 0) { Progress = Math.Max(0, Math.Min((int)args.Progress / 2, 50)); } }; backuper.Save(TenantId); using (var stream = new FileStream(backupFile, FileMode.Open)) using (var progressStream = new ProgressStream(stream)) { progressStream.OnReadProgress += (sender, args) => { Progress = Math.Max(0, Math.Min(100, 50 + args / 2)); }; ExpirationDate = DateTime.UtcNow + config.ExpirePeriod; var storage = StorageFactory.GetStorage(pathToWebConfig, "backupfiles", "backup"); Link = storage.SavePrivate(string.Empty, Path.GetFileName(backupFile), progressStream, ExpirationDate); } NotifyHelper.SendAboutBackupCompleted(TenantId, notificationReceiverId, Link, ExpirationDate); } finally { File.Delete(backupFile); } }
protected override void RunInternal() { var config = BackupConfigurationSection.GetSection(); var pathToCurrentWebConfig = FileUtility.GetRootedPath(config.WebConfigs.GetCurrentConfig()); var pathToTargetWebConfig = FileUtility.GetRootedPath(config.WebConfigs.GetPathForRegion(targetRegion)); var tempFolderPath = config.TempFolder; if (!Directory.Exists(tempFolderPath)) { Directory.CreateDirectory(tempFolderPath); } try { NotifyHelper.SendAboutTransferStart(TenantId, targetRegion, NotifyOnlyOwner); var transferTask = new TransferPortalTask(CoreContext.TenantManager.GetTenant(TenantId), pathToCurrentWebConfig, pathToTargetWebConfig) { BackupDirectory = FileUtility.GetRootedPath(config.TempFolder) }; if (!TransferMail) { transferTask.IgnoreModule(ModuleName.Mail); } transferTask.ProgressChanged += (sender, args) => Progress = args.Progress; transferTask.Message += (sender, args) => { if (args.Reason == MessageReason.Info && Log != null) { Log.Debug(args.Message); } else if (args.Reason == MessageReason.Warning && Log != null) { Log.Warn(args.Message); } }; transferTask.Run(); NotifyHelper.SendAboutTransferComplete(TenantId, targetRegion, GetPortalAddress(pathToTargetWebConfig), NotifyOnlyOwner); } catch { NotifyHelper.SendAboutTransferError(TenantId, targetRegion, GetPortalAddress(pathToCurrentWebConfig), NotifyOnlyOwner); throw; } }
protected override void RunInternal() { var config = BackupConfigurationSection.GetSection(); var pathToWebConfig = FileUtility.GetRootedPath(config.WebConfigs.GetCurrentConfig()); if (!pathToWebConfig.EndsWith(".config", StringComparison.InvariantCultureIgnoreCase)) { pathToWebConfig = Path.Combine(pathToWebConfig, "web.config"); } var tenant = CoreContext.TenantManager.GetTenant(TenantId); tenant.SetStatus(TenantStatus.Restoring); CoreContext.TenantManager.SaveTenant(tenant); var backupManager = new BackupManager(pathToBackupFile, pathToWebConfig); backupManager.ProgressChanged += (sender, args) => { Progress = (int)args.Progress; }; backupManager.Load(); }