github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_full/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 21 for i in $(seq $DB_COUNT); do 22 run_sql "CREATE DATABASE $DB${i};" 23 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} 24 done 25 26 for i in $(seq $DB_COUNT); do 27 row_count_ori[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') 28 done 29 30 # backup full and kill tikv to test reset connection 31 echo "backup with limit start..." 32 export GO_FAILPOINTS="github.com/pingcap/br/pkg/backup/reset-retryable-error=1*return(true)" 33 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB-limit" --concurrency 4 34 export GO_FAILPOINTS="" 35 36 # backup full and let TiKV returns an unknown error, to test whether we can gracefully stop. 37 echo "backup with unretryable error start..." 38 export GO_FAILPOINTS="github.com/pingcap/br/pkg/backup/reset-not-retryable-error=1*return(true)" 39 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB-no-retryable" --concurrency 4 & 40 pid=$! 41 export GO_FAILPOINTS="" 42 sleep 15 43 if ps -q $pid ; then 44 echo "After failed 15 seconds, BR doesn't gracefully shutdown..." 45 exit 1 46 fi 47 48 49 # backup full 50 echo "backup with lz4 start..." 51 export GO_FAILPOINTS="github.com/pingcap/br/pkg/backup/backup-storage-error=1*return(\"connection refused\")" 52 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB-lz4" --concurrency 4 --compression lz4 53 export GO_FAILPOINTS="" 54 size_lz4=$(du -d 0 $TEST_DIR/$DB-lz4 | awk '{print $1}') 55 56 echo "backup with zstd start..." 57 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB-zstd" --concurrency 4 --compression zstd --compression-level 6 58 size_zstd=$(du -d 0 $TEST_DIR/$DB-zstd | awk '{print $1}') 59 60 if [ "$size_lz4" -le "$size_zstd" ]; then 61 echo "full backup lz4 size $size_lz4 is small than backup with zstd $size_zstd" 62 exit -1 63 fi 64 65 for ct in limit lz4 zstd; do 66 for i in $(seq $DB_COUNT); do 67 run_sql "DROP DATABASE $DB${i};" 68 done 69 70 # restore full 71 echo "restore with $ct backup start..." 72 export GO_FAILPOINTS="github.com/pingcap/br/pkg/restore/restore-storage-error=1*return(\"connection refused\")" 73 run_br restore full -s "local://$TEST_DIR/$DB-$ct" --pd $PD_ADDR --ratelimit 1024 74 export GO_FAILPOINTS="" 75 76 for i in $(seq $DB_COUNT); do 77 row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') 78 done 79 80 fail=false 81 for i in $(seq $DB_COUNT); do 82 if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then 83 fail=true 84 echo "TEST: [$TEST_NAME] fail on database $DB${i}" 85 fi 86 echo "database $DB${i} [original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}" 87 done 88 89 if $fail; then 90 echo "TEST: [$TEST_NAME] failed!" 91 exit 1 92 fi 93 done 94 95 for i in $(seq $DB_COUNT); do 96 run_sql "DROP DATABASE $DB${i};" 97 done