def _delete(params): # localPath = params['path'].lstrip('/') pathID = params['id'] if not packetid.Valid(pathID): return { 'result': { "success": False, "error": "path %s is not valid" % pathID } } if not backup_fs.ExistsID(pathID): return { 'result': { "success": False, "error": "path %s not found" % pathID } } backup_control.DeletePathBackups(pathID, saveDB=False, calculate=False) backup_fs.DeleteLocalDir(settings.getLocalBackupsDir(), pathID) backup_fs.DeleteByID(pathID) backup_fs.Scan() backup_fs.Calculate() backup_control.Save() control.request_update([ ('pathID', pathID), ]) backup_monitor.A('restart') return {'result': {"success": True, "error": None}}
def _delete_version(params): lg.out(6, '_delete_version %s' % str(params)) backupID = params['backupid'] if not packetid.Valid(backupID): return { 'result': { "success": False, "error": "backupID %s is not valid" % backupID } } customerGlobalID, remotePath, version = packetid.SplitBackupID(backupID) if not customerGlobalID: customerGlobalID = my_id.getGlobalID() if not backup_fs.ExistsID( remotePath, iterID=backup_fs.fsID( global_id.GlobalUserToIDURL(customerGlobalID))): return { 'result': { "success": False, "error": "path %s not found" % remotePath } } if version: backup_control.DeleteBackup(backupID, saveDB=False, calculate=False) backup_fs.Scan() backup_fs.Calculate() backup_control.Save() backup_monitor.A('restart') control.request_update([ ('backupID', backupID), ]) return {'result': {"success": True, "error": None}}
def _download(params): # localName = params['name'] backupID = global_id.CanonicalID(params['backupid']) destpath = params['dest_path'] if bpio.Linux() or bpio.Mac(): destpath = '/' + destpath.lstrip('/') restorePath = bpio.portablePath(destpath) # overwrite = params['overwrite'] customerGlobalID, remotePath, version = packetid.SplitBackupID(backupID) pathID = packetid.MakeBackupID(customerGlobalID, remotePath) if not customerGlobalID: customerGlobalID = my_id.getGlobalID() if not packetid.IsCanonicalVersion(version): return {'result': {"success": False, "error": "path %s is not valid" % backupID}} if not remotePath: return {'result': {"success": False, "error": "path %s is not valid" % backupID}} if not packetid.Valid(remotePath): return {'result': {"success": False, "error": "path %s is not valid" % backupID}} if backup_control.IsBackupInProcess(backupID): return {'result': {"success": True, "error": None}} if backup_control.HasTask(pathID): return {'result': {"success": True, "error": None}} localPath = backup_fs.ToPath(remotePath) if localPath == restorePath: restorePath = os.path.dirname(restorePath) def _itemRestored(backupID, result): customerGlobalID, remotePath, _ = packetid.SplitBackupID(backupID) backup_fs.ScanID(remotePath, customer_idurl=global_id.GlobalUserToIDURL(customerGlobalID)) backup_fs.Calculate() restore_monitor.Start(backupID, restorePath, callback=_itemRestored) return {'result': {"success": True, "error": None}}
def make_valid_filename(customerIDURL, glob_path): """ Must be a customer, and then we make full path filename for where this packet is stored locally. """ keyAlias = glob_path['key_alias'] or 'master' packetID = glob_path['path'] customerGlobID = glob_path['customer'] if not customerGlobID: lg.warn("customer id is empty") return '' if not packetid.Valid(packetID): # SECURITY if packetID not in [ settings.BackupInfoFileName(), settings.BackupInfoFileNameOld(), settings.BackupInfoEncryptedFileName(), settings.BackupIndexFileName() ]: lg.warn('invalid file path') return '' if not contactsdb.is_customer(customerIDURL): # SECURITY lg.warn("%s is not my customer" % (customerIDURL)) if customerGlobID: if glob_path['idurl'] != customerIDURL: lg.warn('making filename for another customer: %s != %s' % (glob_path['idurl'], customerIDURL)) filename = make_filename(customerGlobID, packetID, keyAlias) return filename
def ListSummary(dirlist): """ Take directory listing and make summary of format:: BackupID-1-Data 1-1873 missing for 773,883, BackupID-1-Parity 1-1873 missing for 777,982, """ BackupMax = {} BackupAll = {} result = "" for filename in dirlist: if not packetid.Valid(filename): # if not type we can summarize result += filename + "\n" # then just include filename else: BackupID, BlockNum, SupNum, DataOrParity = packetid.BidBnSnDp( filename) LocalID = BackupID + "-" + str(SupNum) + "-" + DataOrParity blocknum = int(BlockNum) BackupAll[(LocalID, blocknum)] = True if LocalID in BackupMax: if BackupMax[LocalID] < blocknum: BackupMax[LocalID] = blocknum else: BackupMax[LocalID] = blocknum for BackupName in sorted(BackupMax.keys()): missing = [] thismax = BackupMax[BackupName] for blocknum in range(0, thismax): if not (BackupName, blocknum) in BackupAll: missing.append(str(blocknum)) result += BackupName + " from 0-" + str(thismax) if len(missing) > 0: result += ' missing ' result += ','.join(missing) # for m in missing: # result += str(m) + "," result += "\n" return result
def makeFilename(customerIDURL, packetID): """ Must be a customer, and then we make full path filename for where this packet is stored locally. """ customerGlobID, packetID = packetid.SplitPacketID(packetID) if not packetid.Valid(packetID): # SECURITY if packetID not in [ settings.BackupInfoFileName(), settings.BackupInfoFileNameOld(), settings.BackupInfoEncryptedFileName(), settings.BackupIndexFileName() ]: # lg.out(1, "p2p_service.makeFilename ERROR failed packetID format: " + packetID ) return '' if not contactsdb.is_customer(customerIDURL): # SECURITY lg.warn("%s is not a customer" % (customerIDURL)) return '' if customerGlobID: customerIDURL_packet = global_id.GlobalUserToIDURL(customerGlobID) if customerIDURL_packet != customerIDURL: lg.warn('making filename for another customer: %s != %s' % (customerIDURL_packet, customerIDURL)) return constructFilename(customerIDURL, packetID)
def cb(result, realpath, subpath, name): if not os.access(realpath, os.R_OK): return False if os.path.isfile(realpath): try: filesz = os.path.getsize(realpath) except: filesz = -1 result.write('F%s %d\n' % (subpath, filesz)) return False if not packetid.IsCanonicalVersion(name): result.write('D%s\n' % subpath) return True maxBlock = -1 versionSize = {} dataBlocks = {} parityBlocks = {} dataMissing = {} parityMissing = {} for filename in os.listdir(realpath): packetID = subpath + '/' + filename pth = os.path.join(realpath, filename) try: filesz = os.path.getsize(pth) except: filesz = -1 if os.path.isdir(pth): result.write('D%s\n' % packetID) continue if not packetid.Valid(packetID): result.write('F%s %d\n' % (packetID, filesz)) continue customer, pathID, versionName, blockNum, supplierNum, dataORparity = packetid.SplitFull( packetID) if None in [ pathID, versionName, blockNum, supplierNum, dataORparity ]: result.write('F%s %d\n' % (packetID, filesz)) continue if dataORparity != 'Data' and dataORparity != 'Parity': result.write('F%s %d\n' % (packetID, filesz)) continue if maxBlock < blockNum: maxBlock = blockNum if supplierNum not in versionSize: versionSize[supplierNum] = 0 if supplierNum not in dataBlocks: dataBlocks[supplierNum] = {} if supplierNum not in parityBlocks: parityBlocks[supplierNum] = {} if dataORparity == 'Data': dataBlocks[supplierNum][blockNum] = filesz elif dataORparity == 'Parity': parityBlocks[supplierNum][blockNum] = filesz for supplierNum in versionSize.keys(): dataMissing[supplierNum] = set(range(maxBlock + 1)) parityMissing[supplierNum] = set(range(maxBlock + 1)) for blockNum in range(maxBlock + 1): if blockNum in list(dataBlocks[supplierNum].keys()): versionSize[supplierNum] += dataBlocks[supplierNum][ blockNum] dataMissing[supplierNum].discard(blockNum) if blockNum in list(parityBlocks[supplierNum].keys()): versionSize[supplierNum] += parityBlocks[supplierNum][ blockNum] parityMissing[supplierNum].discard(blockNum) suppliers = set(list(dataBlocks.keys()) + list(parityBlocks.keys())) for supplierNum in suppliers: versionString = '%s %d 0-%d %d' % (subpath, supplierNum, maxBlock, versionSize[supplierNum]) if len(dataMissing[supplierNum]) > 0 or len( parityMissing[supplierNum]) > 0: versionString += ' missing' if len(dataMissing[supplierNum]) > 0: versionString += ' Data:' + (','.join( map(str, dataMissing[supplierNum]))) if len(parityMissing[supplierNum]) > 0: versionString += ' Parity:' + (','.join( map(str, parityMissing[supplierNum]))) result.write('V%s\n' % versionString) del dataBlocks del parityBlocks del dataMissing del parityMissing return False