Exemple #1
0
        public void StartRestore(StartRestoreRequest request)
        {
            if ((BackupStorageType)request.StorageType == BackupStorageType.Local)
            {
                if (string.IsNullOrEmpty(request.FilePathOrId) || !File.Exists(request.FilePathOrId))
                {
                    throw new FileNotFoundException();
                }
            }

            if (!request.BackupId.Equals(Guid.Empty))
            {
                var backupRecord = BackupRepository.GetBackupRecord(request.BackupId);
                if (backupRecord == null)
                {
                    throw new FileNotFoundException();
                }

                request.FilePathOrId  = backupRecord.StoragePath;
                request.StorageType   = backupRecord.StorageType;
                request.StorageParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(backupRecord.StorageParams);
            }

            var progress = BackupWorker.StartRestore(request);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException();
            }
        }
        public BackupProgress StartRestore(StartRestoreRequest request)
        {
            if (request.StorageType == BackupStorageType.Local)
            {
                if (string.IsNullOrEmpty(request.FilePathOrId) || !File.Exists(request.FilePathOrId))
                {
                    throw new FileNotFoundException();
                }
            }

            if (!request.BackupId.Equals(Guid.Empty))
            {
                var backupRepository = BackupStorageFactory.GetBackupRepository();
                var backupRecord     = backupRepository.GetBackupRecord(request.BackupId);
                if (backupRecord == null)
                {
                    throw new FileNotFoundException();
                }

                request.FilePathOrId  = backupRecord.StoragePath;
                request.StorageType   = backupRecord.StorageType;
                request.StorageParams = backupRecord.StorageParams;
            }

            var progress = BackupWorker.StartRestore(request);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException(progress.Error);
            }
            return(progress);
        }
Exemple #3
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 void ScheduleBackupTasks(BackupSchedulerService backupSchedulerService)
        {
            Log.DebugFormat("started to schedule backups");
            var backupsToSchedule = BackupRepository.GetBackupSchedules().Where(schedule => Schedule.IsToBeProcessed(schedule)).ToList();

            Log.DebugFormat("{0} backups are to schedule", backupsToSchedule.Count);
            foreach (var schedule in backupsToSchedule)
            {
                if (!backupSchedulerService.IsStarted)
                {
                    return;
                }
                try
                {
                    var tariff = PaymentManager.GetTariff(schedule.TenantId);
                    if (tariff.State < TariffState.Delay)
                    {
                        schedule.LastBackupTime = DateTime.UtcNow;
                        BackupRepository.SaveBackupSchedule(schedule);
                        Log.DebugFormat("Start scheduled backup: {0}, {1}, {2}, {3}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath);
                        BackupWorker.StartScheduledBackup(schedule);
                    }
                    else
                    {
                        Log.DebugFormat("Skip portal {0} not paid", schedule.TenantId);
                    }
                }
                catch (Exception error)
                {
                    Log.Error("error while scheduling backups: {0}", error);
                }
            }
        }
Exemple #5
0
        public void StartTransfer(StartTransferRequest request)
        {
            var progress = BackupWorker.StartTransfer(request.TenantId, request.TargetRegion, request.BackupMail, request.NotifyUsers);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException();
            }
        }
Exemple #6
0
        public void StartBackup(StartBackupRequest request)
        {
            var progress = BackupWorker.StartBackup(request);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException();
            }
        }
        public BackupProgress GetBackupProgress(int tenantId)
        {
            var progress = BackupWorker.GetBackupProgress(tenantId);

            if (progress != null && !string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException(progress.Error);
            }
            return(progress);
        }
Exemple #8
0
        public BackupProgress StartBackup(StartBackupRequest request)
        {
            var progress = BackupWorker.StartBackup(request.TenantId, request.UserId, request.BackupMail, request.StorageType, request.StorageBasePath);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException(progress.Error);
            }
            return(progress);
        }
Exemple #9
0
        public BackupProgress GetTransferProgress(int tenantID)
        {
            var progress = BackupWorker.GetTransferProgress(tenantID);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException(progress.Error);
            }
            return(progress);
        }
 private void ScheduleBackupTasks()
 {
     if (Monitor.TryEnter(schedulerLock))
     {
         try
         {
             log.DebugFormat("started to schedule backups");
             var backupRepostory   = BackupStorageFactory.GetBackupRepository();
             var backupsToSchedule = backupRepostory.GetBackupSchedules().Where(schedule => schedule.IsToBeProcessed()).ToList();
             log.DebugFormat("{0} backups are to schedule", backupsToSchedule.Count);
             foreach (var schedule in backupsToSchedule)
             {
                 if (!isStarted)
                 {
                     return;
                 }
                 try
                 {
                     if (CoreContext.Configuration.Standalone || CoreContext.TenantManager.GetTenantQuota(schedule.TenantId).AutoBackup)
                     {
                         var tariff = CoreContext.PaymentManager.GetTariff(schedule.TenantId);
                         if (tariff.State < TariffState.Delay)
                         {
                             schedule.LastBackupTime = DateTime.UtcNow;
                             backupRepostory.SaveBackupSchedule(schedule);
                             log.DebugFormat("Start scheduled backup: {0}, {1}, {2}, {3}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath);
                             BackupWorker.StartScheduledBackup(schedule);
                         }
                         else
                         {
                             log.DebugFormat("Skip portal {0} not paid", schedule.TenantId);
                         }
                     }
                     else
                     {
                         log.DebugFormat("Skip portal {0} haven't access", schedule.TenantId);
                     }
                 }
                 catch (Exception error)
                 {
                     log.Error("error while scheduling backups: {0}", error);
                 }
             }
         }
         catch (Exception error)
         {
             log.Error("error while scheduling backups: {0}", error);
         }
         finally
         {
             Monitor.Exit(schedulerLock);
         }
     }
 }
 public BackupSchedulerServiceHelper(
     IOptionsMonitor <ILog> options,
     PaymentManager paymentManager,
     BackupWorker backupWorker,
     BackupRepository backupRepository,
     Schedule schedule)
 {
     PaymentManager   = paymentManager;
     BackupWorker     = backupWorker;
     BackupRepository = backupRepository;
     Schedule         = schedule;
     Log = options.CurrentValue;
 }
Exemple #12
0
 public BackupService(
     IOptionsMonitor <ILog> options,
     BackupStorageFactory backupStorageFactory,
     BackupWorker backupWorker,
     BackupRepository backupRepository,
     ConfigurationExtension configuration)
 {
     Log = options.CurrentValue;
     BackupStorageFactory = backupStorageFactory;
     BackupWorker         = backupWorker;
     BackupRepository     = backupRepository;
     Configuration        = configuration;
 }
 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 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 Task StopAsync(CancellationToken cancellationToken)
 {
     BackupWorker.Stop();
     BackupListener.Stop();
     if (CleanerService != null)
     {
         CleanerService.Stop();
         CleanerService = null;
     }
     if (SchedulerService != null)
     {
         SchedulerService.Stop();
         SchedulerService = null;
     }
     return(Task.CompletedTask);
 }
 public BackupSchedulerServiceHelper(
     IOptionsMonitor <ILog> options,
     PaymentManager paymentManager,
     BackupWorker backupWorker,
     BackupRepository backupRepository,
     Schedule schedule,
     TenantManager tenantManager,
     CoreBaseSettings coreBaseSettings)
 {
     PaymentManager   = paymentManager;
     BackupWorker     = backupWorker;
     BackupRepository = backupRepository;
     Schedule         = schedule;
     TenantManager    = tenantManager;
     CoreBaseSettings = coreBaseSettings;
     Log = options.CurrentValue;
 }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            NotifyConfiguration.Configure();

            var settings = Configuration.GetSetting <BackupSettings>("backup");

            BackupWorker.Start(settings);
            BackupListener.Start();

            CleanerService.Period = settings.Cleaner.Period;
            CleanerService.Start();

            SchedulerService.Period = settings.Scheduler.Period;
            SchedulerService.Start();

            return(Task.CompletedTask);
        }
 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;
     }
 }
Exemple #19
0
        public BackupProgress StartRestore(StartRestoreRequest request)
        {
            if (!request.BackupId.Equals(Guid.Empty))
            {
                var backupRepository = BackupStorageFactory.GetBackupRepository();
                var backupRecord     = backupRepository.GetBackupRecord(request.BackupId);
                if (backupRecord == null)
                {
                    throw new FileNotFoundException();
                }

                request.FilePathOrId = backupRecord.StoragePath;
                request.StorageType  = backupRecord.StorageType;
            }

            var progress = BackupWorker.StartRestore(request.TenantId, request.StorageType, request.FilePathOrId, request.NotifyAfterCompletion);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException(progress.Error);
            }
            return(progress);
        }
Exemple #20
0
 public BackupProgress GetRestoreProgress(int tenantId)
 {
     return(BackupWorker.GetRestoreProgress(tenantId));
 }
Exemple #21
0
 public BackupProgress GetTransferProgress(int tenantId)
 {
     return(BackupWorker.GetTransferProgress(tenantId));
 }