Exemple #1
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();
        }
        internal void DeleteExpiredBackups(BackupCleanerService backupCleanerService)
        {
            log.Debug("started to clean expired backups");

            var backupsToRemove = BackupRepository.GetExpiredBackupRecords();

            log.DebugFormat("found {0} backups which are expired", backupsToRemove.Count);

            if (!backupCleanerService.IsStarted)
            {
                return;
            }
            foreach (var scheduledBackups in BackupRepository.GetScheduledBackupRecords().GroupBy(r => r.TenantId))
            {
                if (!backupCleanerService.IsStarted)
                {
                    return;
                }
                var schedule = BackupRepository.GetBackupSchedule(scheduledBackups.Key);
                if (schedule != null)
                {
                    var scheduledBackupsToRemove = scheduledBackups.OrderByDescending(r => r.CreatedOn).Skip(schedule.BackupsStored).ToList();
                    if (scheduledBackupsToRemove.Any())
                    {
                        log.DebugFormat("only last {0} scheduled backup records are to keep for tenant {1} so {2} records must be removed", schedule.BackupsStored, schedule.TenantId, scheduledBackupsToRemove.Count);
                        backupsToRemove.AddRange(scheduledBackupsToRemove);
                    }
                }
                else
                {
                    backupsToRemove.AddRange(scheduledBackups);
                }
            }

            foreach (var backupRecord in backupsToRemove)
            {
                if (!backupCleanerService.IsStarted)
                {
                    return;
                }
                try
                {
                    var backupStorage = BackupStorageFactory.GetBackupStorage(backupRecord);
                    if (backupStorage == null)
                    {
                        continue;
                    }

                    backupStorage.Delete(backupRecord.StoragePath);

                    BackupRepository.DeleteBackupRecord(backupRecord.Id);
                }
                catch (Exception error)
                {
                    log.Warn("can't remove backup record: {0}", error);
                }
            }
        }
 public BackupServiceLauncher(
     BackupCleanerService cleanerService,
     BackupSchedulerService schedulerService,
     BackupWorker backupWorker,
     ConfigurationExtension configuration,
     BackupListener backupListener,
     NotifyConfiguration notifyConfiguration)
 {
     CleanerService      = cleanerService;
     SchedulerService    = schedulerService;
     BackupWorker        = backupWorker;
     Configuration       = configuration;
     BackupListener      = backupListener;
     NotifyConfiguration = notifyConfiguration;
 }
 public BackupServiceLauncher(
     IServiceProvider serviceProvider,
     BackupCleanerService cleanerService,
     BackupSchedulerService schedulerService,
     BackupWorker backupWorker,
     IConfiguration configuration,
     BackupListener backupListener)
 {
     ServiceProvider  = serviceProvider;
     CleanerService   = cleanerService;
     SchedulerService = schedulerService;
     BackupWorker     = backupWorker;
     Configuration    = configuration;
     BackupListener   = backupListener;
 }
 public void Stop()
 {
     BackupWorker.Stop();
     if (host != null)
     {
         host.Close();
         host = null;
     }
     if (cleanerService != null)
     {
         cleanerService.Stop();
         cleanerService = null;
     }
     if (schedulerService != null)
     {
         schedulerService.Stop();
         schedulerService = null;
     }
 }