github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_incremental_ddl/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=100 20 PATH="tests/$TEST_NAME:bin:$PATH" 21 22 echo "load data..." 23 # create database 24 run_sql "CREATE DATABASE IF NOT EXISTS $DB;" 25 # create table 26 run_sql "CREATE TABLE IF NOT EXISTS ${DB}.${TABLE} (c1 INT);" 27 # insert records 28 for i in $(seq $ROW_COUNT); do 29 run_sql "INSERT INTO ${DB}.${TABLE}(c1) VALUES ($i);" 30 done 31 32 # full backup 33 echo "full backup start..." 34 run_br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/full" --db $DB -t $TABLE 35 # run ddls 36 echo "run ddls..." 37 run_sql "RENAME TABLE ${DB}.${TABLE} to ${DB}.${TABLE}1;" 38 run_sql "DROP TABLE ${DB}.${TABLE}1;" 39 run_sql "DROP DATABASE ${DB};" 40 run_sql "CREATE DATABASE ${DB};" 41 run_sql "CREATE TABLE ${DB}.${TABLE}1 (c2 CHAR(255));" 42 run_sql "RENAME TABLE ${DB}.${TABLE}1 to ${DB}.${TABLE};" 43 run_sql "TRUNCATE TABLE ${DB}.${TABLE};" 44 # insert records 45 for i in $(seq $ROW_COUNT); do 46 run_sql "INSERT INTO ${DB}.${TABLE}(c2) VALUES ('$i');" 47 done 48 # incremental backup 49 echo "incremental backup start..." 50 last_backup_ts=$(run_br validate decode --field="end-version" -s "local://$TEST_DIR/$DB/full" | grep -oE "^[0-9]+") 51 run_br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/inc" --db $DB -t $TABLE --lastbackupts $last_backup_ts 52 53 run_sql "DROP DATABASE $DB;" 54 # full restore 55 echo "full restore start..." 56 run_br restore table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB/full" --pd $PD_ADDR 57 row_count_full=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 58 # check full restore 59 if [ "${row_count_full}" != "${ROW_COUNT}" ];then 60 echo "TEST: [$TEST_NAME] full restore fail on database $DB" 61 exit 1 62 fi 63 # incremental restore 64 echo "incremental restore start..." 65 run_br restore table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB/inc" --pd $PD_ADDR 66 row_count_inc=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 67 # check full restore 68 if [ "${row_count_inc}" != "${ROW_COUNT}" ];then 69 echo "TEST: [$TEST_NAME] incremental restore fail on database $DB" 70 exit 1 71 fi 72 run_sql "INSERT INTO ${DB}.${TABLE}(c2) VALUES ('1');" 73 74 run_sql "DROP DATABASE $DB;"