forked from romeOz/docker-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·158 lines (144 loc) · 10.3 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
set -e
echo "-- Building mysql 5.5 image"
docker build -t mysql-5.5 5.5/
DIR_VOLUME=$(pwd)/vol55
mkdir -p ${DIR_VOLUME}/backup
echo
echo "-- Testing mysql 5.5 is running"
docker run --name base_1 -d -e MYSQL_USER=user -e 'MYSQL_PASS=test' mysql-5.5; sleep 10
docker run --name base_2 -d --link base_1:base_1 mysql-5.5; sleep 10
docker exec -it base_2 bash -c 'mysqladmin -uuser -ptest -h${BASE_1_PORT_3306_TCP_ADDR} ping | grep -c "mysqld is alive"'
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
echo
echo "-- Testing backup/checking on mysql 5.5"
docker run --name base_1 -d -e MYSQL_USER=user -e 'MYSQL_PASS=test' -e 'DB_NAME=db_1,test_1' mysql-5.5; sleep 10
docker run -it --rm --link base_1:base_1 -e 'MYSQL_MODE=backup' -e 'DB_REMOTE_HOST=base_1' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=test' -v $(pwd)/vol55/backup:/tmp/backup mysql-5.5; sleep 10
docker run -it --rm -e 'MYSQL_CHECK=default' -e 'DB_NAME=db_1' -v ${DIR_VOLUME}/backup:/tmp/backup mysql-5.5 | tail -n 1 | grep -c 'Success'; sleep 10
docker run -it --rm -e 'MYSQL_CHECK=/tmp/backup/backup.last.bz2' -e 'DB_NAME=test_1' -v ${DIR_VOLUME}/backup:/tmp/backup mysql-5.5 | tail -n 1 | grep -c 'Success'; sleep 10
docker run -it --rm -e 'MYSQL_CHECK=default' -e 'DB_NAME=db' -v ${DIR_VOLUME}/backup:/tmp/backup mysql-5.5 2>&1 | tail -n 1 | grep -c 'Fail'; sleep 10
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
rm -r ${DIR_VOLUME}
echo
echo
echo "-- Testing master/slave on mysql 5.5"
docker run --name base_1 -d -e 'MYSQL_MODE=master' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'DB_NAME=db_1,test_1' mysql-5.5; sleep 10
docker exec -it base_1 mysql -uroot -e 'CREATE TABLE test_1.foo (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), PRIMARY KEY(id)) ENGINE = INNODB; INSERT INTO test_1.foo (name) VALUES ("Petr");'
echo
echo "-- Create slave"
docker run --name base_2 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' mysql-5.5; sleep 10
echo
echo "-- Backup master"
docker run -it --rm --link base_1:base_1 -e 'MYSQL_MODE=backup' -e 'DB_REMOTE_HOST=base_1' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.5 --master-data --single-transaction; sleep 10
echo
echo "-- Restore slave from master-file"
docker run --name base_3 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=/tmp/backup/backup.last.bz2' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.5; sleep 10
docker exec -it base_1 mysql -uroot -e 'INSERT INTO test_1.foo (name) VALUES ("Tom");'; sleep 5
docker run --name base_4 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=default' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.5; sleep 10
docker exec -it base_3 mysql -uroot -e 'SELECT * FROM test_1.foo;' | grep -c -w "Tom"
echo
echo "-- Backup slave"
docker run -it --rm --link base_4:base_4 -e 'MYSQL_MODE=backup' -e 'DB_REMOTE_HOST=base_4' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' -v ${DIR_VOLUME}/backup_slave:/tmp/backup mysql-5.5 --dump-slave; sleep 10
echo
echo "-- Restore slave from slave-file"
docker run --name base_5 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=/tmp/backup/backup.last.bz2' -v ${DIR_VOLUME}/backup_slave:/tmp/backup mysql-5.5; sleep 10
docker exec -it base_1 mysql -uroot -e 'INSERT INTO test_1.foo (name) VALUES ("Bob");'; sleep 5
docker exec -it base_5 mysql -uroot -e 'SELECT * FROM test_1.foo;' | grep -c -w "Bob"
docker exec -it base_1 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3"
docker exec -it base_2 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3"
docker exec -it base_3 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3"
docker exec -it base_4 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3"
docker exec -it base_5 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3"
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
echo
echo "-- Restore master from master-file"
docker run --name restore_1 -d -e 'MYSQL_MODE=master' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=default' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.5; sleep 10
docker run --name restore_2 -d --link restore_1:restore_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=restore_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' mysql-5.5; sleep 10
docker exec -it restore_1 mysql -uroot -e 'INSERT INTO test_1.foo (name) VALUES ("Romeo");'; sleep 5
docker exec -it restore_1 mysql -uroot -e 'SELECT * FROM test_1.foo;' | grep -c -w "Romeo";
docker exec -it restore_1 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "2"
docker exec -it restore_2 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "2"
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
docker rmi mysql-5.5; sleep 5
rm -r ${DIR_VOLUME}
echo
echo
echo "-- Building mysql 5.6 image"
docker build -t mysql-5.6 5.6/
DIR_VOLUME=$(pwd)/vol56
mkdir -p ${DIR_VOLUME}/backup
echo
echo "-- Testing mysql 5.6 is running"
docker run --name base_1 -d -e MYSQL_USER=user -e 'MYSQL_PASS=test' mysql-5.6; sleep 10
docker run --name base_2 -d --link base_1:base_1 mysql-5.6; sleep 10
docker exec -it base_2 bash -c 'mysqladmin -uuser -ptest -h${BASE_1_PORT_3306_TCP_ADDR} ping | grep -c "mysqld is alive"'
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
echo
echo "-- Testing backup/checking on mysql 5.6"
docker run --name base_1 -d -e MYSQL_USER=user -e 'MYSQL_PASS=test' -e 'DB_NAME=db_1,test_1' mysql-5.6; sleep 10
docker run -it --rm --link base_1:base_1 -e 'MYSQL_MODE=backup' -e 'DB_REMOTE_HOST=base_1' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=test' -v $(pwd)/vol56/backup:/tmp/backup mysql-5.6; sleep 10
docker run -it --rm -e 'MYSQL_CHECK=default' -e 'DB_NAME=db_1' -v ${DIR_VOLUME}/backup:/tmp/backup mysql-5.6 | tail -n 1 | grep -c 'Success'; sleep 10
docker run -it --rm -e 'MYSQL_CHECK=/tmp/backup/backup.last.bz2' -e 'DB_NAME=test_1' -v ${DIR_VOLUME}/backup:/tmp/backup mysql-5.6 | tail -n 1 | grep -c 'Success'; sleep 10
docker run -it --rm -e 'MYSQL_CHECK=default' -e 'DB_NAME=db' -v ${DIR_VOLUME}/backup:/tmp/backup mysql-5.6 2>&1 | tail -n 1 | grep -c 'Fail'; sleep 10
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
rm -r ${DIR_VOLUME}
echo
echo
echo "-- Testing master/slave on mysql 5.6"
docker run --name base_1 -d -e 'MYSQL_MODE=master' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'DB_NAME=db_1,test_1' mysql-5.6; sleep 10
docker exec -it base_1 mysql -uroot -e 'CREATE TABLE test_1.foo (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), PRIMARY KEY(id)) ENGINE = INNODB; INSERT INTO test_1.foo (name) VALUES ("Petr");'
echo
echo "-- Create slave"
docker run --name base_2 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' mysql-5.6; sleep 10
echo
echo "-- Backup master"
docker run -it --rm --link base_1:base_1 -e 'MYSQL_MODE=backup' -e 'DB_REMOTE_HOST=base_1' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.6 --master-data --single-transaction; sleep 10
echo
echo "-- Restore slave from master-file"
docker run --name base_3 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=/tmp/backup/backup.last.bz2' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.6; sleep 10
docker exec -it base_1 mysql -uroot -e 'INSERT INTO test_1.foo (name) VALUES ("Tom");'; sleep 5
docker run --name base_4 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=default' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.6; sleep 10
docker exec -it base_3 mysql -uroot -e 'SELECT * FROM test_1.foo;' | grep -c -w "Tom"
echo
echo "-- Backup slave"
docker run -it --rm --link base_4:base_4 -e 'MYSQL_MODE=backup' -e 'DB_REMOTE_HOST=base_4' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' -v ${DIR_VOLUME}/backup_slave:/tmp/backup mysql-5.6 --dump-slave; sleep 10
echo
echo "-- Restore slave from slave-file"
docker run --name base_5 -d --link base_1:base_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=base_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=/tmp/backup/backup.last.bz2' -v ${DIR_VOLUME}/backup_slave:/tmp/backup mysql-5.6; sleep 10
docker exec -it base_1 mysql -uroot -e 'INSERT INTO test_1.foo (name) VALUES ("Bob");'; sleep 10
docker exec -it base_5 mysql -uroot -e 'SELECT * FROM test_1.foo;' | grep -c -w "Bob"
docker exec -it base_1 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3";sleep 3
docker exec -it base_2 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3";sleep 3
docker exec -it base_3 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3";sleep 3
docker exec -it base_4 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3";sleep 3
docker exec -it base_5 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "3"
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
echo
echo "-- Restore master from master-file"
docker run --name restore_1 -d -e 'MYSQL_MODE=master' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'MYSQL_RESTORE=default' -v ${DIR_VOLUME}/backup_master:/tmp/backup mysql-5.6; sleep 10
docker run --name restore_2 -d --link restore_1:restore_1 -e 'MYSQL_MODE=slave' -e 'REPLICATION_HOST=restore_1' -e MYSQL_USER=user -e 'MYSQL_PASS=pass' -e 'DB_REMOTE_USER=user' -e 'DB_REMOTE_PASS=pass' mysql-5.6; sleep 10
docker exec -it restore_1 mysql -uroot -e 'INSERT INTO test_1.foo (name) VALUES ("Romeo");'; sleep 5
docker exec -it restore_1 mysql -uroot -e 'SELECT * FROM test_1.foo;' | grep -c -w "Romeo";
docker exec -it restore_1 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "2"
docker exec -it restore_2 mysql -uroot -e 'SELECT COUNT(*) FROM test_1.foo;' | grep -c -w "2"
echo
echo "-- Clear"
docker rm -f -v $(sudo docker ps -aq); sleep 5
docker rmi mysql-5.6; sleep 5
rm -r ${DIR_VOLUME}
echo
echo "-- Done"