github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_full_index/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 TABLE="usertable" 19 DB_COUNT=3 20 LOG=/$TEST_DIR/backup.log 21 22 for i in $(seq $DB_COUNT); do 23 run_sql "CREATE DATABASE $DB${i};" 24 go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB${i} 25 done 26 27 for i in $(seq $DB_COUNT); do 28 row_count_ori[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') 29 done 30 31 for i in $(seq $DB_COUNT); do 32 run_sql "USE $DB${i}; ALTER TABLE $TABLE ADD INDEX i1(FIELD0);" 33 run_sql "USE $DB${i}; ALTER TABLE $TABLE DROP INDEX i1;" 34 run_sql "USE $DB${i}; ALTER TABLE $TABLE ADD INDEX i1(FIELD1);" 35 done 36 37 # backup full 38 echo "backup start..." 39 # Do not log to terminal 40 unset BR_LOG_TO_TERM 41 # do not backup stats to test whether we can restore without stats. 42 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" --ignore-stats=true --log-file $LOG || cat $LOG 43 BR_LOG_TO_TERM=1 44 45 checksum_count=$(cat $LOG | grep "checksum success" | wc -l | xargs) 46 47 if [ "${checksum_count}" -lt "$DB_COUNT" ];then 48 echo "TEST: [$TEST_NAME] fail on fast checksum: required $DB_COUNT databases checked, but only ${checksum_count} dbs checked" 49 echo $(cat $LOG | grep checksum) 50 exit 1 51 fi 52 53 for i in $(seq $DB_COUNT); do 54 run_sql "DROP DATABASE $DB${i};" 55 done 56 57 # restore full 58 echo "restore start..." 59 run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR 60 61 for i in $(seq $DB_COUNT); do 62 row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') 63 done 64 65 fail=false 66 for i in $(seq $DB_COUNT); do 67 if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then 68 fail=true 69 echo "TEST: [$TEST_NAME] fail on database $DB${i}" 70 fi 71 echo "database $DB${i} [original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}" 72 done 73 74 if $fail; then 75 echo "TEST: [$TEST_NAME] failed!" 76 exit 1 77 fi 78 79 for i in $(seq $DB_COUNT); do 80 run_sql "DROP DATABASE $DB${i};" 81 done