示例#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
示例#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 . 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
示例#3
0
 def A(self, event, *args, **kwargs):
     from customer import fire_hire
     from customer import data_sender
     from customer import list_files_orator
     from storage import backup_rebuilder
     from storage import index_synchronizer
     #---READY---
     if self.state == 'READY':
         if event == 'timer-5sec':
             self.doOverallCheckUp(*args, **kwargs)
         elif event == 'restart' or event == 'suppliers-changed' or (
                 event == 'instant' and self.RestartAgain):
             self.state = 'FIRE_HIRE'
             self.RestartAgain = False
             self.doRememberSuppliers(*args, **kwargs)
             fire_hire.A('restart')
     #---LIST_FILES---
     elif self.state == 'LIST_FILES':
         if (event == 'list_files_orator.state' and args[0] == 'NO_FILES'):
             self.state = 'READY'
         elif (event == 'list_files_orator.state'
               and args[0] == 'SAW_FILES'):
             self.state = 'LIST_BACKUPS'
             index_synchronizer.A('pull')
             data_sender.A('restart')
             self.doPrepareListBackups(*args, **kwargs)
         elif event == 'restart':
             self.RestartAgain = True
         elif event == 'suppliers-changed':
             self.state = 'READY'
             self.RestartAgain = True
     #---LIST_BACKUPS---
     elif self.state == 'LIST_BACKUPS':
         if event == 'list-backups-done':
             self.state = 'REBUILDING'
             backup_rebuilder.A('start')
         elif event == 'restart':
             self.RestartAgain = True
         elif event == 'suppliers-changed':
             self.state = 'READY'
             self.RestartAgain = True
         elif event == 'restart':
             self.state = 'FIRE_HIRE'
             fire_hire.A('restart')
     #---REBUILDING---
     elif self.state == 'REBUILDING':
         if (event == 'backup_rebuilder.state'
                 and args[0] in ['DONE', 'STOPPED']):
             self.state = 'READY'
             self.doCleanUpBackups(*args, **kwargs)
             data_sender.A('restart')
         elif event == 'restart' or event == 'suppliers-changed':
             self.state = 'FIRE_HIRE'
             backup_rebuilder.SetStoppedFlag()
             fire_hire.A('restart')
     #---FIRE_HIRE---
     elif self.state == 'FIRE_HIRE':
         if event == 'suppliers-changed' and self.isSuppliersNumberChanged(
                 *args, **kwargs):
             self.state = 'LIST_FILES'
             self.doDeleteAllBackups(*args, **kwargs)
             self.doRememberSuppliers(*args, **kwargs)
             list_files_orator.A('need-files')
         elif event == 'fire-hire-finished':
             self.state = 'LIST_FILES'
             list_files_orator.A('need-files')
         elif event == 'suppliers-changed' and not self.isSuppliersNumberChanged(
                 *args, **kwargs):
             self.state = 'LIST_FILES'
             self.doUpdateSuppliers(*args, **kwargs)
             self.doRememberSuppliers(*args, **kwargs)
             list_files_orator.A('need-files')
         elif event == 'restart':
             self.RestartAgain = True
     #---AT_STARTUP---
     elif self.state == 'AT_STARTUP':
         if event == 'init':
             self.state = 'READY'
             self.RestartAgain = False
     return None