github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_db/run.sh (about) 1 #!/bin/sh 2 # 3 # Copyright 2019 PingCAP, Inc. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 set -eu 17 DB="$TEST_NAME" 18 19 PROGRESS_FILE="$TEST_DIR/progress_unit_file" 20 rm -rf $PROGRESS_FILE 21 22 run_sql "CREATE DATABASE $DB;" 23 24 run_sql "CREATE TABLE $DB.usertable1 ( \ 25 YCSB_KEY varchar(64) NOT NULL, \ 26 FIELD0 varchar(1) DEFAULT NULL, \ 27 PRIMARY KEY (YCSB_KEY) \ 28 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" 29 30 run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");" 31 run_sql "INSERT INTO $DB.usertable1 VALUES (\"aa\", \"b\");" 32 33 run_sql "CREATE TABLE $DB.usertable2 ( \ 34 YCSB_KEY varchar(64) NOT NULL, \ 35 FIELD0 varchar(1) DEFAULT NULL, \ 36 PRIMARY KEY (YCSB_KEY) \ 37 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" 38 39 run_sql "INSERT INTO $DB.usertable2 VALUES (\"c\", \"d\");" 40 # backup db 41 echo "backup start..." 42 export GO_FAILPOINTS="github.com/pingcap/br/pkg/task/progress-call-back=return(\"$PROGRESS_FILE\")" 43 run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB" 44 export GO_FAILPOINTS="" 45 46 # check if we use the region unit 47 if [[ "$(wc -l <$PROGRESS_FILE)" == "1" ]] && [[ $(grep -c "region" $PROGRESS_FILE) == "1" ]]; 48 then 49 echo "use the correct progress unit" 50 else 51 echo "use the wrong progress unit, expect region" 52 cat $PROGRESS_FILE 53 exit 1 54 fi 55 rm -rf $PROGRESS_FILE 56 57 run_sql "DROP DATABASE $DB;" 58 59 # restore db 60 echo "restore start..." 61 run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR 62 63 table_count=$(run_sql "use $DB; show tables;" | grep "Tables_in" | wc -l) 64 if [ "$table_count" -ne "2" ];then 65 echo "TEST: [$TEST_NAME] failed!" 66 exit 1 67 fi 68 69 # Test BR DDL query string 70 echo "testing DDL query..." 71 run_curl https://$TIDB_STATUS_ADDR/ddl/history | grep -E '/\*from\(br\)\*/CREATE TABLE' 72 run_curl https://$TIDB_STATUS_ADDR/ddl/history | grep -E '/\*from\(br\)\*/CREATE DATABASE' 73 74 run_sql "DROP DATABASE $DB;"