Example #1
0
        public static void Initialize()
        {
            var backupConfiguration = BackupConfigurationSection.GetSection();

            currentWebConfigPath = ToAbsolute(backupConfiguration.RegionConfigs.GetCurrentConfig());
            if (!currentWebConfigPath.EndsWith(".config", StringComparison.OrdinalIgnoreCase))
            {
                currentWebConfigPath = Path.Combine(currentWebConfigPath, "web.config");
            }

            tmpfolder = ToAbsolute(backupConfiguration.TmpFolder);
            expire    = backupConfiguration.ExpirePeriod;

            tasks   = new ProgressQueue(backupConfiguration.ThreadCount, TimeSpan.FromMinutes(15), false);
            cleaner = new Timer(Clean, expire, expire, expire);

            ThreadPool.QueueUserWorkItem(state =>
            {
                foreach (var tenant in CoreContext.TenantManager
                         .GetTenants()
                         .Where(t => t.Status == TenantStatus.Transfering))
                {
                    tenant.SetStatus(TenantStatus.Active);
                    CoreContext.TenantManager.SaveTenant(tenant);
                    var url = tenant.TenantDomain;
                    if (!url.StartsWith("http://") && !url.StartsWith("https://"))
                    {
                        url = "http://" + url;
                    }
                    NotifyHelper.SendAboutTransferError(tenant.TenantId, string.Empty, url, string.Empty, true);
                }
            });
        }
Example #2
0
        public void Start()
        {
            var config = BackupConfigurationSection.GetSection();

            BackupWorker.Start(config);
            host = new ServiceHost(typeof(BackupService));
            host.Open();

            if (config.Cleaner.ElementInformation.IsPresent)
            {
                cleanerService = new BackupCleanerService {
                    Period = config.Cleaner.Period
                };
                cleanerService.Start();
            }
            if (config.Scheduler.ElementInformation.IsPresent)
            {
                schedulerService = new BackupSchedulerService {
                    Period = config.Scheduler.Period
                };
                schedulerService.Start();
            }
            deleterTempService = new BackupCleanerTempFileService();
            deleterTempService.Start();
        }
        public static void Initialize()
        {
            var config = BackupConfigurationSection.GetSection();

            tasks   = new ProgressQueue(config.ThreadCount, TimeSpan.FromMinutes(15), false);
            cleaner = new Timer(Clean, config.ExpirePeriod, config.ExpirePeriod, config.ExpirePeriod);

            ThreadPool.QueueUserWorkItem(_ => RestoreTransferingTenants());
        }
Example #4
0
        public List <TransferRegion> GetTransferRegions()
        {
            var config        = BackupConfigurationSection.GetSection();
            var currentRegion = config.RegionConfigs.CurrentRegion;

            return((from WebConfigElement configFileElement in config.RegionConfigs
                    let webConfig = ConfigurationHelper.OpenConfiguration(ToAbsolute(configFileElement.Path))
                                    let baseDomain = webConfig.AppSettings.Settings["core.base-domain"].Value
                                                     select new TransferRegion
            {
                Name = configFileElement.Region,
                BaseDomain = baseDomain,
                IsCurrentRegion = configFileElement.Region.Equals(currentRegion, StringComparison.InvariantCultureIgnoreCase)
            }).ToList());
        }
Example #5
0
            public void RunJob()
            {
                try
                {
                    NotifyHelper.SendAboutTransferStart(_tenant.TenantId, _targetRegion, _notifyAllUsers);

                    string targetWebConfigPath = ToAbsolute(BackupConfigurationSection.GetSection().RegionConfigs.GetConfig(_targetRegion).Path);

                    var transferTask = new TransferPortalTask(_tenant, currentWebConfigPath, targetWebConfigPath)
                    {
                        BackupDirectory = tmpfolder
                    };

                    if (!_backupMail)
                    {
                        transferTask.IgnoreModule(ModuleName.Mail);
                    }

                    transferTask.ProgressChanged += (sender, args) => Percentage = args.Progress;
                    transferTask.Message         += (sender, args) =>
                    {
                        if (args.Reason == MessageReason.Info)
                        {
                            log.Debug(args.Message);
                        }
                        else if (args.Reason == MessageReason.Warning)
                        {
                            log.Warn(args.Message);
                        }
                    };

                    transferTask.Run();

                    NotifyHelper.SendAboutTransferComplete(_tenant.TenantId, _targetRegion, GetPortalAddress(targetWebConfigPath), _notifyAllUsers);
                }
                catch (Exception error)
                {
                    log.Error(error);
                    NotifyHelper.SendAboutTransferError(_tenant.TenantId, _targetRegion, GetPortalAddress(currentWebConfigPath), error.Message, _notifyAllUsers);
                    Error = error;
                }
                finally
                {
                    IsCompleted = true;
                }
            }
Example #6
0
        public static void Start(BackupConfigurationSection config)
        {
            limit         = config.Limit;
            upgradesPath  = config.UpgradesPath;
            currentRegion = config.WebConfigs.CurrentRegion;
            configPaths   = config.WebConfigs.Cast <WebConfigElement>().ToDictionary(el => el.Region, el => PathHelper.ToRootedConfigPath(el.Path));
            configPaths[currentRegion] = PathHelper.ToRootedConfigPath(config.WebConfigs.CurrentPath);

            var invalidConfigPath = configPaths.Values.FirstOrDefault(path => !File.Exists(path));

            if (invalidConfigPath != null)
            {
                Log.WarnFormat("Configuration file {0} not found", invalidConfigPath);
            }

            tasks          = new ProgressQueue(config.Service.WorkerCount, TimeSpan.FromMinutes(15), false);
            schedulerTasks = new ProgressQueue(config.Scheduler.WorkerCount, TimeSpan.FromMinutes(15), false);
        }
Example #7
0
        public List <TransferRegion> GetTransferRegions()
        {
            var webConfigs = BackupConfigurationSection.GetSection().WebConfigs;

            return(webConfigs
                   .Cast <WebConfigElement>()
                   .Select(configElement =>
            {
                var config = ConfigurationProvider.Open(PathHelper.ToRootedConfigPath(configElement.Path));
                var baseDomain = config.AppSettings.Settings["core.base-domain"].Value;
                return new TransferRegion
                {
                    Name = configElement.Region,
                    BaseDomain = baseDomain,
                    IsCurrentRegion = configElement.Region.Equals(webConfigs.CurrentRegion, StringComparison.InvariantCultureIgnoreCase)
                };
            })
                   .ToList());
        }
Example #8
0
 public BackupResult TransferPortal(TransferRequest request)
 {
     lock (tasks.SynchRoot)
     {
         var task = tasks.GetItems().OfType <TransferTask>().FirstOrDefault(x => (int)x.Id == request.TenantId);
         if (task != null && task.IsCompleted)
         {
             tasks.Remove(task);
             task = null;
         }
         if (task == null)
         {
             if (request.TargetRegion == BackupConfigurationSection.GetSection().RegionConfigs.CurrentRegion)
             {
                 throw new FaultException("Current and target regions are the same!");
             }
             task = new TransferTask(request);
             tasks.Add(task);
         }
         return(ToResult(task));
     }
 }
Example #9
0
 public BackupResult RestorePortal(int tenantID, string demoID)
 {
     lock (tasks.SynchRoot)
     {
         IProgressItem task = tasks.GetItems().FirstOrDefault(t => (int)t.Id == tenantID);
         if (task != null && task.IsCompleted)
         {
             tasks.Remove(task);
             task = null;
         }
         if (task == null)
         {
             var config     = BackupConfigurationSection.GetSection();
             var demoPortal = config.DemoPortals.GetDemoPortal(demoID) ?? config.DemoPortals.Default;
             if (demoPortal == null)
             {
                 throw new FaultException("Can't find demo portal with id = " + demoID);
             }
             task = new RestoreTask(tenantID, demoPortal.DataPath);
             tasks.Add(task);
         }
         return(ToResult(task));
     }
 }
Example #10
0
 private static void Clean(object period)
 {
     try
     {
         lock (tasks.SynchRoot)
         {
             foreach (var item in tasks.GetItems().Where(i => i.IsCompleted).ToList())
             {
                 var backupItem = item as BackupProgressItem;
                 if (backupItem == null || backupItem.ExpirationDate < DateTime.UtcNow)
                 {
                     tasks.Remove(item);
                 }
             }
         }
         var pathToWebConfig = FileUtility.GetRootedPath(BackupConfigurationSection.GetSection().WebConfigs.GetCurrentConfig());
         var store           = StorageFactory.GetStorage(pathToWebConfig, "backupfiles", "backup");
         store.DeleteExpired(string.Empty, string.Empty, (TimeSpan)period);
     }
     catch (Exception error)
     {
         log.Error(error);
     }
 }
Example #11
0
 public List <string> GetDemoData()
 {
     return(BackupConfigurationSection.GetSection().DemoPortals.Cast <DemoPortalElement>().Select(demoData => demoData.ID).ToList());
 }