github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_incremental_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 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} VALUES ($i);" 30 done 31 32 # full backup 33 echo "backup full start..." 34 run_sql "CREATE INDEX idx_c1 ON ${DB}.${TABLE}(c1)" 35 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB/full" 36 wait 37 # run ddls 38 echo "run ddls..." 39 run_sql "ALTER TABLE ${DB}.${TABLE} ADD COLUMN c2 INT NOT NULL;"; 40 run_sql "ALTER TABLE ${DB}.${TABLE} ADD COLUMN c3 INT NOT NULL;"; 41 run_sql "ALTER TABLE ${DB}.${TABLE} DROP COLUMN c3;"; 42 # incremental backup 43 echo "incremental backup start..." 44 last_backup_ts=$(run_br validate decode --field="end-version" -s "local://$TEST_DIR/$DB/full" | grep -oE "^[0-9]+") 45 run_br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/inc" --db $DB -t $TABLE --lastbackupts $last_backup_ts 46 47 run_sql "DROP DATABASE $DB;" 48 # full restore 49 echo "full restore start..." 50 run_br restore table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB/full" --pd $PD_ADDR 51 row_count_full=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 52 # check full restore 53 if [ "${row_count_full}" != "${ROW_COUNT}" ];then 54 echo "TEST: [$TEST_NAME] full restore fail on database $DB" 55 exit 1 56 fi 57 # incremental restore 58 echo "incremental restore start..." 59 run_br restore table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB/inc" --pd $PD_ADDR 60 row_count_inc=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 61 # check full restore 62 if [ "${row_count_inc}" != "${ROW_COUNT}" ];then 63 echo "TEST: [$TEST_NAME] incremental restore fail on database $DB" 64 exit 1 65 fi 66 run_sql "INSERT INTO ${DB}.${TABLE} VALUES (1, 1);" 67 row_count_insert=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 68 # check insert count 69 if [ "${row_count_insert}" != "$(expr $row_count_inc + 1)" ];then 70 echo "TEST: [$TEST_NAME] insert record fail on database $DB" 71 exit 1 72 fi 73 74 run_sql "DROP DATABASE $DB;"