def checksum_tbl(instance, db, tbl): """ Args: instance: the master instance to run against db: the database to checksum tbl: the table within the database to checksum Returns: cmd: the command line(s) executed out: any output written to STDOUT err: any output written to STDERR ret: the return code of the checksum process """ username, password = mysql_lib.get_mysql_user_for_role('ptchecksum') cmd = (' '.join(('/usr/bin/pt-table-checksum', CHECKSUM_DEFAULTS, '--tables={db}.{tbl}', '--user={username}', '--password={password}', '--host={host}', '--port={port}')).format(tbl=tbl, db=db, username=username, password=password, host=instance.hostname, port=instance.port)) out, err, ret = host_utils.shell_exec(cmd) return cmd.replace(password, 'REDACTED'), out, err, ret
def disk_space_available_for_migration(instance): """ Check the disk space available for migrations on the data dir mount Args: instance - A hostaddr object Returns: The number of MB available """ datadir = mysql_lib.get_global_variables(instance)['datadir'] cmd = MIGRATION_SPACE_CMD.format(hostname=instance.hostname, datadir=datadir, disk_limit=DISK_LIMIT) log.info(cmd) out, err, ret = host_utils.shell_exec(cmd) return float(out.strip())
def init_privileges_tables(port): """ Bootstap a MySQL instance Args: port - the port on which to act upon on localhost """ datadir = host_utils.get_cnf_setting('datadir', port) cmd = ('{MYSQL_INSTALL_DB} --datadir={datadir}' ' --user=mysql'.format(MYSQL_INSTALL_DB=MYSQL_INSTALL_DB, datadir=datadir)) log.info(cmd) (std_out, std_err, return_code) = host_utils.shell_exec(cmd) if return_code: raise Exception("Return {return_code} != 0 \n" "std_err:{std_err}\n" "std_out:{std_out}".format(return_code=return_code, std_err=std_err, std_out=std_out))
def checksum_tbl_via_sync(instance, db, tbl): username, password = mysql_lib.get_mysql_user_for_role('ptchecksum') cmd = (' '.join( ('/usr/bin/pt-table-sync', CHECKSUM_SYNC_DEFAULTS, '--tables={db}.{tbl}', '--user={username}', '--password={password}', 'h={host},P={port}')).format(db=db, tbl=tbl, username=username, password=password, host=instance.hostname, port=instance.port)) out, err, ret = host_utils.shell_exec(cmd) diff_count = 0 for line in out.split("\n"): diff_count += parse_sync_row(line) # strip out the password in case we are storing it in the DB. return cmd.replace(password, 'REDACTED'), out, err, ret, diff_count
def checksum_tbl_via_sync(instance, db, tbl): username, password = mysql_lib.get_mysql_user_for_role('ptchecksum') cmd = (' '.join(('/usr/bin/pt-table-sync', CHECKSUM_SYNC_DEFAULTS, '--tables={db}.{tbl}', '--user={username}', '--password={password}', 'h={host},P={port}')).format(db=db, tbl=tbl, username=username, password=password, host=instance.hostname, port=instance.port)) out, err, ret = host_utils.shell_exec(cmd) diff_count = 0 for line in out.split("\n"): diff_count += parse_sync_row(line) # strip out the password in case we are storing it in the DB. return cmd.replace(password, 'REDACTED'), out, err, ret, diff_count