def _list_active_tasks(params): result = [] for tsk in backup_control.ListPendingTasks(): result.append({ 'name': os.path.basename(tsk.localPath), 'path': os.path.dirname(tsk.localPath), 'id': tsk.pathID, 'version': '', 'customer': '', 'mode': 'up', 'progress': '0%', }) for backupID in backup_control.ListRunningBackups(): backup_obj = backup_control.GetRunningBackupObject(backupID) customerGlobalID, remotePath, versionName = packetid.SplitBackupID( backupID) result.append({ 'name': os.path.basename(backup_obj.sourcePath), 'path': os.path.dirname(backup_obj.sourcePath), 'id': remotePath, 'version': versionName, 'customer': customerGlobalID, 'mode': 'up', 'progress': misc.percent2string(backup_obj.progress()), }) # for backupID in restore_monitor.GetWorkingIDs(): # result.append(backupID) return { 'result': result, }
def doPrepareListBackups(self, *args, **kwargs): from storage import backup_rebuilder if backup_control.HasRunningBackup(): # if some backups are running right now no need to rebuild something - too much use of CPU backup_rebuilder.RemoveAllBackupsToWork() lg.out(6, 'backup_monitor.doPrepareListBackups skip all rebuilds') self.automat('list-backups-done') return # take remote and local backups and get union from it allBackupIDs = set( list(backup_matrix.local_files().keys()) + list(backup_matrix.remote_files().keys())) # take only backups from data base allBackupIDs.intersection_update(backup_fs.ListAllBackupIDs()) # remove running backups allBackupIDs.difference_update(backup_control.ListRunningBackups()) # sort it in reverse order - newer backups should be repaired first allBackupIDs = misc.sorted_backup_ids(list(allBackupIDs), True) # add backups to the queue backup_rebuilder.AddBackupsToWork(allBackupIDs) lg.out( 6, 'backup_monitor.doPrepareListBackups %d items:' % len(allBackupIDs)) lg.out(6, ' %s' % allBackupIDs) self.automat('list-backups-done', allBackupIDs)