SET DEBUG_SYNC= 'RESET';
From con1:
DROP DATABASE IF EXISTS db1;
DROP DATABASE IF EXISTS db2;
DROP DATABASE IF EXISTS db3;
Create database 1 and a table then populate it
CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT);
INSERT INTO db1.t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(0);
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
INSERT INTO db1.t1 SELECT * FROM db1.t1;
CREATE TABLE db1.t2 (a int) ENGINE=MEMORY;
INSERT INTO db1.t2 VALUES (1),(2),(3),(4),(5);
CREATE TABLE db1.t3 (a int) ENGINE=INNODB;
INSERT INTO db1.t3 VALUES (11),(12),(13);
Show initial count of table
SELECT COUNT(*) FROM db1.t1;
COUNT(*)
327680
SELECT COUNT(*) FROM db1.t2;
COUNT(*)
5
SELECT COUNT(*) FROM db1.t3;
COUNT(*)
3
From con2:
Create database 2 and a table then populate it and add a trigger
that updates the table in database 1
CREATE DATABASE db2;
CREATE TABLE db2.t2 (A INT);
CREATE TRIGGER db2.trg AFTER INSERT ON db2.t2 FOR EACH ROW
BEGIN
INSERT INTO db1.t1 VALUES ('99');
END|
From con1:
Now do the backup 
BACKUP DATABASE db1 TO 'db1.bak';
backup_id
#
DROP DATABASE db1;
now start the restore and while the restore is running, fire the trigger
activate synchronization points for restore.
SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
RESTORE FROM 'db1.bak' OVERWRITE;;
From breakpoints:
Wait for restore to reach its synchronization point.
SET DEBUG_SYNC= 'now WAIT_FOR wait_for_restore';
From con2:
Now do the insert while restore is running.
INSERT INTO db2.t2 VALUES (0);
From breakpoints:
breakpoints: Sending finish signal to wake restore.
SET DEBUG_SYNC= 'now SIGNAL finish';
Reattach to connection 2 and finish.
Reattach to connection 1 and finish.
backup_id
#
Show the count for t1. It should be 1 more than before restore.
SELECT COUNT(*) FROM db1.t1;
COUNT(*)
327681
SELECT * FROM db1.t2;
a
1
2
3
4
5
SELECT * FROM db1.t3;
a
11
12
13
SET DEBUG_SYNC= 'RESET';
DELETE FROM db2.t2;
now start the restore and while the restore is running, fire the trigger
activate synchronization points for restore.
SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
RESTORE FROM 'db1.bak' OVERWRITE;;
From breakpoints:
Wait for restore to reach its synchronization point.
SET DEBUG_SYNC= 'now WAIT_FOR wait_for_restore';
From con2:
Now do the select while restore is running.
SELECT * FROM db1.t1 limit 10;
From breakpoints:
breakpoints: Sending finish signal to wake restore.
SET DEBUG_SYNC= 'now SIGNAL finish';
Reattach to connection 2 and finish.
a
1
2
3
4
5
6
7
8
9
0
Reattach to connection 1 and finish.
backup_id
#
Show the count for t1. It should be the same as before restore.
SELECT COUNT(*) FROM db1.t1;
COUNT(*)
327680
SELECT * FROM db1.t2;
a
1
2
3
4
5
SELECT * FROM db1.t3;
a
11
12
13
SET DEBUG_SYNC= 'RESET';
Create a database with a table and a view using the MyISAM engine.
CREATE DATABASE db3;
CREATE TABLE db3.t1(name CHAR(10));
INSERT INTO db3.t1 VALUES('A'),('B'),('C'),('D');
CREATE VIEW db3.v1 AS SELECT * FROM db3.t1;
Show the data before backup
SELECT * FROM db3.t1;
name
A
B
C
D
SELECT * FROM db3.v1;
name
A
B
C
D
Backup the database.
BACKUP DATABASE db3 TO 'db3.bak';
backup_id
#
Now drop then restore the database.
DROP DATABASE db3;
RESTORE FROM 'db3.bak';
backup_id
#
Show the table and view.
SHOW FULL TABLES FROM db3;
Tables_in_db3	Table_type
t1	BASE TABLE
v1	VIEW
Show the data after restore.
SELECT * FROM db3.v1;
name
A
B
C
D
SELECT * FROM db3.t1;
name
A
B
C
D
cleanup
DROP DATABASE db1;
DROP DATABASE db2;
DROP DATABASE db3;
