"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/mysqldbcompare.py" between
mysql-utilities-1.6.4.tar.gz and mysql-utilities-1.6.5.tar.gz

About: MySQL Utilities is a package of utilities that are used for maintenance and administration of MySQL servers (written in Python).

mysqldbcompare.py  (mysql-utilities-1.6.4):mysqldbcompare.py  (mysql-utilities-1.6.5)
skipping to change at line 24 skipping to change at line 24
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# #
""" """
This file contains the operations to perform database consistency checking This file contains the operations to perform database consistency checking
on two databases. on two databases.
""" """
from mysql.utilities.common.tools import check_python_version
# Check Python version compatibility
check_python_version()
import os import os
import re import re
import sys import sys
from mysql.utilities.common.tools import check_python_version
from mysql.utilities.exception import UtilError, FormatError from mysql.utilities.exception import UtilError, FormatError
from mysql.utilities.command.dbcompare import (compare_all_databases, from mysql.utilities.command.dbcompare import (compare_all_databases,
database_compare) database_compare)
from mysql.utilities.common.ip_parser import parse_connection from mysql.utilities.common.ip_parser import parse_connection
from mysql.utilities.common.dbcompare import (DEFAULT_SPAN_KEY_SIZE, from mysql.utilities.common.dbcompare import (DEFAULT_SPAN_KEY_SIZE,
MAX_SPAN_KEY_SIZE) MAX_SPAN_KEY_SIZE)
from mysql.utilities.common.pattern_matching import (REGEXP_OBJ_NAME, from mysql.utilities.common.pattern_matching import (REGEXP_OBJ_NAME,
REGEXP_OBJ_NAME_AQ) REGEXP_OBJ_NAME_AQ)
from mysql.utilities.common.tools import check_connector_python from mysql.utilities.common.tools import check_connector_python
from mysql.utilities.common.messages import (PARSE_ERR_DB_PAIR, from mysql.utilities.common.messages import (PARSE_ERR_DB_PAIR,
skipping to change at line 64 skipping to change at line 60
add_character_set_option, add_character_set_option,
add_ssl_options, get_ssl_dict, add_ssl_options, get_ssl_dict,
setup_common_options, setup_common_options,
check_password_security, check_password_security,
add_exclude, check_exclude_pattern) add_exclude, check_exclude_pattern)
from mysql.utilities.common.server import connect_servers from mysql.utilities.common.server import connect_servers
from mysql.utilities.common.sql_transform import (is_quoted_with_backticks, from mysql.utilities.common.sql_transform import (is_quoted_with_backticks,
remove_backtick_quoting, remove_backtick_quoting,
quote_with_backticks) quote_with_backticks)
# Check Python version compatibility
check_python_version()
# Constants # Constants
NAME = "MySQL Utilities - mysqldbcompare " NAME = "MySQL Utilities - mysqldbcompare "
DESCRIPTION = "mysqldbcompare - compare databases for consistency" DESCRIPTION = "mysqldbcompare - compare databases for consistency"
USAGE = "%prog --server1=user:pass@host:port:socket " + \ USAGE = "%prog --server1=user:pass@host:port:socket " + \
"--server2=user:pass@host:port:socket db1:db2" "--server2=user:pass@host:port:socket db1:db2"
PRINT_WIDTH = 75 PRINT_WIDTH = 75
# Check for connector/python # Check for connector/python
if not check_connector_python(): if not check_connector_python():
sys.exit(1) sys.exit(1)
skipping to change at line 215 skipping to change at line 214
check_verbosity(opt) check_verbosity(opt)
# Fail if the --all option and database arguments are both specified. # Fail if the --all option and database arguments are both specified.
check_all(parser, opt, args, "databases") check_all(parser, opt, args, "databases")
# Process --exclude values to remove unnecessary quotes (when used) in # Process --exclude values to remove unnecessary quotes (when used) in
# order to avoid further matching issues. # order to avoid further matching issues.
exclude_list = None exclude_list = None
if opt.exclude: if opt.exclude:
if not opt.all: if not opt.all:
print(WARN_OPT_ONLY_USED_WITH.format(opt='--exclude', if not opt.quiet:
used_with='the --all option')) print(WARN_OPT_ONLY_USED_WITH.format(opt='--exclude',
used_with='the --all'
' option'))
else: else:
# Remove unnecessary outer quotes. # Remove unnecessary outer quotes.
exclude_list = [pattern.strip("'\"") for pattern in opt.exclude] exclude_list = [pattern.strip("'\"") for pattern in opt.exclude]
# The --regexp option requires --exclude. # The --regexp option requires --exclude.
if opt.use_regexp and not opt.exclude: if opt.use_regexp and not opt.exclude:
print(WARN_OPT_ONLY_USED_WITH.format(opt='--regexp', if not opt.quiet:
used_with='the --exclude option')) print(WARN_OPT_ONLY_USED_WITH.format(opt='--regexp',
used_with='the --exclude'
' option'))
# Check for regexp symbols # Check for regexp symbols
check_exclude_pattern(exclude_list, opt.use_regexp) check_exclude_pattern(exclude_list, opt.use_regexp)
db_idxes_l = None db_idxes_l = None
# Set options for database operations. # Set options for database operations.
options = { options = {
"quiet": opt.quiet, "quiet": opt.quiet,
"verbosity": opt.verbosity, "verbosity": opt.verbosity,
skipping to change at line 307 skipping to change at line 310
server1_sql_mode = servers[0].select_variable("SQL_MODE") server1_sql_mode = servers[0].select_variable("SQL_MODE")
if servers[1] is not None: if servers[1] is not None:
server2_sql_mode = servers[1].select_variable("SQL_MODE") server2_sql_mode = servers[1].select_variable("SQL_MODE")
else: else:
server2_sql_mode = '' server2_sql_mode = ''
except UtilError: except UtilError:
server1_sql_mode = '' server1_sql_mode = ''
server2_sql_mode = '' server2_sql_mode = ''
ukey_regex_server1 = REGEXP_OBJ_NAME ukey_regex_server1 = REGEXP_OBJ_NAME
if "ANSI_QUOTES" in server1_sql_mode: if "ANSI_QUOTES" in server1_sql_mode:
ukey_regex_server1 = REGEXP_OBJ_NAME_AQ ukey_regex_server1 = REGEXP_OBJ_NAME_AQ
ukey_regex_server2 = REGEXP_OBJ_NAME ukey_regex_server2 = REGEXP_OBJ_NAME
if "ANSI_QUOTES" in server2_sql_mode: if "ANSI_QUOTES" in server2_sql_mode:
ukey_regex_server2 = REGEXP_OBJ_NAME_AQ ukey_regex_server2 = REGEXP_OBJ_NAME_AQ
# check unique keys # check unique keys
ukey_regexp = re.compile(r'(?:(?:;){{0,1}}{0}\.{1})' ukey_regexp = re.compile(r'(?:(?:;){{0,1}}{0}\.{1})'
''.format(ukey_regex_server1, ukey_regex_server2)) ''.format(ukey_regex_server1, ukey_regex_server2))
skipping to change at line 346 skipping to change at line 349
if opt.span_key_size is not None: if opt.span_key_size is not None:
if opt.span_key_size < DEFAULT_SPAN_KEY_SIZE: if opt.span_key_size < DEFAULT_SPAN_KEY_SIZE:
parser.error( parser.error(
PARSE_ERR_SPAN_KEY_SIZE_TOO_LOW.format( PARSE_ERR_SPAN_KEY_SIZE_TOO_LOW.format(
s_value=opt.span_key_size, default=DEFAULT_SPAN_KEY_SIZE)) s_value=opt.span_key_size, default=DEFAULT_SPAN_KEY_SIZE))
if opt.span_key_size > MAX_SPAN_KEY_SIZE: if opt.span_key_size > MAX_SPAN_KEY_SIZE:
parser.error( parser.error(
PARSE_ERR_SPAN_KEY_SIZE_TOO_HIGH.format( PARSE_ERR_SPAN_KEY_SIZE_TOO_HIGH.format(
s_value=opt.span_key_size, max=MAX_SPAN_KEY_SIZE)) s_value=opt.span_key_size, max=MAX_SPAN_KEY_SIZE))
if opt.span_key_size % 2 != 0: if opt.span_key_size % 2 != 0:
print("# WARNING: The value for the --span-key-size option must " if not opt.quiet:
"be an even number. The value {0} will be used instead." print("# WARNING: The value for the --span-key-size option"
"".format(opt.span_key_size - 1)) " must be an even number. The value {0} will be used "
"instead.".format(opt.span_key_size - 1))
# Operations to perform: # Operations to perform:
# 1) databases exist # 1) databases exist
# 2) check object counts # 2) check object counts
# 3) check object differences # 3) check object differences
# 4) check row counts among the tables # 4) check row counts among the tables
# 5) check table data consistency # 5) check table data consistency
res = True res = True
check_failed = False check_failed = False
skipping to change at line 413 skipping to change at line 417
db1 = remove_backtick_quoting(parts[0], server1_sql_mode) \ db1 = remove_backtick_quoting(parts[0], server1_sql_mode) \
if is_quoted_with_backticks(parts[0], server1_sql_mode) \ if is_quoted_with_backticks(parts[0], server1_sql_mode) \
else parts[0] else parts[0]
db2 = remove_backtick_quoting(parts[1], server1_sql_mode) \ db2 = remove_backtick_quoting(parts[1], server1_sql_mode) \
if is_quoted_with_backticks(parts[1], server1_sql_mode) \ if is_quoted_with_backticks(parts[1], server1_sql_mode) \
else parts[1] else parts[1]
try: try:
res = database_compare(server1_values, server2_values, res = database_compare(server1_values, server2_values,
db1, db2, options) db1, db2, options)
print if not opt.quiet:
print
except UtilError: except UtilError:
_, e, _ = sys.exc_info() _, e, _ = sys.exc_info()
print("ERROR: %s" % e.errmsg) print("ERROR: %s" % e.errmsg)
sys.exit(1) sys.exit(1)
if not res: if not res:
check_failed = True check_failed = True
if check_failed and not opt.run_all_tests: if check_failed and not opt.run_all_tests:
break break
if not opt.quiet: if not opt.quiet:
print print
if check_failed is None: if check_failed is None:
print("# No databases to compare.") print("# No databases to compare.")
elif check_failed: elif check_failed:
print("# Database consistency check failed.") print("# Database consistency check failed.")
else: else:
sys.stdout.write("# Databases are consistent") sys.stdout.write("# Databases are consistent")
if (opt.no_object_check or opt.no_diff or if (opt.no_object_check or opt.no_diff or
opt.no_row_count or opt.no_data or opt.skip_tbl_opts): opt.no_row_count or opt.no_data or opt.skip_tbl_opts):
sys.stdout.write(" given skip options specified") sys.stdout.write(" given skip options specified")
print(".") print(".")
print("#\n# ...done") print("#\n# ...done")
if check_failed: if check_failed:
sys.exit(1) sys.exit(1)
sys.exit() sys.exit()
 End of changes. 9 change blocks. 
15 lines changed or deleted 20 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS