Beispiel #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 stream import io_throttle
    from storage 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
Beispiel #2
0
def DeletePathBackups(pathID,
                      removeLocalFilesToo=True,
                      saveDB=True,
                      calculate=True):
    """
    This removes all backups of given path ID
    Doing same operations as ``DeleteBackup()``.
    """
    from storage import backup_rebuilder
    from stream 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
 def doScanBrokenBlocks(self, *args, **kwargs):
     """
     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 stream import io_throttle
     io_throttle.DeleteBackupRequests(self.currentBackupID)
     if _Debug:
         lg.out(
             _DebugLevel,
             'backup_rebuilder.doScanBrokenBlocks for %s : %s' %
             (self.currentBackupID, str(self.workingBlocksQueue)))
     self.automat('backup-ready')
 def doCloseThisBackup(self, *args, **kwargs):
     """
     Action method.
     """
     global _BackupIDsQueue
     global _BackupIDsExclude
     self.workingBlocksQueue = []
     if _Debug:
         lg.out(
             _DebugLevel,
             'backup_rebuilder.doCloseThisBackup %s about to finish, queue length: %d'
             % (self.currentBackupID, len(_BackupIDsQueue)))
     if self.currentBackupID:
         RemoveBackupToWork(self.currentBackupID)
         # clear requesting queue from previous task
         from stream import io_throttle
         io_throttle.DeleteBackupRequests(self.currentBackupID)
     self.currentBackupID = None
     self.currentCustomerIDURL = None
Beispiel #5
0
 def doDeleteAllRequests(self, *args, **kwargs):
     """
     Action method.
     """
     from stream import io_throttle
     io_throttle.DeleteBackupRequests(self.backup_id)
Beispiel #6
0
 def _do_block_rebuilding(self):
     from storage import backup_rebuilder
     backup_rebuilder.BlockBackup(self.backup_id)
     io_throttle.DeleteBackupRequests(self.backup_id)