Example #1
0
        public List <BackupHistoryRecord> GetBackupHistory(int tenantId)
        {
            var backupHistory = new List <BackupHistoryRecord>();

            foreach (var record in BackupRepository.GetBackupRecordsByTenantId(tenantId))
            {
                var storage = BackupStorageFactory.GetBackupStorage(record);
                if (storage == null)
                {
                    continue;
                }
                if (storage.IsExists(record.StoragePath))
                {
                    backupHistory.Add(new BackupHistoryRecord
                    {
                        Id          = record.Id,
                        FileName    = record.Name,
                        StorageType = record.StorageType,
                        CreatedOn   = record.CreatedOn,
                        ExpiresOn   = record.ExpiresOn
                    });
                }
                else
                {
                    BackupRepository.DeleteBackupRecord(record.Id);
                }
            }
            return(backupHistory);
        }
Example #2
0
        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);
                }
            }
        }
Example #3
0
        public void DeleteBackup(Guid id)
        {
            var backupRecord = BackupRepository.GetBackupRecord(id);

            BackupRepository.DeleteBackupRecord(backupRecord.Id);

            var storage = BackupStorageFactory.GetBackupStorage(backupRecord);

            if (storage == null)
            {
                return;
            }
            storage.Delete(backupRecord.StoragePath);
        }
Example #4
0
 public void DeleteAllBackups(int tenantId)
 {
     foreach (var backupRecord in BackupRepository.GetBackupRecordsByTenantId(tenantId))
     {
         try
         {
             BackupRepository.DeleteBackupRecord(backupRecord.Id);
             var storage = BackupStorageFactory.GetBackupStorage(backupRecord);
             if (storage == null)
             {
                 continue;
             }
             storage.Delete(backupRecord.StoragePath);
         }
         catch (Exception error)
         {
             Log.Warn("error while removing backup record: {0}", error);
         }
     }
 }