github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_insert_after_restore/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 ROW_COUNT=10 20 PATH="tests/$TEST_NAME:bin:$PATH" 21 22 insertRecords() { 23 for i in $(seq $1); do 24 run_sql "INSERT INTO $DB.$TABLE VALUES ('$i');" 25 done 26 } 27 28 createTable() { 29 run_sql "CREATE TABLE IF NOT EXISTS $DB.$TABLE (c1 CHAR(255));" 30 } 31 32 echo "load data..." 33 echo "create database" 34 run_sql "CREATE DATABASE IF NOT EXISTS $DB;" 35 echo "create table" 36 createTable 37 echo "insert records" 38 insertRecords $ROW_COUNT 39 40 row_count_ori=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 41 42 # backup full 43 echo "backup start..." 44 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" 45 46 run_sql "DROP DATABASE $DB;" 47 48 # restore full 49 echo "restore start..." 50 run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR 51 52 row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 53 54 fail=false 55 if [ "${row_count_ori}" != "${row_count_new}" ];then 56 fail=true 57 echo "TEST: [$TEST_NAME] fail on database $DB" 58 fi 59 echo "database $DB [original] row count: ${row_count_ori}, [after br] row count: ${row_count_new}" 60 61 if $fail; then 62 echo "TEST: [$TEST_NAME] failed!" 63 exit 1 64 fi 65 66 # insert records 67 insertRecords $ROW_COUNT 68 row_count_insert=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 69 fail=false 70 if [ "${row_count_insert}" != "$(expr $row_count_new \* 2)" ];then 71 fail=true 72 echo "TEST: [$TEST_NAME] fail on inserting records to database $DB after restore: ${row_count_insert}" 73 fi 74 75 if $fail; then 76 echo "TEST: [$TEST_NAME] failed!" 77 exit 1 78 fi 79 80 run_sql "DROP DATABASE $DB;"