示例#1
0
 def doOverallCheckUp(self, *args, **kwargs):
     """
     Action method.
     """
     if '' in contactsdb.suppliers():
         if _Debug:
             lg.out(
                 _DebugLevel,
                 'backup_monitor.doOverallCheckUp found empty supplier, restart now'
             )
         self.automat('restart')
         return
     if contact_status.listOfflineSuppliers():
         if time.time() - self.last_execution_time > 60:
             # re-sync every 1 min. if at least on supplier is dead
             if _Debug:
                 lg.out(
                     _DebugLevel,
                     'backup_monitor.doOverallCheckUp   restart after 1 min, found offline suppliers'
                 )
             self.automat('restart')
             return
     if time.time() - self.last_execution_time > 60 * 10:
         # also re-sync every 10 min.
         if _Debug:
             lg.out(
                 _DebugLevel,
                 'backup_monitor.doOverallCheckUp   periodic 10 min. restart'
             )
         self.automat('restart')
         return
示例#2
0
 def doRemoveUnusedFiles(self, arg):
     # we want to remove files for this block
     # because we only need them during rebuilding
     if settings.getBackupsKeepLocalCopies() is True:
         # if user set this in settings - he want to keep the local files
         return
     # ... user do not want to keep local backups
     if settings.getGeneralWaitSuppliers() is True:
         from customer import fire_hire
         # but he want to be sure - all suppliers are green for a long time
         if len(contact_status.listOfflineSuppliers(
         )) > 0 or time.time() - fire_hire.GetLastFireTime() < 24 * 60 * 60:
             # some people are not there or we do not have stable team yet
             # do not remove the files because we need it to rebuild
             return
     count = 0
     from storage import backup_matrix
     from storage import restore_monitor
     from storage import backup_rebuilder
     if _Debug:
         lg.out(_DebugLevel, 'data_sender.doRemoveUnusedFiles')
     for backupID in misc.sorted_backup_ids(
             backup_matrix.local_files().keys()):
         if restore_monitor.IsWorking(backupID):
             if _Debug:
                 lg.out(_DebugLevel,
                        '        %s : SKIP, because restoring' % backupID)
             continue
         if backup_rebuilder.IsBackupNeedsWork(backupID):
             if _Debug:
                 lg.out(
                     _DebugLevel,
                     '        %s : SKIP, because needs rebuilding' %
                     backupID)
             continue
         if not backup_rebuilder.ReadStoppedFlag():
             if backup_rebuilder.A().currentBackupID is not None:
                 if backup_rebuilder.A().currentBackupID == backupID:
                     if _Debug:
                         lg.out(
                             _DebugLevel,
                             '        %s : SKIP, because rebuilding is in process'
                             % backupID)
                     continue
         packets = backup_matrix.ScanBlocksToRemove(
             backupID, settings.getGeneralWaitSuppliers())
         for packetID in packets:
             customer, pathID = packetid.SplitPacketID(packetID)
             filename = os.path.join(settings.getLocalBackupsDir(),
                                     customer, pathID)
             if os.path.isfile(filename):
                 try:
                     os.remove(filename)
                     # lg.out(6, '    ' + os.path.basename(filename))
                 except:
                     lg.exc()
                     continue
                 count += 1
     if _Debug:
         lg.out(_DebugLevel, '    %d files were removed' % count)
     backup_matrix.ReadLocalFiles()