def _bsetInfo(db, info): print "Backupset : %s (%d)" % ((info['name']), info['backupset']) print "Completed : %s" % ('True' if info['completed'] else 'False') t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(info['starttime']))) print "StartTime : %s" % (t) if info['endtime'] is not None: t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(info['endtime']))) duration = str(datetime.timedelta(seconds = (int(float(info['endtime']) - float(info['starttime']))))) print "EndTime : %s" % (t) print "Duration : %s" % (duration) print "SW Versions : C:%s S:%s" % (info['clientversion'], info['serverversion']) print "Client IP : %s" % (info['clientip']) details = db.getBackupSetDetails(info['backupset']) (files, dirs, size, newInfo, endInfo) = details print "Files : %d" % (files) print "Directories : %d" % (dirs) print "Total Size : %s" % (Util.fmtSize(size)) print "New Files : %d" % (newInfo[0]) print "New File Size : %s" % (Util.fmtSize(newInfo[1])) print "New File Space : %s" % (Util.fmtSize(newInfo[2])) print "Purgeable Files : %d" % (endInfo[0]) print "Purgeable Size : %s" % (Util.fmtSize(endInfo[1])) print "Purgeable Space : %s" % (Util.fmtSize(endInfo[2]))
def _bsetInfo(db, info): print("Backupset : %s (%d)" % ((info['name']), info['backupset'])) print("Completed : %s" % ('True' if info['completed'] else 'False')) t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(info['starttime']))) print("StartTime : %s" % (t)) if info['endtime'] is not None: t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(info['endtime']))) duration = str(datetime.timedelta(seconds = (int(float(info['endtime']) - float(info['starttime']))))) print("EndTime : %s" % (t)) print("Duration : %s" % (duration)) print("SW Versions : C:%s S:%s" % (info['clientversion'], info['serverversion'])) print("Client IP : %s" % (info['clientip'])) details = db.getBackupSetDetails(info['backupset']) (files, dirs, size, newInfo, endInfo) = details print("Files : %d" % (files)) print("Directories : %d" % (dirs)) print("Total Size : %s" % (Util.fmtSize(size))) print("New Files : %d" % (newInfo[0])) print("New File Size : %s" % (Util.fmtSize(newInfo[1]))) print("New File Space : %s" % (Util.fmtSize(newInfo[2]))) print("Purgeable Files : %d" % (endInfo[0])) print("Purgeable Size : %s" % (Util.fmtSize(endInfo[1]))) print("Purgeable Space : %s" % (Util.fmtSize(endInfo[2])))
def _bsetInfo(db, info): print "Backupset : %s (%d)" % ((info["name"]), info["backupset"]) print "Completed : %s" % ("True" if info["completed"] else "False") t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(info["starttime"]))) print "StartTime : %s" % (t) if info["endtime"] is not None: t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(info["endtime"]))) duration = str(datetime.timedelta(seconds=(int(float(info["endtime"]) - float(info["starttime"]))))) print "EndTime : %s" % (t) print "Duration : %s" % (duration) print "SW Versions : C:%s S:%s" % (info["clientversion"], info["serverversion"]) print "Client IP : %s" % (info["clientip"]) details = db.getBackupSetDetails(info["backupset"]) (files, dirs, size, newInfo, endInfo) = details print "Files : %d" % (files) print "Directories : %d" % (dirs) print "Total Size : %s" % (Util.fmtSize(size)) print "New Files : %d" % (newInfo[0]) print "New File Size : %s" % (Util.fmtSize(newInfo[1])) print "New File Space : %s" % (Util.fmtSize(newInfo[2])) print "Purgeable Files : %d" % (endInfo[0]) print "Purgeable Size : %s" % (Util.fmtSize(endInfo[1])) print "Purgeable Space : %s" % (Util.fmtSize(endInfo[2]))
def listBSets(db, crypt, cache): global _regenerator try: if args.longinfo: _regenerator = Regenerator.Regenerator(cache, db, crypt) last = db.lastBackupSet() print "%-30s %-4s %-6s %3s %-5s %-24s %-7s %6s %5s %8s %s" % ("Name", "Id", "Comp", "Pri", "Full", "Start", "Runtime", "Files", "Delta", "Size", "") for bset in db.listBackupSets(): t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(bset['starttime']))) if bset['endtime'] is not None: duration = str(datetime.timedelta(seconds = (int(float(bset['endtime']) - float(bset['starttime']))))) else: duration = '' completed = 'Comp' if bset['completed'] else 'Incomp' full = 'Full' if bset['full'] else 'Delta' isCurrent = current if bset['backupset'] == last['backupset'] else '' size = Util.fmtSize(bset['bytesreceived'], formats=['', 'KB', 'MB', 'GB', 'TB']) print "%-30s %-4d %-6s %3d %-5s %-24s %-7s %6s %5s %8s %s" % (bset['name'], bset['backupset'], completed, bset['priority'], full, t, duration, bset['filesfull'], bset['filesdelta'], size, isCurrent) if args.longinfo: commandLine = getCommandLine(db, bset['commandline']) if commandLine: print " Command Line: %s" % (commandLine) print except TardisDB.AuthenticationException as e: logger.error("Authentication failed. Bad password") return 1 except Exception as e: logger.error(e) exceptionLogger.log(e) return 1
def listBSets(db): try: last = db.lastBackupSet() for i in db.listBackupSets(): t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(i["starttime"]))) if i["endtime"] is not None: duration = str(datetime.timedelta(seconds=(int(float(i["endtime"]) - float(i["starttime"]))))) else: duration = "" completed = "Comp" if i["completed"] else "Incomp" full = "Full" if i["full"] else "Delta" isCurrent = current if i["backupset"] == last["backupset"] else "" size = Util.fmtSize(i["bytesreceived"], formats=["", "KB", "MB", "GB", "TB"]) print "%-30s %-4d %-6s %3d %-5s %s %-7s %6s %5s %8s %s" % ( i["name"], i["backupset"], completed, i["priority"], full, t, duration, i["filesfull"], i["filesdelta"], size, isCurrent, ) except Exception as e: logger.error(e) logger.exception(e) return 1
def listBSets(db): try: last = db.lastBackupSet() for bset in db.listBackupSets(): t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(bset['starttime']))) if bset['endtime'] is not None: duration = str( datetime.timedelta(seconds=( int(float(bset['endtime']) - float(bset['starttime']))))) else: duration = '' completed = 'Comp' if bset['completed'] else 'Incomp' full = 'Full' if bset['full'] else 'Delta' isCurrent = current if bset['backupset'] == last[ 'backupset'] else '' size = Util.fmtSize(bset['bytesreceived'], formats=['', 'KB', 'MB', 'GB', 'TB']) print "%-30s %-4d %-6s %3d %-5s %s %-7s %6s %5s %8s %s" % ( bset['name'], bset['backupset'], completed, bset['priority'], full, t, duration, bset['filesfull'], bset['filesdelta'], size, isCurrent) except Exception as e: logger.error(e) logger.exception(e) return 1
def listFiles(db, crypt): #print args info = getBackupSet(db, args.backup, args.date, defaultCurrent=True) #print info, info['backupset'] lastDir = '/' lastDirInode = (-1, -1) bset = info['backupset'] files = db.getNewFiles(info['backupset'], args.previous) for fInfo in files: name = _decryptFilename(fInfo['name'], crypt) if not args.dirs and fInfo['dir']: continue dirInode = (fInfo['parent'], fInfo['parentdev']) if dirInode == lastDirInode: path = lastDir else: path = _path(db, crypt, bset, dirInode) lastDirInode = dirInode lastDir = path if not args.fullname: print "%s:" % (path) if args.status: status = '[New] ' if fInfo['chainlength'] == 0 else '[Delta] ' else: status = '' if args.fullname: name = os.path.join(path, name) if args.long: mode = Util.filemode(fInfo['mode']) group = Util.getGroupName(fInfo['gid']) owner = Util.getUserId(fInfo['uid']) mtime = Util.formatTime(fInfo['mtime']) if fInfo['size'] is not None: if args.human: size = "%8s" % Util.fmtSize(fInfo['size'], formats=['','KB','MB','GB', 'TB', 'PB']) else: size = "%8d" % int(fInfo['size']) else: size = '' print' %s%9s %-8s %-8s %8s %12s' % (status, mode, owner, group, size, mtime), if args.cksums: print ' %32s ' % (fInfo['checksum'] or ''), if args.chnlen: print ' %4s ' % (fInfo['chainlength']), if args.inode: print ' %-16s ' % ("(%s, %s)" % (fInfo['device'], fInfo['inode'])), print name else: print " %s" % status, if args.cksums: print ' %32s ' % (fInfo['checksum'] or ''), if args.chnlen: print ' %4s ' % (fInfo['chainlength']), if args.inode: print ' %-16s ' % ("(%s, %s)" % (fInfo['device'], fInfo['inode'])), print name
def listFiles(db, crypt): #print args info = getBackupSet(db, args.backup, args.date, defaultCurrent=True) #print info, info['backupset'] lastDir = '/' lastDirInode = (-1, -1) bset = info['backupset'] files = db.getNewFiles(info['backupset'], args.previous) for fInfo in files: name = _decryptFilename(fInfo['name'], crypt) if not args.dirs and fInfo['dir']: continue dirInode = (fInfo['parent'], fInfo['parentdev']) if dirInode == lastDirInode: path = lastDir else: path = _path(db, crypt, bset, dirInode) lastDirInode = dirInode lastDir = path if not args.fullname: print("%s:" % (path)) if args.status: status = '[New] ' if fInfo['chainlength'] == 0 else '[Delta] ' else: status = '' if args.fullname: name = os.path.join(path, name) if args.long: mode = Util.filemode(fInfo['mode']) group = Util.getGroupName(fInfo['gid']) owner = Util.getUserId(fInfo['uid']) mtime = Util.formatTime(fInfo['mtime']) if fInfo['size'] is not None: if args.human: size = "%8s" % Util.fmtSize(fInfo['size'], formats=['','KB','MB','GB', 'TB', 'PB']) else: size = "%8d" % int(fInfo['size']) else: size = '' print(' %s%9s %-8s %-8s %8s %12s' % (status, mode, owner, group, size, mtime), end=' ') if args.cksums: print(' %32s ' % (fInfo['checksum'] or ''), end=' ') if args.chnlen: print(' %4s ' % (fInfo['chainlength']), end=' ') if args.inode: print(' %-16s ' % ("(%s, %s)" % (fInfo['device'], fInfo['inode'])), end=' ') print(name) else: print(" %s" % status, end=' ') if args.cksums: print(' %32s ' % (fInfo['checksum'] or ''), end=' ') if args.chnlen: print(' %4s ' % (fInfo['chainlength']), end=' ') if args.inode: print(' %-16s ' % ("(%s, %s)" % (fInfo['device'], fInfo['inode'])), end=' ') print(name)
def removeOrphans(db, cache): if hasattr(cache, 'removeOrphans'): r = cache.removeOrphans() logger.debug("Remove Orphans: %s %s", type(r), r) count = r['count'] size = r['size'] rounds = r['rounds'] else: count, size, rounds = Util.removeOrphans(db, cache) print "Removed %d orphans, for %s, in %d rounds" % (count, Util.fmtSize(size), rounds)
def removeOrphans(db, cache): if hasattr(cache, "removeOrphans"): r = cache.removeOrphans() logger.debug("Remove Orphans: %s %s", type(r), r) count = r["count"] size = r["size"] rounds = r["rounds"] else: count, size, rounds = Util.removeOrphans(db, cache) print "Removed %d orphans, for %s, in %d rounds" % (count, Util.fmtSize(size), rounds)
def removeOrphans(db, cache): if hasattr(cache, 'removeOrphans'): r = cache.removeOrphans() logger.debug("Remove Orphans: %s %s", type(r), r) count = r['count'] size = r['size'] rounds = r['rounds'] else: count, size, rounds = Util.removeOrphans(db, cache) print "Removed %d orphans, for %s, in %d rounds" % (count, Util.fmtSize(size), rounds)
def listBSets(db): try: last = db.lastBackupSet() for i in db.listBackupSets(): t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(i['starttime']))) if i['endtime'] is not None: duration = str(datetime.timedelta(seconds = (int(float(i['endtime']) - float(i['starttime']))))) else: duration = '' completed = 'Comp' if i['completed'] else 'Incomp' full = 'Full' if i['full'] else 'Delta' isCurrent = current if i['backupset'] == last['backupset'] else '' size = Util.fmtSize(i['bytesreceived'], formats=['', 'KB', 'MB', 'GB', 'TB']) print "%-30s %-4d %-6s %3d %-5s %s %-7s %6s %5s %8s %s" % (i['name'], i['backupset'], completed, i['priority'], full, t, duration, i['filesfull'], i['filesdelta'], size, isCurrent) except Exception as e: logger.error(e) logger.exception(e) return 1
def listBSets(db, crypt, cache): global _regenerator try: if args.longinfo: _regenerator = Regenerator.Regenerator(cache, db, crypt) last = db.lastBackupSet() print("%-30s %-4s %-6s %3s %-5s %-24s %-7s %6s %5s %8s %s" % ("Name", "Id", "Comp", "Pri", "Full", "Start", "Runtime", "Files", "Delta", "Size", "")) sets = list(db.listBackupSets()) if args.minpriority: sets = list(filter(lambda x: x['priority'] >= args.minpriority, sets)) sets = sets[-(args.number):] for bset in sets: t = time.strftime("%d %b, %Y %I:%M:%S %p", time.localtime(float(bset['starttime']))) if bset['endtime'] is not None: duration = str(datetime.timedelta(seconds = (int(float(bset['endtime']) - float(bset['starttime']))))) else: duration = '' completed = 'Comp' if bset['completed'] else 'Incomp' full = 'Full' if bset['full'] else 'Delta' isCurrent = current if bset['backupset'] == last['backupset'] else '' size = Util.fmtSize(bset['bytesreceived'], formats=['', 'KB', 'MB', 'GB', 'TB']) print("%-30s %-4d %-6s %3d %-5s %-24s %-7s %6s %5s %8s %s" % (bset['name'], bset['backupset'], completed, bset['priority'], full, t, duration, bset['filesfull'], bset['filesdelta'], size, isCurrent)) if args.longinfo: commandLine = getCommandLine(db, bset['commandline']) if commandLine: print(" Command Line: %s" % (commandLine.decode('utf-8'))) print() except TardisDB.AuthenticationException as e: logger.error("Authentication failed. Bad password") return 1 except Exception as e: logger.error(e) if args.exceptions: logger.exception(e) return 1
def printit(info, name, color, gone): global column annotation = '' if args.annotate and info is not None: if info['dir']: annotation = '/' elif info['link']: annotation = '@' elif info['mode'] & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH): annotation = '*' name = name + annotation if gone: name = '(' + name + ')' if column == 0: doprint(' ') if args.cksums: if info and info['checksum']: cksum = info['checksum'] else: cksum = '' if args.chnlen: if info and info['chainlength'] is not None: chnlen = "%-3d" % int(info['chainlength']) else: chnlen = '' if args.inode: if info and info['inode'] is not None: inode = "%8d" % int(info['inode']) else: inode = '' if args.size: if info and info['size'] is not None: if args.human: fsize = "%8s" % Util.fmtSize(info['size'], formats=['','KB','MB','GB', 'TB', 'PB']) else: fsize = "%8d" % int(info['size']) else: fsize = '' if args.long: if gone: doprint(' %s' % (name), color, eol=True) else: mode = Util.filemode(info['mode']) group = Util.getGroupName(info['gid']) owner = Util.getUserId(info['uid']) mtime = Util.formatTime(info['mtime']) nlinks = info['nlinks'] if info['size'] is not None: if args.human: size = Util.fmtSize(info['size'], formats=['','KB','MB','GB', 'TB', 'PB']) else: size = "%8d" % info['size'] else: size = '' doprint(' %9s %3d %-8s %-8s %8s %12s ' % (mode, nlinks, owner, group, size, mtime), color=colors['name']) if args.size: doprint(' %8s ' % (fsize)) if args.inode: doprint(' %8s ' % (inode)) if args.cksums: doprint(' %32s ' % (cksum)) if args.chnlen: doprint(' %-3s ' % (chnlen)) doprint('%s' % (name), color, eol=True) elif args.cksums or args.chnlen or args.inode or args.size: doprint(columnfmt % name, color) if args.size: doprint(' ' + fsize, color=colors['name']) if args.inode: doprint(' ' + inode, color=colors['name']) if args.cksums: doprint(' ' + cksum, color=colors['name']) if args.chnlen: doprint(' ' + chnlen, color=colors['name']) doprint(' ', eol=True) else: column += 1 if column == columns: eol = True column = 0 else: eol = False doprint(columnfmt % name, color, eol=eol)
def printit(info, name, color, gone): global column annotation = '' if args.annotate and info is not None: if info['dir']: annotation = '/' elif info['link']: annotation = '@' elif info['mode'] & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH): annotation = '*' name = name + annotation if gone: name = '(' + name + ')' if column == 0: doprint(' ') if args.cksums: if info and info['checksum']: cksum = info['checksum'] else: cksum = '' if args.chnlen: if info and info['chainlength'] is not None: chnlen = "%-3d" % int(info['chainlength']) else: chnlen = '' if args.inode: if info and info['inode'] is not None: inode = "%8d" % int(info['inode']) else: inode = '' if args.size: if info and info['size'] is not None: if args.human: fsize = "%8s" % Util.fmtSize(info['size'], formats=['','KB','MB','GB', 'TB', 'PB']) else: fsize = "%8d" % int(info['size']) else: fsize = '' if args.long: if gone: doprint(' %s' % (name), color, eol=True) else: mode = Util.filemode(info['mode']) group = Util.getGroupName(info['gid']) owner = Util.getUserId(info['uid']) mtime = Util.formatTime(info['mtime']) nlinks = info['nlinks'] if info['size'] is not None: if args.human: size = Util.fmtSize(info['size'], formats=['','KB','MB','GB', 'TB', 'PB']) else: size = "%8d" % info['size'] else: size = '' doprint(' %9s %3d %-8s %-8s %8s %12s ' % (mode, nlinks, owner, group, size, mtime), color=colors['name']) if args.size: doprint(' %8s ' % (fsize)) if args.inode: doprint(' %8s ' % (inode)) if args.cksums: doprint(' %32s ' % (cksum)) if args.chnlen: doprint(' %-3s ' % (chnlen)) doprint('%s' % (name), color, eol=True) elif args.cksums or args.chnlen or args.inode or args.size: doprint(columnfmt % name, color) if args.size: doprint(' ' + fsize, color=colors['name']) if args.inode: doprint(' ' + inode, color=colors['name']) if args.cksums: doprint(' ' + cksum, color=colors['name']) if args.chnlen: doprint(' ' + chnlen, color=colors['name']) doprint('', eol=True) else: column += 1 if column == columns: eol = True column = 0 else: eol = False doprint(columnfmt % name, color, eol=eol)
def processFile(cksInfo, regenerator, cacheDir, db, crypto, basis=None): try: conn = db.conn c2 = conn.cursor() checksum = cksInfo['checksum'] if cksInfo['encrypted']: logger.info(" Skipping %s", checksum) return None logger.info(" Processing %s (%s, %s)", checksum, Util.fmtSize(cksInfo['size'], formats=suffixes), Util.fmtSize(cksInfo['diskSize'], formats=suffixes)) signature = not cacheDir.exists(checksum + ".sig") nameHmac = crypto.getHash() retFile = generateFullFileInfo(checksum, regenerator, cacheDir, nameHmac, signature, basis) if basis: basis.close() newCks = nameHmac.hexdigest() logger.info(" Hashed %s => %s (%s, %s)", checksum, newCks, Util.fmtSize(cksInfo['size'], formats=suffixes), Util.fmtSize(cksInfo['diskSize'], formats=suffixes)) iv = crypto.getIV() cipher = crypto.getContentCipher(iv) hmac = crypto.getHash(func=hashlib.sha512) fSize = encryptFile(checksum, cacheDir, cipher, iv, crypto.pad, hmac, nameHmac, output=newCks) logger.info( " Encrypted %s => %s (%s)", checksum, newCks, Util.fmtSize(fSize, formats=['', 'KB', 'MB', 'GB', 'TB', 'PB'])) #cacheDir.link(checksum + '.enc', newCks, soft=False) #cacheDir.link(checksum + ".sig", newCks + ".sig", soft=False) cacheDir.move(checksum + ".sig", newCks + ".sig") logger.debug(" Moved sig file, updating database") c2.execute( 'UPDATE CheckSums SET Encrypted = 1, DiskSize = :size, Checksum = :newcks WHERE Checksum = :cks', { "size": fSize, "newcks": newCks, "cks": checksum }) c2.execute('UPDATE CheckSums SET Basis = :newcks WHERE Basis = :cks', { "newcks": newCks, "cks": checksum }) logger.debug(" Ready to commit") conn.commit() logger.debug(" Commit complete, removing files") cacheDir.removeSuffixes(checksum, ['.meta', '.enc', '.sig', '.basis', '']) logger.debug(" Done with %s", checksum) return retFile except Exception as e: conn.rollback() logger.error("Unable to convert checksum: %s :: %s", checksum, e) logger.exception(e) return None