github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_incremental_same_table/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 DB_COUNT=3 22 23 echo "load data..." 24 25 # create database 26 run_sql "CREATE DATABASE IF NOT EXISTS $DB;" 27 # create table 28 run_sql "CREATE TABLE IF NOT EXISTS ${DB}.${TABLE} (c1 INT);" 29 # insert records 30 for i in $(seq $ROW_COUNT); do 31 run_sql "INSERT INTO ${DB}.${TABLE}(c1) VALUES ($i);" 32 done 33 34 # full backup 35 echo "full backup start..." 36 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB/full" 37 # run ddls 38 39 # create 3 databases, each db has one table with same name 40 for i in $(seq $DB_COUNT); do 41 # create database 42 run_sql "CREATE DATABASE $DB$i;" 43 # create table 44 run_sql "CREATE TABLE IF NOT EXISTS $DB$i.${TABLE} (c1 INT);" 45 # insert records 46 for j in $(seq $ROW_COUNT); do 47 run_sql "INSERT INTO $DB$i.${TABLE}(c1) VALUES ($j);" 48 done 49 done 50 51 # incremental backup 52 echo "incremental backup start..." 53 last_backup_ts=$(run_br validate decode --field="end-version" -s "local://$TEST_DIR/$DB/full" | grep -oE "^[0-9]+") 54 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB/inc" --lastbackupts $last_backup_ts 55 56 # cleanup env 57 run_sql "DROP DATABASE $DB;" 58 for i in $(seq $DB_COUNT); do 59 run_sql "DROP DATABASE $DB$i;" 60 done 61 62 # full restore 63 echo "full restore start..." 64 run_br restore full -s "local://$TEST_DIR/$DB/full" --pd $PD_ADDR 65 row_count_full=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') 66 # check full restore 67 if [ "${row_count_full}" != "${ROW_COUNT}" ];then 68 echo "TEST: [$TEST_NAME] full restore fail on database $DB" 69 exit 1 70 fi 71 72 # incremental restore only DB2.Table 73 echo "incremental restore start..." 74 run_br restore table --db ${DB}2 --table $TABLE -s "local://$TEST_DIR/$DB/inc" --pd $PD_ADDR 75 row_count_inc=$(run_sql "SELECT COUNT(*) FROM ${DB}2.$TABLE;" | awk '/COUNT/{print $2}') 76 # check full restore 77 if [ "${row_count_inc}" != "${ROW_COUNT}" ];then 78 echo "TEST: [$TEST_NAME] incremental restore fail on database $DB" 79 exit 1 80 fi 81 82 # cleanup env 83 run_sql "DROP DATABASE $DB;" 84 for i in $(seq $DB_COUNT); do 85 run_sql "DROP DATABASE IF EXISTS $DB$i;" 86 done