Esempio n. 1
0
def main():
    """The main entrypoint for holland's cmdshell
    """

    if len(sys.argv) < 2:
        print_help()
        sys.exit(1)

    opts, args = parse_sys(sys.argv[1:])

    if args:
        args = args[0].split(',')
    logging.raiseExceptions = bool(opts.log_level == 'debug')
    if 'log_level' in opts:
        opts.log_level = is_logging_level(opts.log_level)

    if opts.command is None:
        print_help()
        sys.exit(1)

    # Bootstrap the environment
    bootstrap(opts)

    LOGGER.info("Holland %s started with pid %d", HOLLAND_VERSION, os.getpid())
    return run(opts, args)
Esempio n. 2
0
def main():
    """The main entrypoint for holland's cmdshell
    """

    if len(sys.argv) < 2:
        print_help()
        sys.exit(1)

    opts, args = parse_sys(sys.argv[1:])

    if args:
        args = args[0].split(",")
    logging.raiseExceptions = bool(opts.log_level == "debug")
    if "log_level" in opts:
        opts.log_level = is_logging_level(opts.log_level)

    if opts.command is None:
        print_help()
        sys.exit(1)

    # Bootstrap the environment
    bootstrap(opts)

    LOG.info("Holland %s started with pid %d", HOLLAND_VERSION, os.getpid())
    return run(opts, args)
Esempio n. 3
0
def main():
    """The main entrypoint for holland's cmdshell
    """

    if len(sys.argv) < 2:
        print_help()
        sys.exit(1)

    opts, args = parse_sys(sys.argv[1:])

    if args:
        args = args[0].split(',')
    logging.raiseExceptions = bool(opts.log_level == 'debug')
    if 'log_level' in opts:
        opts.log_level = is_logging_level(opts.log_level)

    if opts.command is None:
        print_help()
        sys.exit(1)
       
    # set LANG to C for parsing of lvs and vgs
    # patch from https://bugs.launchpad.net/holland-backup/+bug/1256121/comments/1
    os.environ['LANG'] = 'C'
    os.environ['LC_ALL'] = 'C'

    # Bootstrap the environment
    bootstrap(opts)

    LOGGER.info("Holland %s started with pid %d", HOLLAND_VERSION, os.getpid())
    return run(opts, args)
Esempio n. 4
0
def main():
    opts, args = parser.parse_args(sys.argv[1:])

    logging.raiseExceptions = bool(opts.log_level == 'debug')

    if opts.log_level:
        opts.log_level = is_logging_level(opts.log_level)

    if not args:
        args = ['help']

    if opts.help or args[0] == 'help':
        if args[0] == 'help':
            args = args[1:]
        return run(['help'] + args)

    # Bootstrap the environment
    bootstrap(opts)

    LOGGER.info("Holland %s started with pid %d", HOLLAND_VERSION, os.getpid())
    return run(args)
Esempio n. 5
0
def main():
    opts, args = parser.parse_args(sys.argv[1:])

    logging.raiseExceptions = bool(opts.log_level == 'debug')

    if opts.log_level:
        opts.log_level = is_logging_level(opts.log_level)

    if not args:
        args = ['help']

    if opts.help or args[0] == 'help':
        if args[0] == 'help':
            args = args[1:]
        return run(['help'] + args)

    # Bootstrap the environment
    bootstrap(opts)

    LOGGER.info("Holland %s started with pid %d", HOLLAND_VERSION, os.getpid())
    return run(args)
Esempio n. 6
0
def main():
    opts, args = parser.parse_args(sys.argv[1:])

    if opts.log_level:
        opts.log_level = is_logging_level(opts.log_level)

    # Bootstrap the environment
    bootstrap(opts)

    if opts.help:
        args = ['help'] + args

    LOGGER.info("Holland %s started with pid %d", HOLLAND_VERSION, os.getpid())
    return run(args)
Esempio n. 7
0
def main():
    """
    For some reason (take a wild guess) Commvault has decided that
    their long options will take the form of '-option' not the standard
    '--option'.


    Always set HOME to '/root', as the commvault environment is bare
    """
    os.environ["HOME"] = "/root"
    os.environ["TMPDIR"] = "/tmp"
    # ensure we do not inherit commvault's LD_LIBRARY_PATH
    os.environ.pop("LD_LIBRARY_PATH", None)

    holland_conf = "/etc/holland/holland.conf"
    if sys.platform.startswith("freebsd"):
        holland_conf = "/usr/local" + holland_conf

    parser = ArgumentParser()
    parser.add_argument(
        "--config-file", "-c", metavar="<file>", help="Read configuration from the given file"
    )

    parser.add_argument(
        "-l",
        "--log-level",
        metavar="<log-level>",
        choices=["critical", "error", "warning", "info", "debug"],
        help="Specify the log level. " "One of: critical,error,warning,info,debug",
    )
    parser.add_argument("--quiet", "-q", action="store_true", help="Don't log to console")
    parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")

    parser.add_argument(
        "--bksets",
        "-b",
        metavar="<bkset>,<bkset>...",
        help="only run the specified backupset",
        default=[],
        action=ArgList,
    )

    parser.add_argument("-bkplevel", type=int)
    parser.add_argument("-attempt", type=int)
    parser.add_argument("-status", type=int)
    parser.add_argument("-job", type=int)
    parser.add_argument("-vm")
    parser.add_argument("-cn")
    parser.set_defaults(config_file=os.getenv("HOLLAND_CONFIG") or holland_conf, verbose=False)

    args, largs = parser.parse_known_args(sys.argv[1:])
    if args.log_level:
        args.log_level = format_loglevel(args.log_level)

    bootstrap(args)

    logging.info("Holland (commvault agent) %s started with pid %d", HOLLAND_VERSION, os.getpid())
    # Commvault usually runs with a very low default limit for nofile
    # so a best effort is taken to raise that here.
    try:
        resource.setrlimit(resource.RLIMIT_NOFILE, (262144, 262144))
        logging.debug("(Adjusted ulimit -n (RLIMIT_NOFILE) to %d)", 262144)
    except (ValueError, resource.error) as exc:
        logging.debug("Failed to raise RLIMIT_NOFILE: %s", exc)

    args.command = "backup"
    args.dry_run = 0
    args.no_lock = 0
    spool = HOLLANDCFG.lookup("holland.backup-directory")
    if not args.bksets:
        largs = HOLLANDCFG.lookup("holland.backupsets")
    else:
        largs = args.bksets

    status_file = "%s/%s/newest/job_%s" % (spool, largs[0], args.job)
    logging.info("status_file: %s", status_file)
    pid_name = "holland_commvault_%s" % args.job
    pid_location = "/var/run/%s.pid" % pid_name
    try:
        with PidFile(pid_name):
            ret = 0
            if run(args, largs):
                ret = 1
            status = open(status_file, "w")
            status.write(str(ret))
            status.close()
            return ret
    except PidFileAlreadyLockedError:
        ret = 1
        pid_file = open(pid_location, "r")
        pid = pid_file.read()
        pid_file.close()

        logging.info("Holland (commvault agent) is already running, waiting for the pid %s", pid)
        count = 0
        while os.path.isfile(pid_location):
            sleep(10)
            count = count + 1
            # ~14 hour timeout
            if count > 5040:
                logging.info("Holland (commvault agent) timed out after %s seconds", count * 10)
                return 1
        try:
            status = open(status_file, "r")
            ret = int(status.read())
        except IOError:
            logging.info("Holland (commvault agent) failed to open/read status file")
            return 1
        else:
            status.close()
        return ret
    except IOError as ex:
        logging.warning("Holland (commvault agent) IOError: %r", ex)
        return 1
Esempio n. 8
0
def main():
    # For some reason (take a wild guess) Commvault has decided that
    # their long options will take the form of '-option' not the standard
    # '--option'.

    # Always set HOME to '/root', as the commvault environment is bare
    os.environ['HOME'] = '/root'
    os.environ['TMPDIR'] = '/tmp'
    # ensure we do not inherit commvault's LD_LIBRARY_PATH
    os.environ.pop('LD_LIBRARY_PATH', None)

    argv = sys.argv[1:]

    holland_conf = '/etc/holland/holland.conf'
    if sys.platform.startswith('freebsd'):
        holland_conf = '/usr/local' + holland_conf

    parser = ArgumentParser()
    parser.add_argument("--config-file",
                        "-c",
                        metavar="<file>",
                        help="Read configuration from the given file")

    parser.add_argument(
        '-l',
        '--log-level',
        metavar='<log-level>',
        choices=['critical', 'error', 'warning', 'info', 'debug'],
        help="Specify the log level. "
        "One of: critical,error,warning,info,debug")
    parser.add_argument("--quiet",
                        "-q",
                        action="store_true",
                        help="Don't log to console")
    parser.add_argument("--verbose",
                        "-v",
                        action="store_true",
                        help="Verbose output")

    parser.add_argument("--bksets",
                        "-b",
                        metavar="<bkset>,<bkset>...",
                        help="only run the specified backupset",
                        default=[],
                        action=ArgList)

    parser.add_argument("-bkplevel", type=int)
    parser.add_argument("-attempt", type=int)
    parser.add_argument("-status", type=int)
    parser.add_argument("-job", type=int)
    parser.add_argument("-vm")
    parser.add_argument("-cn")
    parser.set_defaults(
        config_file=os.getenv('HOLLAND_CONFIG') or holland_conf,
        verbose=False,
    )

    args, largs = parser.parse_known_args(sys.argv[1:])
    if args.log_level:
        args.log_level = format_loglevel(args.log_level)

    bootstrap(args)

    logging.info("Holland (commvault agent) %s started with pid %d",
                 HOLLAND_VERSION, os.getpid())
    # Commvault usually runs with a very low default limit for nofile
    # so a best effort is taken to raise that here.
    try:
        resource.setrlimit(resource.RLIMIT_NOFILE, (262144, 262144))
        logging.debug("(Adjusted ulimit -n (RLIMIT_NOFILE) to %d)", 262144)
    except (ValueError, resource.error) as exc:
        logging.debug("Failed to raise RLIMIT_NOFILE: %s", exc)

    args.command = 'backup'
    args.dry_run = 0
    args.no_lock = 0
    largs = args.bksets
    if run(args, largs):
        return 1
    else:
        return 0
Esempio n. 9
0
def main():
    """
    For some reason (take a wild guess) Commvault has decided that
    their long options will take the form of '-option' not the standard
    '--option'.


    Always set HOME to '/root', as the commvault environment is bare
    """
    os.environ["HOME"] = "/root"
    os.environ["TMPDIR"] = "/tmp"
    # ensure we do not inherit commvault's LD_LIBRARY_PATH
    os.environ.pop("LD_LIBRARY_PATH", None)

    holland_conf = "/etc/holland/holland.conf"
    if sys.platform.startswith("freebsd"):
        holland_conf = "/usr/local" + holland_conf

    parser = ArgumentParser()
    parser.add_argument("--config-file",
                        "-c",
                        metavar="<file>",
                        help="Read configuration from the given file")

    parser.add_argument(
        "-l",
        "--log-level",
        metavar="<log-level>",
        choices=["critical", "error", "warning", "info", "debug"],
        help="Specify the log level. "
        "One of: critical,error,warning,info,debug",
    )
    parser.add_argument("--quiet",
                        "-q",
                        action="store_true",
                        help="Don't log to console")
    parser.add_argument("--verbose",
                        "-v",
                        action="store_true",
                        help="Verbose output")

    parser.add_argument(
        "--bksets",
        "-b",
        metavar="<bkset>,<bkset>...",
        help="only run the specified backupset",
        default=[],
        action=ArgList,
    )

    parser.add_argument("-bkplevel", type=int)
    parser.add_argument("-attempt", type=int)
    parser.add_argument("-status", type=int)
    parser.add_argument("-job", type=int)
    parser.add_argument("-vm")
    parser.add_argument("-cn")
    parser.set_defaults(config_file=os.getenv("HOLLAND_CONFIG")
                        or holland_conf,
                        verbose=False)

    args, largs = parser.parse_known_args(sys.argv[1:])
    if args.log_level:
        args.log_level = format_loglevel(args.log_level)

    bootstrap(args)

    logging.info("Holland (commvault agent) %s started with pid %d",
                 HOLLAND_VERSION, os.getpid())
    # Commvault usually runs with a very low default limit for nofile
    # so a best effort is taken to raise that here.
    try:
        resource.setrlimit(resource.RLIMIT_NOFILE, (262144, 262144))
        logging.debug("(Adjusted ulimit -n (RLIMIT_NOFILE) to %d)", 262144)
    except (ValueError, resource.error) as exc:
        logging.debug("Failed to raise RLIMIT_NOFILE: %s", exc)

    args.command = "backup"
    args.dry_run = 0
    args.no_lock = 0
    spool = HOLLANDCFG.lookup("holland.backup-directory")
    if not args.bksets:
        largs = HOLLANDCFG.lookup("holland.backupsets")
    else:
        largs = args.bksets

    status_file = "%s/%s/newest/job_%s" % (spool, largs[0], args.job)
    logging.info("status_file: %s", status_file)
    pid_name = "holland_commvault_%s" % args.job
    pid_location = "/var/run/%s.pid" % pid_name
    try:
        with PidFile(pid_name):
            ret = 0
            if run(args, largs):
                ret = 1
            status = open(status_file, "w")
            status.write(str(ret))
            status.close()
            return ret
    except PidFileAlreadyLockedError:
        ret = 1
        pid_file = open(pid_location, "r")
        pid = pid_file.read()
        pid_file.close()

        logging.info(
            "Holland (commvault agent) is already running, waiting for the pid %s",
            pid)
        count = 0
        while os.path.isfile(pid_location):
            sleep(10)
            count = count + 1
            # ~14 hour timeout
            if count > 5040:
                logging.info(
                    "Holland (commvault agent) timed out after %s seconds",
                    count * 10)
                return 1
        try:
            status = open(status_file, "r")
            ret = int(status.read())
        except IOError:
            logging.info(
                "Holland (commvault agent) failed to open/read status file")
            return 1
        else:
            status.close()
        return ret
    except IOError:
        logging.info(
            "Holland (commvault agent) must have permission to write to /var/run"
        )
        return 1
Esempio n. 10
0
    parser.add_argument("-status", type=int)
    parser.add_argument("-job", type=int)
    parser.add_argument("-vm")
    parser.add_argument("-cn")
    parser.set_defaults(
        config_file=os.getenv('HOLLAND_CONFIG') or '/etc/holland/holland.conf',
        verbose=False,
    )

    args, largs = parser.parse_known_args(argv)

    bootstrap(args)

    logging.info("Holland (commvault agent) %s started with pid %d",
                 HOLLAND_VERSION, os.getpid())
    # Commvault usually runs with a very low default limit for nofile
    # so a best effort is taken to raise that here.
    try:
        resource.setrlimit(resource.RLIMIT_NOFILE, (262144, 262144))
        logging.debug("(Adjusted ulimit -n (RLIMIT_NOFILE) to %d)", 262144)
    except (ValueError, resource.error), exc:
        logging.debug("Failed to raise RLIMIT_NOFILE: %s", exc)

    if args.log_level:
        args.log_level = format_loglevel(opts.log_level)

    if run(['backup'] + args.bksets):
        return 1
    else:
        return 0