|
| 1 | +if ($cnf == "galera2_to_mariadb") |
| 2 | +{ |
| 3 | + --let MASTER_MYPORT= $NODE_MYPORT_1 |
| 4 | + --connect master, 127.0.0.1, root, , test, $NODE_MYPORT_1 |
| 5 | + --connect slave, 127.0.0.1, root, , test, $NODE_MYPORT_3 |
| 6 | + --disable_query_log |
| 7 | + --replace_result $MASTER_MYPORT ### |
| 8 | + --eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='root', MASTER_PORT=$MASTER_MYPORT; |
| 9 | + --enable_query_log |
| 10 | + START SLAVE; |
| 11 | + --source include/wait_for_slave_to_start.inc |
| 12 | + |
| 13 | + --let XTRABACKUP_BACKUP_OPTIONS=--no-defaults --user=root --host='127.0.0.1' --port=$NODE_MYPORT_3 |
| 14 | + --let XTRABACKUP_COPY_BACK_OPTIONS= --no-defaults |
| 15 | +} |
| 16 | + |
| 17 | +if ($cnf == "mariadb_to_mariadb") |
| 18 | +{ |
| 19 | + --let XTRABACKUP_BACKUP_OPTIONS=--defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 |
| 20 | + --let XTRABACKUP_COPY_BACK_OPTIONS=--defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2 |
| 21 | +} |
| 22 | + |
| 23 | +--connection master |
| 24 | +--let $MYSQLD_DATADIR_MASTER= `select @@datadir` |
| 25 | +--connection slave |
| 26 | +--let $MYSQLD_DATADIR_SLAVE= `select @@datadir` |
| 27 | + |
| 28 | +# This test covers the filename:pos based synchronization |
| 29 | +# between the master and the slave. |
| 30 | +# If we ever need to test a GTID based synchronization, |
| 31 | +# it should be done in a separate test. |
| 32 | + |
| 33 | + |
| 34 | +--echo ############################################################## |
| 35 | +--echo ### Initial block with some transactions |
| 36 | + |
| 37 | +--echo ### Slave: Make sure replication is not using GTID |
| 38 | +--connection slave |
| 39 | +--let $value= query_get_value(SHOW SLAVE STATUS, "Using_Gtid", 1) |
| 40 | +--echo # Using_Gtid=$value |
| 41 | + |
| 42 | +--echo ### Master: Create and populate t1 |
| 43 | +--connection master |
| 44 | +CREATE TABLE t1(a TEXT) ENGINE=InnoDB; |
| 45 | +START TRANSACTION; |
| 46 | +INSERT INTO t1 VALUES ('tr#00:stmt#00 - slave run#0, before backup'); |
| 47 | +INSERT INTO t1 VALUES ('tr#00:stmt#01 - slave run#0, before backup'); |
| 48 | +INSERT INTO t1 VALUES ('tr#00:stmt#02 - slave run#0, before backup'); |
| 49 | +COMMIT; |
| 50 | +--sync_slave_with_master |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +--echo ############################################################## |
| 55 | +--echo ### Run the last transaction before mariadb-backup --backup |
| 56 | +--echo ### Remember SHOW MASTER STATUS and @@gtid_binlog_pos |
| 57 | +--echo ### before and after the transaction. |
| 58 | + |
| 59 | +--echo ### Master: Rember MASTER STATUS and @@gtid_binlog_pos before tr#01 |
| 60 | +--connection master |
| 61 | +--let $master_before_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) |
| 62 | +--let $master_before_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) |
| 63 | +--let $master_before_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` |
| 64 | + |
| 65 | +--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos before tr#01 |
| 66 | +--connection slave |
| 67 | +--let $slave_before_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) |
| 68 | +--let $slave_before_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) |
| 69 | +--let $slave_before_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` |
| 70 | + |
| 71 | +--echo ### Master: Run the actual last transaction before the backup |
| 72 | +--connection master |
| 73 | +START TRANSACTION; |
| 74 | +INSERT INTO t1 VALUES ('tr#01:stmt#00 - slave run#0, before backup'); |
| 75 | +INSERT INTO t1 VALUES ('tr#01:stmt#01 - slave run#0, before backup'); |
| 76 | +INSERT INTO t1 VALUES ('tr#01:stmt#02 - slave run#0, before backup'); |
| 77 | +COMMIT; |
| 78 | +--sync_slave_with_master |
| 79 | + |
| 80 | +--echo ### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 |
| 81 | +--connection master |
| 82 | +--let $master_after_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) |
| 83 | +--let $master_after_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) |
| 84 | +--let $master_after_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` |
| 85 | + |
| 86 | +--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01 |
| 87 | +--connection slave |
| 88 | +--let $slave_after_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) |
| 89 | +--let $slave_after_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) |
| 90 | +--let $slave_after_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` |
| 91 | + |
| 92 | + |
| 93 | +--echo ############################################################## |
| 94 | +--echo ### Running `mariadb-backup --backup,--prepare` and checking |
| 95 | +--echo ### that xtrabackup_slave_info and xtrabackup_binlog_info are OK |
| 96 | + |
| 97 | +--echo ### Slave: Create a backup |
| 98 | +--let $backup_slave=$MYSQLTEST_VARDIR/tmp/backup-slave |
| 99 | +--disable_result_log |
| 100 | +--exec $XTRABACKUP $XTRABACKUP_BACKUP_OPTIONS --slave-info --backup --target-dir=$backup_slave |
| 101 | +--enable_result_log |
| 102 | + |
| 103 | +--echo ### Slave: Prepare the backup |
| 104 | +--exec $XTRABACKUP --prepare --target-dir=$backup_slave |
| 105 | + |
| 106 | +--echo ### Slave: xtrabackup files: |
| 107 | +--echo ############################ xtrabackup_slave_info |
| 108 | +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position |
| 109 | +--cat_file $backup_slave/xtrabackup_slave_info |
| 110 | +--echo ############################ xtrabackup_binlog_info |
| 111 | +--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr01_gtid_binlog_pos slave_after_tr01_gtid_binlog_pos |
| 112 | +--cat_file $backup_slave/xtrabackup_binlog_info |
| 113 | +--echo ############################ |
| 114 | + |
| 115 | + |
| 116 | +--echo ############################################################## |
| 117 | +--echo ### Run more transactions after the backup: |
| 118 | +--echo ### - while the slave is still running, then |
| 119 | +--echo ### - while the slave is shut down |
| 120 | + |
| 121 | +--echo ### Master: Run another transaction while the slave is still running |
| 122 | +--connection master |
| 123 | +START TRANSACTION; |
| 124 | +INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup'); |
| 125 | +INSERT INTO t1 VALUES ('tr#02:stmt#01 - slave run#0, after backup'); |
| 126 | +INSERT INTO t1 VALUES ('tr#02:stmt@02 - slave run#0, after backup'); |
| 127 | +COMMIT; |
| 128 | +--sync_slave_with_master |
| 129 | + |
| 130 | +--echo ### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 |
| 131 | +--connection master |
| 132 | +--let $master_after_tr02_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) |
| 133 | +--let $master_after_tr02_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) |
| 134 | +--let $master_after_tr02_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` |
| 135 | + |
| 136 | +--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02 |
| 137 | +--connection slave |
| 138 | +--let $slave_after_tr02_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1) |
| 139 | +--let $slave_after_tr02_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1) |
| 140 | +--let $slave_after_tr02_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos` |
| 141 | + |
| 142 | + |
| 143 | +--echo ### Master: Checking SHOW BINLOG EVENTS |
| 144 | + |
| 145 | +--connection master |
| 146 | +--vertical_results |
| 147 | +### The BEGIN event |
| 148 | +--replace_column 4 # 5 # |
| 149 | +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position $master_after_tr02_gtid_binlog_pos master_after_tr02_gtid_binlog_pos |
| 150 | +--eval SHOW BINLOG EVENTS IN '$master_after_tr01_show_master_status_file' FROM $master_after_tr01_show_master_status_position LIMIT 0,1 |
| 151 | +### The INSERT event |
| 152 | +--replace_column 2 # 4 # 5 # |
| 153 | +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position |
| 154 | +# Hide the difference between row and stmt binary logging |
| 155 | +--replace_regex /use `test`; // /(Query|Annotate_rows)/Query_or_Annotate_rows/ |
| 156 | +--eval SHOW BINLOG EVENTS IN '$master_after_tr01_show_master_status_file' FROM $master_after_tr01_show_master_status_position LIMIT 1,1 |
| 157 | +--horizontal_results |
| 158 | + |
| 159 | +--echo ### Slave: Checking SHOW BINLOG EVENTS |
| 160 | +--connection slave |
| 161 | +--vertical_results |
| 162 | +### The BEGIN event |
| 163 | +--replace_column 2 # 5 # |
| 164 | +--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr02_gtid_binlog_pos slave_after_tr02_gtid_binlog_pos |
| 165 | +--eval SHOW BINLOG EVENTS IN '$slave_after_tr01_show_master_status_file' FROM $slave_after_tr01_show_master_status_position LIMIT 0,1 |
| 166 | +### The INSERT event |
| 167 | +--replace_column 2 # 4 # 5 # |
| 168 | +--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr02_gtid_binlog_pos slave_after_tr02_gtid_binlog_pos |
| 169 | +# Hide the difference between row and stmt binary logging |
| 170 | +--replace_regex /use `test`; // /(Query|Annotate_rows)/Query_or_Annotate_rows/ |
| 171 | +--eval SHOW BINLOG EVENTS IN '$slave_after_tr01_show_master_status_file' FROM $slave_after_tr01_show_master_status_position LIMIT 1,1 |
| 172 | +--horizontal_results |
| 173 | + |
| 174 | +--echo ### Slave: Stop replication |
| 175 | +--connection slave |
| 176 | +STOP SLAVE; |
| 177 | +--source include/wait_for_slave_to_stop.inc |
| 178 | +RESET SLAVE; |
| 179 | + |
| 180 | +--echo ### Slave: Shutdown the server |
| 181 | + |
| 182 | +if ($cnf == "mariadb_to_mariadb") |
| 183 | +{ |
| 184 | + --let $rpl_server_number= 2 |
| 185 | + --source include/rpl_stop_server.inc |
| 186 | +} |
| 187 | + |
| 188 | +if ($cnf == "galera2_to_mariadb") |
| 189 | +{ |
| 190 | + --connection slave |
| 191 | + --source $MYSQL_TEST_DIR/include/shutdown_mysqld.inc |
| 192 | +} |
| 193 | + |
| 194 | +--echo ### Master: Run a transaction while the slave is shut down |
| 195 | +--connection master |
| 196 | +START TRANSACTION; |
| 197 | +INSERT INTO t1 VALUES ('tr#03:stmt#00 - after slave run#0, slave is shut down, after backup'); |
| 198 | +INSERT INTO t1 VALUES ('tr#03:stmt#01 - after slave run#0, slave is shut down, after backup'); |
| 199 | +INSERT INTO t1 VALUES ('tr#03:stmt#02 - after slave run#0, slave is shut down, after backup'); |
| 200 | +COMMIT; |
| 201 | + |
| 202 | + |
| 203 | +--echo ############################################################## |
| 204 | +--echo ### Emulate starting a new virgin slave |
| 205 | + |
| 206 | +--echo ### Slave: Remove the data directory |
| 207 | +--rmdir $MYSQLD_DATADIR_SLAVE |
| 208 | + |
| 209 | +--echo ### Slave: Copy back the backup |
| 210 | +--exec $XTRABACKUP $XTRABACKUP_COPY_BACK_OPTIONS --copy-back --datadir=$MYSQLD_DATADIR_SLAVE --target-dir=$backup_slave |
| 211 | + |
| 212 | +--echo ### Slave: Restart the server |
| 213 | +if ($cnf == "mariadb_to_mariadb") |
| 214 | +{ |
| 215 | + --let $rpl_server_number= 2 |
| 216 | + --source include/rpl_start_server.inc |
| 217 | + --source include/wait_until_connected_again.inc |
| 218 | +} |
| 219 | + |
| 220 | +if ($cnf == "galera2_to_mariadb") |
| 221 | +{ |
| 222 | + --connection slave |
| 223 | + --source $MYSQL_TEST_DIR/include/start_mysqld.inc |
| 224 | +} |
| 225 | + |
| 226 | +--echo ### Slave: Display the restored data before START SLAVE |
| 227 | +--connection slave |
| 228 | +SELECT * FROM t1 ORDER BY a; |
| 229 | + |
| 230 | +--echo ### Slave: Execute the CHANGE MASTER statement to set up the host and port |
| 231 | +--replace_result $MASTER_MYPORT ### |
| 232 | +--eval CHANGE MASTER '' TO MASTER_USER='root', MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_CONNECT_RETRY=1 |
| 233 | + |
| 234 | +--echo ### Slave: Execute the CHANGE MASTER statement from xtrabackup_slave_info |
| 235 | +--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position |
| 236 | +--source $backup_slave/xtrabackup_slave_info |
| 237 | + |
| 238 | +--echo ### Slave: Execute START SLAVE |
| 239 | +--source include/start_slave.inc |
| 240 | + |
| 241 | +--echo ### Master: Wait for the slave to apply all master events |
| 242 | +--connection master |
| 243 | +--sync_slave_with_master slave |
| 244 | + |
| 245 | +--echo ### Slave: Make sure replication is not using GTID after the slave restart |
| 246 | +--connection slave |
| 247 | +--let $value= query_get_value(SHOW SLAVE STATUS, "Using_Gtid", 1) |
| 248 | +--echo # Using_Gtid=$value |
| 249 | + |
| 250 | +--echo ### Slave: Display the restored data after START SLAVE |
| 251 | +--connection slave |
| 252 | +SELECT * FROM t1 ORDER BY a; |
| 253 | + |
| 254 | + |
| 255 | +--echo ############################################################## |
| 256 | +--echo ### Continue master transactions, check the new slave replicates well. |
| 257 | + |
| 258 | +--echo ### Master: Run a transaction after restarting replication |
| 259 | +--connection master |
| 260 | +START TRANSACTION; |
| 261 | +INSERT INTO t1 VALUES ('tr#04:stmt#00 - slave run#1'); |
| 262 | +INSERT INTO t1 VALUES ('tr#04:stmt#01 - slave run#1'); |
| 263 | +INSERT INTO t1 VALUES ('tr#04:stmt#02 - slave run#1'); |
| 264 | +COMMIT; |
| 265 | +--sync_slave_with_master |
| 266 | + |
| 267 | +--echo ### Slave: Display the restored data + new transactions |
| 268 | +--connection slave |
| 269 | +SELECT * FROM t1 ORDER BY a; |
| 270 | + |
| 271 | + |
| 272 | +--echo ############################################################## |
| 273 | +--echo ### Cleanup |
| 274 | + |
| 275 | +--echo ### Removing the backup directory |
| 276 | +--rmdir $backup_slave |
| 277 | + |
| 278 | +--connection master |
| 279 | +DROP TABLE t1; |
| 280 | +--sync_slave_with_master |
| 281 | + |
| 282 | +if ($cnf == "mariadb_to_mariadb") |
| 283 | +{ |
| 284 | + --source include/rpl_end.inc |
| 285 | +} |
| 286 | + |
| 287 | +if ($cnf == "galera2_to_mariadb") |
| 288 | +{ |
| 289 | + STOP SLAVE; |
| 290 | + --source include/wait_for_slave_to_stop.inc |
| 291 | + RESET SLAVE ALL; |
| 292 | + |
| 293 | + --connection master |
| 294 | + set global wsrep_on=OFF; |
| 295 | + RESET MASTER; |
| 296 | + set global wsrep_on=ON; |
| 297 | +} |
0 commit comments