Ejemplo n.º 1
0
def do_mongo_restore(source,
                     host=None,
                     port=None,
                     dbpath=None,
                     database=None,
                     username=None,
                     password=None,
                     version_info=None,
                     restore_options=None):


    # create restore command with host and port
    restore_cmd = [get_mongo_restore_executable(version_info)]

    if host:
        restore_cmd.extend(["--host", host])
    if port:
        restore_cmd.extend(["--port", str(port)])

    # dbpath
    if dbpath:
        restore_cmd.extend(["--dbpath", dbpath])

    # database
    if database:
        restore_cmd.extend(["-d", database])

    # username and password
    if username:
        restore_cmd.extend(["-u", username, "-p"])
        if password:
            restore_cmd.append(password)

    # ignore authenticationDatabase option is version_info is less than 2.4.0
    if (restore_options and "authenticationDatabase" in restore_options and
            version_info and version_info < make_version_info("2.4.0")):
        restore_options.pop("authenticationDatabase", None)

    # ignore restoreDbUsersAndRoles option is version_info is less than 2.6.0
    if (restore_options and "restoreDbUsersAndRoles" in restore_options and
            version_info and version_info < make_version_info("2.6.0")):
        restore_options.pop("restoreDbUsersAndRoles", None)

    # append shell options
    if restore_options:
        restore_cmd.extend(options_to_command_args(restore_options))

    # pass source arg
    restore_cmd.append(source)

    cmd_display =  restore_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] =  "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] =  "****"

    # execute!
    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(restore_cmd, bubble_exit_code=True)
Ejemplo n.º 2
0
def do_mongo_restore(source,
                     host=None,
                     port=None,
                     dbpath=None,
                     database=None,
                     username=None,
                     password=None,
                     version_info=None,
                     restore_options=None):

    # create restore command with host and port
    restore_cmd = [get_mongo_restore_executable(version_info)]

    if host:
        restore_cmd.extend(["--host", host])
    if port:
        restore_cmd.extend(["--port", str(port)])

    # dbpath
    if dbpath:
        restore_cmd.extend(["--dbpath", dbpath])

    # database
    if database:
        restore_cmd.extend(["-d", database])

    # username and password
    if username:
        restore_cmd.extend(["-u", username, "-p"])
        if password:
            restore_cmd.append(password)

    # ignore authenticationDatabase option is version_info is less than 2.4.0
    if (restore_options and "authenticationDatabase" in restore_options
            and version_info and version_info < make_version_info("2.4.0")):
        restore_options.pop("authenticationDatabase", None)

    # ignore restoreDbUsersAndRoles option is version_info is less than 2.6.0
    if (restore_options and "restoreDbUsersAndRoles" in restore_options
            and version_info and version_info < make_version_info("2.6.0")):
        restore_options.pop("restoreDbUsersAndRoles", None)

    # append shell options
    if restore_options:
        restore_cmd.extend(options_to_command_args(restore_options))

    # pass source arg
    restore_cmd.append(source)

    cmd_display = restore_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] = "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] = "****"

    # execute!
    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(restore_cmd, bubble_exit_code=True)
Ejemplo n.º 3
0
def do_mongo_dump(host=None,
                  port=None,
                  dbpath=None,
                  database=None,
                  username=None,
                  password=None,
                  version_info=None,
                  dump_options=None):


    # create dump command with host and port
    dump_cmd = [get_mongo_dump_executable(version_info)]

    if host:
        dump_cmd.extend(["--host", host])
    if port:
        dump_cmd.extend(["--port", str(port)])

    # dbpath
    if dbpath:
        dump_cmd.extend(["--dbpath", dbpath])

    # database
    if database:
        dump_cmd.extend(["-d", database])

    # username and password
    if username:
        dump_cmd.extend(["-u", username, "-p"])
        if password:
            dump_cmd.append(password)

    # ignore authenticationDatabase option is version_info is less than 2.4.0
    if (dump_options and "authenticationDatabase" in dump_options and
            version_info and version_info < VersionInfo("2.4.0")):
        dump_options.pop("authenticationDatabase", None)

    # ignore dumpDbUsersAndRoles option is version_info is less than 2.6.0
    if (dump_options and "dumpDbUsersAndRoles" in dump_options and
            version_info and version_info < VersionInfo("2.6.0")):
        dump_options.pop("dumpDbUsersAndRoles", None)

    # append shell options
    if dump_options:
        dump_cmd.extend(options_to_command_args(dump_options))


    cmd_display =  dump_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] = "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] =  "****"



    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(dump_cmd, bubble_exit_code=True)
Ejemplo n.º 4
0
def do_mongo_dump(host=None,
                  port=None,
                  dbpath=None,
                  database=None,
                  username=None,
                  password=None,
                  version_info=None,
                  dump_options=None):

    # create dump command with host and port
    dump_cmd = [get_mongo_dump_executable(version_info)]

    if host:
        dump_cmd.extend(["--host", host])
    if port:
        dump_cmd.extend(["--port", str(port)])

    # dbpath
    if dbpath:
        dump_cmd.extend(["--dbpath", dbpath])

    # database
    if database:
        dump_cmd.extend(["-d", database])

    # username and password
    if username:
        dump_cmd.extend(["-u", username, "-p"])
        if password:
            dump_cmd.append(password)

    # ignore authenticationDatabase option is version_info is less than 2.4.0
    if (dump_options and "authenticationDatabase" in dump_options
            and version_info and version_info < MongoDBVersionInfo("2.4.0")):
        dump_options.pop("authenticationDatabase", None)

    # ignore dumpDbUsersAndRoles option is version_info is less than 2.6.0
    if (dump_options and "dumpDbUsersAndRoles" in dump_options and version_info
            and version_info < MongoDBVersionInfo("2.6.0")):
        dump_options.pop("dumpDbUsersAndRoles", None)

    # append shell options
    if dump_options:
        dump_cmd.extend(options_to_command_args(dump_options))

    cmd_display = dump_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] = "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] = "****"

    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(dump_cmd, bubble_exit_code=True)
Ejemplo n.º 5
0
def do_open_mongo_shell_to(address,
                           database=None,
                           username=None,
                           password=None,
                           server_version=None,
                           shell_options=None,
                           js_files=None,
                           ssl=False):

    # default database to admin
    database = database if database else "admin"

    shell_options = shell_options or {}
    js_files = js_files or []

    # override port if specified in --port
    if "port" in shell_options:
        address = "%s:%s" % (address.split(":")[0], shell_options["port"])
        # remove port from options since passing address + port is disallowed in mongo
        del shell_options["port"]
    connect_cmd = [
        get_mongo_shell_executable(server_version),
        "%s/%s" % (address, database)
    ]

    if username:
        connect_cmd.extend(["-u", username, "-p"])
        if password:
            connect_cmd.extend([password])

    # append shell options
    if shell_options:
        connect_cmd.extend(options_to_command_args(shell_options))

    # append js files
    if js_files:
        connect_cmd.extend(js_files)

    # ssl options
    if ssl and "--ssl" not in connect_cmd:
        connect_cmd.append("--ssl")

    cmd_display = connect_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] = "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] = "****"

    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(connect_cmd, bubble_exit_code=True)
Ejemplo n.º 6
0
def do_open_mongo_shell_to(address,
                           database=None,
                           username=None,
                           password=None,
                           server_version=None,
                           shell_options=None,
                           js_files=None,
                           ssl=False):

    # default database to admin
    database = database if database else "admin"

    shell_options = shell_options or {}
    js_files = js_files or []

    # override port if specified in --port
    if "port" in shell_options:
        address = "%s:%s" % (address.split(":")[0], shell_options["port"])
        # remove port from options since passing address + port is disallowed in mongo
        del shell_options["port"]
    connect_cmd = [get_mongo_shell_executable(server_version),
                   "%s/%s" % (address, database)]

    if username:
        connect_cmd.extend(["-u",username, "-p"])
        if password:
            connect_cmd.extend([password])

    # append shell options
    if shell_options:
        connect_cmd.extend(options_to_command_args(shell_options))

    # append js files
    if js_files:
        connect_cmd.extend(js_files)

    # ssl options
    if ssl and "--ssl" not in connect_cmd:
        connect_cmd.append("--ssl")

    cmd_display = connect_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] =  "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] =  "****"

    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(connect_cmd, bubble_exit_code=True)
Ejemplo n.º 7
0
def do_open_mongo_shell_to(address,
                           database=None,
                           username=None,
                           password=None,
                           server_version=None,
                           shell_options={},
                           js_files=[],
                           ssl=False):

    # default database to admin
    database = database if database else "admin"

    connect_cmd = [
        get_mongo_shell_executable(server_version),
        "%s/%s" % (address, database)
    ]

    if username:
        connect_cmd.extend(["-u", username, "-p"])
        if password:
            connect_cmd.extend([password])

    # append shell options
    if shell_options:
        connect_cmd.extend(options_to_command_args(shell_options))

    # append js files
    if js_files:
        connect_cmd.extend(js_files)

    # ssl options
    if ssl:
        connect_cmd.append("--ssl")

    cmd_display = connect_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] = "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] = "****"

    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(connect_cmd, bubble_exit_code=True)
Ejemplo n.º 8
0
def do_open_mongo_shell_to(address,
                           database=None,
                           username=None,
                           password=None,
                           server_version=None,
                           shell_options={},
                           js_files=[],
                           ssl=False):

    # default database to admin
    database = database if database else "admin"


    connect_cmd = [get_mongo_shell_executable(server_version),
                   "%s/%s" % (address, database)]

    if username:
        connect_cmd.extend(["-u",username, "-p"])
        if password:
            connect_cmd.extend([password])

    # append shell options
    if shell_options:
        connect_cmd.extend(options_to_command_args(shell_options))

    # append js files
    if js_files:
        connect_cmd.extend(js_files)

    # ssl options
    if ssl:
        connect_cmd.append("--ssl")

    cmd_display =  connect_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] =  "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] =  "****"

    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(connect_cmd, bubble_exit_code=True)
Ejemplo n.º 9
0
def generate_start_command(server, options_override=None):
    """
        Check if we need to use numactl if we are running on a NUMA box.
        10gen recommends using numactl on NUMA. For more info, see
        http://www.mongodb.org/display/DOCS/NUMA
        """
    command = []

    if mongod_needs_numactl():
        log_info("Running on a NUMA machine...")
        command = apply_numactl(command)

    # append the mongod executable
    command.append(get_server_executable(server))

    # create the command args
    cmd_options = server.export_cmd_options(options_override=options_override)

    command.extend(options_to_command_args(cmd_options))
    return command
Ejemplo n.º 10
0
def generate_start_command(server, options_override=None):
    """
        Check if we need to use numactl if we are running on a NUMA box.
        10gen recommends using numactl on NUMA. For more info, see
        http://www.mongodb.org/display/DOCS/NUMA
        """
    command = []

    if mongod_needs_numactl():
        log_info("Running on a NUMA machine...")
        command = apply_numactl(command)

    # append the mongod executable
    command.append(get_server_executable(server))

    # create the command args
    cmd_options = server.export_cmd_options(options_override=options_override)

    command.extend(options_to_command_args(cmd_options))
    return command
Ejemplo n.º 11
0
def do_mongo_restore(source,
                     host=None,
                     port=None,
                     dbpath=None,
                     database=None,
                     username=None,
                     password=None,
                     version_info=None,
                     parsed_options=None,
                     ssl=False):

    restore_options = extract_mongo_restore_options(parsed_options)
    # create restore command with host and port
    restore_cmd = [get_mongo_restore_executable(version_info)]

    # ssl options
    if ssl:
        restore_cmd.append("--ssl")

    if host:
        restore_cmd.extend(["--host", host])
    if port:
        restore_cmd.extend(["--port", str(port)])

    # dbpath
    if dbpath:
        restore_cmd.extend(["--dbpath", dbpath])

    # database
    if database:
        restore_cmd.extend(["-d", database])

    # username and password
    if username:
        restore_cmd.extend(["-u", username, "-p"])
        if password:
            restore_cmd.append(password)

    # ignore authenticationDatabase option is version_info is less than 2.4.0
    if (restore_options and "authenticationDatabase" in restore_options and
            version_info and version_info < make_version_info("2.4.0")):
        restore_options.pop("authenticationDatabase", None)

    # ignore restoreDbUsersAndRoles option is version_info is less than 2.6.0
    if (restore_options and "restoreDbUsersAndRoles" in restore_options and
            version_info and version_info < make_version_info("2.6.0")):
        restore_options.pop("restoreDbUsersAndRoles", None)

    # for 3.0 default writeConcern to '{w:1}' unless overridden by restore_options
    # default stopOnError to true
    if version_info and version_info >= make_version_info("3.0.0"):
        if not restore_options or "writeConcern" not in restore_options:
            restore_cmd.extend(["--writeConcern", "{w:1}"])

        if not parsed_options.continueOnError and "stopOnError" not in restore_options:
            restore_cmd.append("--stopOnError")

    # append shell options
    if restore_options:
        restore_cmd.extend(options_to_command_args(restore_options))

    # pass source arg
    restore_cmd.append(source)

    cmd_display =  restore_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] =  "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] =  "****"

    # execute!
    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(restore_cmd, bubble_exit_code=True)
Ejemplo n.º 12
0
def do_mongo_restore(source,
                     host=None,
                     port=None,
                     dbpath=None,
                     database=None,
                     username=None,
                     password=None,
                     version_info=None,
                     parsed_options=None,
                     ssl=False):

    restore_options = extract_mongo_restore_options(parsed_options)
    # create restore command with host and port
    restore_cmd = [get_mongo_restore_executable(version_info)]

    # ssl options
    if ssl:
        restore_cmd.append("--ssl")

    if host:
        restore_cmd.extend(["--host", host])
    if port:
        restore_cmd.extend(["--port", str(port)])

    # dbpath
    if dbpath:
        restore_cmd.extend(["--dbpath", dbpath])

    # database
    if database:
        restore_cmd.extend(["-d", database])

    # username and password
    if username:
        restore_cmd.extend(["-u", username, "-p"])
        if password:
            restore_cmd.append(password)

    # ignore authenticationDatabase option is version_info is less than 2.4.0
    if (restore_options and "authenticationDatabase" in restore_options
            and version_info and version_info < make_version_info("2.4.0")):
        restore_options.pop("authenticationDatabase", None)

    # ignore restoreDbUsersAndRoles option is version_info is less than 2.6.0
    if (restore_options and "restoreDbUsersAndRoles" in restore_options
            and version_info and version_info < make_version_info("2.6.0")):
        restore_options.pop("restoreDbUsersAndRoles", None)

    # for 3.0 default writeConcern to '{w:1}' unless overridden by restore_options
    # default stopOnError to true
    if version_info and version_info >= make_version_info("3.0.0"):
        if not restore_options or "writeConcern" not in restore_options:
            restore_cmd.extend(["--writeConcern", "{w:1}"])

        if not parsed_options.continueOnError and "stopOnError" not in restore_options:
            restore_cmd.append("--stopOnError")

    # append shell options
    if restore_options:
        restore_cmd.extend(options_to_command_args(restore_options))

    # pass source arg
    restore_cmd.append(source)

    cmd_display = restore_cmd[:]
    # mask user/password
    if username:
        cmd_display[cmd_display.index("-u") + 1] = "****"
        if password:
            cmd_display[cmd_display.index("-p") + 1] = "****"

    # execute!
    log_info("Executing command: \n%s" % " ".join(cmd_display))
    call_command(restore_cmd, bubble_exit_code=True)