github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_systables/run.sh (about) 1 #! /bin/bash 2 3 set -eux 4 5 backup_dir=$TEST_DIR/$TEST_NAME 6 7 test_data="('TiDB'),('TiKV'),('TiFlash'),('TiSpark'),('TiCDC'),('TiPB'),('Rust'),('C++'),('Go'),('Haskell'),('Scala')" 8 9 modify_systables() { 10 run_sql "CREATE USER 'Alyssa P. Hacker'@'%' IDENTIFIED BY 'password';" 11 run_sql "UPDATE mysql.tidb SET VARIABLE_VALUE = '1h' WHERE VARIABLE_NAME = 'tikv_gc_life_time';" 12 13 run_sql "CREATE TABLE mysql.foo(pk int primary key auto_increment, field varchar(255));" 14 run_sql "CREATE TABLE mysql.bar(pk int primary key auto_increment, field varchar(255));" 15 16 run_sql "INSERT INTO mysql.foo(field) VALUES $test_data" 17 run_sql "INSERT INTO mysql.bar(field) VALUES $test_data" 18 19 go-ycsb load mysql -P tests/"$TEST_NAME"/workload \ 20 -p mysql.host="$TIDB_IP" \ 21 -p mysql.port="$TIDB_PORT" \ 22 -p mysql.user=root \ 23 -p mysql.db=mysql 24 25 run_sql "ANALYZE TABLE mysql.usertable;" 26 } 27 28 add_user() { 29 run_sql "CREATE USER 'newuser' IDENTIFIED BY 'newuserpassword';" 30 } 31 32 delete_user() { 33 # FIXME don't check the user table until we support restore user correctly. 34 echo "delete user newuser" 35 # run_sql "DROP USER 'newuser'" 36 } 37 38 add_test_data() { 39 run_sql "CREATE DATABASE usertest;" 40 run_sql "CREATE TABLE usertest.test(pk int primary key auto_increment, field varchar(255));" 41 run_sql "INSERT INTO usertest.test(field) VALUES $test_data" 42 } 43 44 delete_test_data() { 45 run_sql "DROP TABLE usertest.test;" 46 } 47 48 rollback_modify() { 49 run_sql "DROP TABLE mysql.foo;" 50 run_sql "DROP TABLE mysql.bar;" 51 run_sql "UPDATE mysql.tidb SET VARIABLE_VALUE = '10m' WHERE VARIABLE_NAME = 'tikv_gc_life_time';" 52 # FIXME don't check the user table until we support restore user correctly. 53 # run_sql "DROP USER 'Alyssa P. Hacker';" 54 run_sql "DROP TABLE mysql.usertable;" 55 } 56 57 check() { 58 run_sql "SELECT count(*) from mysql.foo;" | grep 11 59 run_sql "SELECT count(*) from mysql.usertable;" | grep 1000 60 run_sql "SHOW TABLES IN mysql;" | awk '/bar/{exit 1}' 61 # we cannot let user overwrite `mysql.tidb` through br in any time. 62 run_sql "SELECT VARIABLE_VALUE FROM mysql.tidb WHERE VARIABLE_NAME = 'tikv_gc_life_time'" | awk '/1h/{exit 1}' 63 64 # FIXME don't check the user table until we support restore user correctly. 65 # TODO remove this after supporting auto flush. 66 # run_sql "FLUSH PRIVILEGES;" 67 # run_sql "SELECT CURRENT_USER();" -u'Alyssa P. Hacker' -p'password' | grep 'Alyssa P. Hacker' 68 # run_sql "SHOW DATABASES" | grep -v '__TiDB_BR_Temporary_' 69 # TODO check stats after supportting. 70 } 71 72 check2() { 73 run_sql "SELECT count(*) from usertest.test;" | grep 11 74 # FIXME don't check the user table until we support restore user correctly. 75 # run_sql "SELECT user FROM mysql.user WHERE user='newuser';" | grep 'newuser' 76 } 77 78 modify_systables 79 run_br backup full -s "local://$backup_dir" 80 rollback_modify 81 run_br restore full -f '*.*' -f '!mysql.bar' -s "local://$backup_dir" 82 check 83 84 run_br restore full -f 'mysql.bar' -s "local://$backup_dir" 85 run_sql "SELECT count(*) from mysql.bar;" | grep 11 86 87 rollback_modify 88 run_br restore full -f "mysql*.*" -f '!mysql.bar' -s "local://$backup_dir" 89 check 90 91 add_user 92 add_test_data 93 run_br backup full -s "local://${backup_dir}1" 94 delete_user 95 delete_test_data 96 run_br restore full -f "mysql*.*" -f "usertest.*" -s "local://${backup_dir}1" 97 check2 98 99 delete_user 100 run_br restore db --db mysql -s "local://${backup_dir}1" 101 check2 102