#!/usr/bin/python import py import vsync optparse = py.compat.optparse parser = optparse.OptionParser() parser.add_option("-t", "--testconnections", action="store_true", dest="testconnections", help="dont run backups, just test connectivity/configuration") parser.add_option("-a", "--allhosts", action="store_true", dest="allhosts", help="run backups for all configured hosts") def run_backup(cls): try: dt = py.std.datetime.datetime.now() vsync.syncbyconf(cls, dt) dt = py.std.datetime.datetime.now() vsync.cleanupbyconf(cls, dt) except KeyboardInterrupt: raise except: print "!"*26, "INTERNAL FAILURE" py.std.traceback.print_exc() print "continuing" def run_test(item, _cache={}): userhost = item.source.split(':')[0] identity = "/etc/vsync/backup" key = (userhost, identity) if key in _cache: return _cache[key] = None print >>py.std.sys.stderr, "connecting to", userhost, "with identity", identity, gw = py.execnet.SshGateway(userhost, identity=identity) ch = gw.remote_exec("import os ; channel.send(os.getpid())") ch.receive() gw.exit() print >>py.std.sys.stderr, "ok" def main(): (options, args) = parser.parse_args() conf = py.path.local('/etc/vsync/vsync.conf.py')._getpymodule() #py.std.pprint.pprint(conf.backupitems) if options.allhosts: args.extend([x.host for x in conf.backupitems]) if options.testconnections: from vsync.__.connectiontest import testconnect testconnect(conf, args) py.std.sys.exit(0) for hostname in args: found = False for item in conf.backupitems: if item.host == hostname: run_backup(item) found = True if not found: print >>py.std.sys.stderr, "no backup class for host %r" %(hostname,) raise SystemExit, 1