1# ==== Purpose ====
2#
3# Check that two or more servers have identical databases; fail if not.
4#
5# ==== Usage ====
6#
7# --let $diff_servers= 1 2
8# [--let $databases= db1 db2 ...]
9# [--let $rpl_debug= 1]
10# --source include/diff_servers.inc
11
12# pretty-print header
13--let $_ds_info= servers=$diff_servers
14if ($databases != '')
15{
16  --let $_ds_info= $_ds_info databases=$databases
17}
18--let $include_filename= diff_servers.inc [$_ds_info]
19--source include/begin_include_file.inc
20
21# get databases
22--let $_ds_databases= $diff_database
23if ($_ds_databases == '')
24{
25  --let $_ds_databases= `SELECT GROUP_CONCAT(SCHEMA_NAME SEPARATOR ' ') FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('information_schema', 'mtr', 'mysql', 'performance_schema')`
26}
27
28# generate command line
29--let $_ds_arg= --defaults-group-suffix=.
30--let $_ds_number_pos= `SELECT LOCATE('$_ds_arg', '$MYSQL_DUMP') + LENGTH('$_ds_arg')`
31--let $_ds_pre_command= `SELECT SUBSTR('$MYSQL_DUMP', 1, $_ds_number_pos - 1)`
32--let $_ds_post_command= `SELECT SUBSTR('$MYSQL_DUMP', $_ds_number_pos + 1)`
33--let $_ds_post_command= $_ds_post_command --compact --order-by-primary --skip-extended-insert --no-create-info --databases $_ds_databases
34--let $_ds_prev_outfile=
35
36# iterate over servers
37--let $_ds_servers= $diff_servers
38while ($_ds_servers != '')
39{
40  --let $_ds_server_number= `SELECT SUBSTRING_INDEX('$_ds_servers', ' ', 1)`
41  --let $_ds_servers= `SELECT TRIM(SUBSTRING('$_ds_servers', 1 + LENGTH('_$ds_server_number')))`
42  --let $_ds_outfile= $MYSQLTEST_VARDIR/tmp/diff_servers_$_ds_server_number
43
44  if ($rpl_debug)
45  {
46    --echo generating dump from server '$_ds_server_number' using command '$_ds_pre_command$_ds_server_number $_ds_post_command > $_ds_outfile'
47    --echo remaining servers: '$_ds_servers'
48  }
49  --exec $_ds_pre_command$_ds_server_number $_ds_post_command > $_ds_outfile
50
51  if ($_ds_prev_outfile != '')
52  {
53    if ($rpl_debug)
54    {
55      --echo diffing files '$_ds_prev_outfile' and '$_ds_outfile'
56    }
57    --diff_files $_ds_prev_outfile $_ds_outfile
58
59    --remove_file $_ds_prev_outfile
60  }
61  --let $_ds_prev_outfile= $_ds_outfile
62}
63
64--remove_file $_ds_prev_outfile
65
66--let $include_filename= diff_servers.inc [servers=$_ds_info]
67--source include/end_include_file.inc
68