Exemplo n.º 1
0
def DeleteBackup(backupID,
                 removeLocalFilesToo=True,
                 saveDB=True,
                 calculate=True):
    """
    This removes a single backup ID completely. Perform several operations:

    1) abort backup if it just started and is running at the moment
    2) if we requested for files for this backup we do not need it anymore - remove 'Data' requests
    3) remove interests in transport_control, see ``lib.transport_control.DeleteBackupInterest()``
    4) remove that ID from the index data base
    5) remove local files for this backup ID
    6) remove all remote info for this backup from the memory, see ``p2p.backup_matrix.EraseBackupRemoteInfo()``
    7) also remove local info from memory, see ``p2p.backup_matrix.EraseBackupLocalInfo()``
    8) stop any rebuilding, we will restart it soon
    9) check and calculate used space
    10) save the modified index data base, soon it will be synchronized with "index_synchronizer()" state machine
    """
    backupID = global_id.CanonicalID(backupID)
    # if the user deletes a backup, make sure we remove any work we're doing on it
    # abort backup if it just started and is running at the moment
    if AbortRunningBackup(backupID):
        lg.out(
            8, 'backup_control.DeleteBackup %s is in process, stopping' %
            backupID)
        return True
    from customer import io_throttle
    from . import backup_rebuilder
    lg.out(8, 'backup_control.DeleteBackup ' + backupID)
    # if we requested for files for this backup - we do not need it anymore
    io_throttle.DeleteBackupRequests(backupID)
    io_throttle.DeleteBackupSendings(backupID)
    # remove interests in transport_control
    # callback.delete_backup_interest(backupID)
    # mark it as being deleted in the db, well... just remove it from the index now
    if not backup_fs.DeleteBackupID(backupID):
        return False
    # finally remove local files for this backupID
    if removeLocalFilesToo:
        backup_fs.DeleteLocalBackup(settings.getLocalBackupsDir(), backupID)
    # remove all remote info for this backup from the memory
    backup_matrix.EraseBackupRemoteInfo(backupID)
    # also remove local info
    backup_matrix.EraseBackupLocalInfo(backupID)
    # stop any rebuilding, we will restart it soon
    backup_rebuilder.RemoveAllBackupsToWork()
    backup_rebuilder.SetStoppedFlag()
    # check and calculate used space
    if calculate:
        backup_fs.Scan()
        backup_fs.Calculate()
    # in some cases we want to save the DB later
    if saveDB:
        Save()
        control.request_update([
            ('backupID', backupID),
        ])
    return True
Exemplo n.º 2
0
def OnJobDone(backupID, result):
    """
    A callback method fired when backup is finished.

    Here we need to save the index data base.
    """
    from . import backup_rebuilder
    from customer import io_throttle
    lg.out(4, '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    lg.out(
        4, 'backup_control.OnJobDone [%s] %s, %d more tasks' %
        (backupID, result, len(tasks())))
    jobs().pop(backupID)
    customerGlobalID, remotePath, version = packetid.SplitBackupID(backupID)
    customer_idurl = global_id.GlobalUserToIDURL(customerGlobalID)
    if result == 'done':
        maxBackupsNum = settings.getBackupsMaxCopies()
        if maxBackupsNum:
            item = backup_fs.GetByID(remotePath,
                                     iterID=backup_fs.fsID(customer_idurl))
            if item:
                versions = item.list_versions(sorted=True, reverse=True)
                if len(versions) > maxBackupsNum:
                    for version in versions[maxBackupsNum:]:
                        item.delete_version(version)
                        backupID = packetid.MakeBackupID(
                            customerGlobalID, remotePath, version)
                        backup_rebuilder.RemoveBackupToWork(backupID)
                        io_throttle.DeleteBackupRequests(backupID)
                        io_throttle.DeleteBackupSendings(backupID)
                        # callback.delete_backup_interest(backupID)
                        backup_fs.DeleteLocalBackup(
                            settings.getLocalBackupsDir(), backupID)
                        backup_matrix.EraseBackupLocalInfo(backupID)
                        backup_matrix.EraseBackupLocalInfo(backupID)
        backup_fs.ScanID(remotePath)
        backup_fs.Calculate()
        Save()
        control.request_update([
            ('pathID', remotePath),
        ])
        # TODO: check used space, if we have over use - stop all tasks immediately
        backup_matrix.RepaintBackup(backupID)
    elif result == 'abort':
        DeleteBackup(backupID)
    if len(tasks()) == 0:
        # do we really need to restart backup_monitor after each backup?
        # if we have a lot tasks started this will produce a lot unneeded actions
        # will be smarter to restart it once we finish all tasks
        # because user will probably leave BitDust working after starting a long running operations
        from storage import backup_monitor
        lg.warn('restarting backup_monitor() machine because no tasks left')
        backup_monitor.A('restart')
    reactor.callLater(0, RunTask)
    reactor.callLater(0, FireTaskFinishedCallbacks, remotePath, version,
                      result)
Exemplo n.º 3
0
def DeletePathBackups(pathID,
                      removeLocalFilesToo=True,
                      saveDB=True,
                      calculate=True):
    """
    This removes all backups of given path ID
    Doing same operations as ``DeleteBackup()``.
    """
    from . import backup_rebuilder
    from customer import io_throttle
    pathID = global_id.CanonicalID(pathID)
    # get the working item
    customer, remotePath = packetid.SplitPacketID(pathID)
    customer_idurl = global_id.GlobalUserToIDURL(customer)
    item = backup_fs.GetByID(remotePath, iterID=backup_fs.fsID(customer_idurl))
    if item is None:
        return False
    lg.out(8, 'backup_control.DeletePathBackups ' + pathID)
    # this is a list of all known backups of this path
    versions = item.list_versions()
    for version in versions:
        backupID = packetid.MakeBackupID(customer, remotePath, version)
        lg.out(8, '        removing %s' % backupID)
        # abort backup if it just started and is running at the moment
        AbortRunningBackup(backupID)
        # if we requested for files for this backup - we do not need it anymore
        io_throttle.DeleteBackupRequests(backupID)
        io_throttle.DeleteBackupSendings(backupID)
        # remove interests in transport_control
        # callback.delete_backup_interest(backupID)
        # remove local files for this backupID
        if removeLocalFilesToo:
            backup_fs.DeleteLocalBackup(settings.getLocalBackupsDir(),
                                        backupID)
        # remove remote info for this backup from the memory
        backup_matrix.EraseBackupRemoteInfo(backupID)
        # also remove local info
        backup_matrix.EraseBackupLocalInfo(backupID)
        # finally remove this backup from the index
        item.delete_version(version)
        # lg.out(8, 'backup_control.DeletePathBackups ' + backupID)
    # stop any rebuilding, we will restart it soon
    backup_rebuilder.RemoveAllBackupsToWork()
    backup_rebuilder.SetStoppedFlag()
    # check and calculate used space
    if calculate:
        backup_fs.Scan()
        backup_fs.Calculate()
    # save the index if needed
    if saveDB:
        Save()
        control.request_update()
    return True
Exemplo n.º 4
0
 def doCloseThisBackup(self, arg):
     """
     Action method.
     """
     self.workingBlocksQueue = []
     if _Debug:
         lg.out(_DebugLevel, 'backup_rebuilder.doCloseThisBackup %s about to finish, queue length: %d' % (
             self.currentBackupID, len(_BackupIDsQueue)))
     if self.currentBackupID:
         # clear requesting queue from previous task
         from customer import io_throttle
         io_throttle.DeleteBackupRequests(self.currentBackupID)
     self.currentBackupID = None
     self.currentCustomerIDURL = None
Exemplo n.º 5
0
 def doScanBrokenBlocks(self, arg):
     """
     Action method.
     """
     # if remote data structure is not exist for this backup - create it
     # this mean this is only local backup!
     from storage import backup_matrix
     if self.currentBackupID not in backup_matrix.remote_files():
         backup_matrix.remote_files()[self.currentBackupID] = {}
         # we create empty remote info for every local block
         # range(0) should return []
         for blockNum in range(backup_matrix.local_max_block_numbers().get(
                 self.currentBackupID, -1) + 1):
             backup_matrix.remote_files()[
                 self.currentBackupID][blockNum] = {
                     'D': [0] * contactsdb.num_suppliers(),
                     'P': [0] * contactsdb.num_suppliers()
                 }
     # detect missing blocks from remote info
     self.workingBlocksQueue = backup_matrix.ScanMissingBlocks(
         self.currentBackupID)
     # find the correct max block number for this backup
     # we can have remote and local files
     # will take biggest block number from both
     backupMaxBlock = max(
         backup_matrix.remote_max_block_numbers().get(
             self.currentBackupID, -1),
         backup_matrix.local_max_block_numbers().get(
             self.currentBackupID, -1))
     # now need to remember this biggest block number
     # remote info may have less blocks - need to create empty info for
     # missing blocks
     for blockNum in range(backupMaxBlock + 1):
         if blockNum in backup_matrix.remote_files()[self.currentBackupID]:
             continue
         backup_matrix.remote_files()[self.currentBackupID][blockNum] = {
             'D': [0] * contactsdb.num_suppliers(),
             'P': [0] * contactsdb.num_suppliers()
         }
     # clear requesting queue, remove old packets for this backup, we will
     # send them again
     from customer import io_throttle
     io_throttle.DeleteBackupRequests(self.currentBackupID)
     lg.out(
         8, 'backup_rebuilder.doScanBrokenBlocks for %s : %s' %
         (self.currentBackupID, str(self.workingBlocksQueue)))
     self.automat('backup-ready')
Exemplo n.º 6
0
 def doDeleteBlockRequests(self, arg):
     from customer import io_throttle
     backupID_pattern = self.BackupID + '/' + str(self.BlockNumber) + '-'
     lg.out(12, 'restore.doDeleteBlockRequests %s' % backupID_pattern)
     io_throttle.DeleteBackupRequests(backupID_pattern)
Exemplo n.º 7
0
 def doDeleteAllRequests(self, arg):
     from customer import io_throttle
     io_throttle.DeleteBackupRequests(self.BackupID)
Exemplo n.º 8
0
 def doDeleteAllRequests(self, *args, **kwargs):
     """
     Action method.
     """
     from customer import io_throttle
     io_throttle.DeleteBackupRequests(self.backup_id)
Exemplo n.º 9
0
 def doDeleteAllRequests(self, arg):
     """
     Action method.
     """
     from customer import io_throttle
     io_throttle.DeleteBackupRequests(self.BackupID)