def main(): global args, logger, exceptionLogger tardis = None try: args = processArgs() logger = Util.setupLogging(args.verbose) exceptionLogger = Util.ExceptionLogger(logger, args.exceptions) setColors(Defaults.getDefault('TARDIS_LS_COLORS')) # Load any password info password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client)) args.password = None (tardis, _, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir) setupDisplay(tardis) if args.headers: doprint("Client: %s DB: %s" %(args.client, args.database), color=colors['name'], eol=True) if args.glob: directories = [] for d in args.directories: if not Util.isMagic(d): directories.append(d) else: directories += globPath(os.path.abspath(d), tardis, crypt) else: directories = args.directories for d in directories: d = unicode(os.path.abspath(d).decode(fsEncoding)) if args.realpath: d = os.path.realpath(d) fInfos = collectFileInfo(d, tardis, crypt) recurse = args.maxdepth if args.recurse else 0 processFile(d, fInfos, tardis, crypt, printContents=(not args.dirinfo), recurse=recurse) except KeyboardInterrupt: pass except TardisDB.AuthenticationException as e: logger.error("Authentication failed. Bad password") exceptionLogger.log(e) except Exception as e: logger.error("Caught exception: %s", str(e)) exceptionLogger.log(e) finally: if tardis: tardis.close()
def main(): global logger, exceptionLogger tardis = None try: parseArgs() logger = Util.setupLogging(args.verbose) exceptionLogger = Util.ExceptionLogger(logger, args.exceptions) if len(args.backup) > 2: logger.error(args.backup) logger.error("Too many backups (%d) specified. Only one or two allowed", len(args.backup)) sys.exit(1) password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client)) args.password = None (tardis, cache, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir) password = None bsets = [] for i in args.backup: bset = getBackupSet(tardis, i) if bset: logger.debug("Got backupset %s", str(bset)) logger.debug("backupset: %s", bset['backupset']) bsets.append(bset) else: sys.exit(1) if len(bsets) == 1: bsets.append(None) r = Regenerator.Regenerator(cache, tardis, crypt) then = time.asctime(time.localtime(float(bsets[0]['starttime']))) + ' (' + bsets[0]['name'] + ')' if bsets[1]: now = time.asctime(time.localtime(float(bsets[1]['starttime']))) + ' (' + bsets[1]['name'] + ')' else: now = time.asctime() + ' (filesystem)' for f in args.files: f = unicode(f.decode(sys.getfilesystemencoding())) if bsets[1] is None and os.path.isdir(f): diffDir(os.path.abspath(f), r, bsets, tardis, crypt, args.reduce, now, then, recurse=args.recurse) else: (i0, _) = getFileInfo(os.path.abspath(f), bsets[0]['backupset'], tardis, crypt, args.reduce) if i0 and i0['dir']: (i1, _) = getFileInfo(os.path.abspath(f), bsets[1]['backupset'], tardis, crypt, args.reduce) if i1 and i1['dir']: diffDir(os.path.abspath(f), r, bsets, tardis, crypt, args.reduce, now, then, recurse=args.recurse) continue diffFile(f, r, bsets, tardis, crypt, args.reduce, args.recurse, now, then) except KeyboardInterrupt: pass except TardisDB.AuthenticationException as e: logger.error("Authentication failed. Bad password") exceptionLogger.log(e) sys.exit(1) except Exception as e: logger.error("Caught exception: %s", str(e)) exceptionLogger.log(e) finally: if tardis: tardis.close()
def main(): global logger, exceptionLogger, args parseArgs() logger = Util.setupLogging(args.verbose) exceptionLogger = Util.ExceptionLogger(logger, args.exceptions) # Commands which cannot be executed on remote databases allowRemote = args.command not in ['create', 'upgrade'] db = None crypt = None cache = None try: confirm = args.command in ['setpass', 'create'] allowNone = args.command not in ['setpass', 'chpass'] try: password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client), allowNone=allowNone, confirm=confirm) except Exception as e: logger.critical(str(e)) exceptionLogger.log(e) return -1 if password: crypt = TardisCrypto.TardisCrypto(password, args.client) args.password = None if args.command == 'create': return createClient(crypt, password) if args.command == 'setpass': if not Util.checkPasswordStrength(password): return -1 if not crypt: logger.error("No password specified") return -1 return setPassword(crypt, password) if args.command == 'chpass': return changePassword(crypt, password) upgrade = (args.command == 'upgrade') try: (db, cache) = getDB(crypt, password, allowRemote=allowRemote, allowUpgrade=upgrade) if crypt and args.command != 'keys': if args.keys: (f, c) = Util.loadKeys(args.keys, db.getConfigValue('ClientID')) else: (f, c) = db.getKeys() crypt.setKeys(f, c) except TardisDB.AuthenticationException as e: logger.error("Authentication failed. Bad password") exceptionLogger.log(e) sys.exit(1) except Exception as e: logger.critical("Unable to connect to database: %s", e) exceptionLogger.log(e) sys.exit(1) if args.command == 'keys': return moveKeys(db, crypt) elif args.command == 'list': return listBSets(db, crypt, cache) elif args.command == 'files': return listFiles(db, crypt) elif args.command == 'info': return bsetInfo(db) elif args.command == 'purge': return purge(db, cache) elif args.command == 'delete': return deleteBsets(db, cache) elif args.command == 'priority': return setPriority(db) elif args.command == 'rename': return renameSet(db) elif args.command == 'getconfig': return getConfig(db) elif args.command == 'setconfig': return setConfig(db) elif args.command == 'orphans': return removeOrphans(db, cache) elif args.command == 'upgrade': return except KeyboardInterrupt: pass except TardisDB.AuthenticationException as e: logger.error("Authentication failed. Bad password") sys.exit(1) except Exception as e: logger.error("Caught exception: %s", str(e)) exceptionLogger.log(e) finally: if db: db.close()