github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_db_online_newkv/run.sh (about) 1 #!/bin/sh 2 # 3 # Copyright 2020 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 19 run_sql "CREATE DATABASE $DB;" 20 21 run_sql "CREATE TABLE $DB.usertable1 ( \ 22 YCSB_KEY varchar(64) NOT NULL, \ 23 FIELD0 varchar(1) DEFAULT NULL, \ 24 PRIMARY KEY (YCSB_KEY) \ 25 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" 26 27 run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");" 28 run_sql "INSERT INTO $DB.usertable1 VALUES (\"aa\", \"b\");" 29 30 run_sql "CREATE TABLE $DB.usertable2 ( \ 31 YCSB_KEY varchar(64) NOT NULL, \ 32 FIELD0 varchar(1) DEFAULT NULL, \ 33 PRIMARY KEY (YCSB_KEY) \ 34 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" 35 36 run_sql "INSERT INTO $DB.usertable2 VALUES (\"c\", \"d\");" 37 38 # backup db 39 echo "backup start..." 40 run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB" 41 42 run_sql "DROP DATABASE $DB;" 43 44 # enable placement rules 45 run_pd_ctl -u https://$PD_ADDR config set enable-placement-rules true 46 47 # add new tikv for restore 48 # actaul tikv_addr are TIKV_ADDR${i} 49 TIKV_ADDR="127.0.0.1:2017" 50 TIKV_STATUS_ADDR="127.0.0.1:2019" 51 TIKV_COUNT=3 52 53 echo "Starting restore TiKV..." 54 for i in $(seq $TIKV_COUNT); do 55 tikv-server \ 56 --pd "$PD_ADDR" \ 57 -A "$TIKV_ADDR$i" \ 58 --status-addr "$TIKV_STATUS_ADDR$i" \ 59 --log-file "$TEST_DIR/restore-tikv${i}.log" \ 60 -C "tests/config/restore-tikv.toml" \ 61 -s "$TEST_DIR/restore-tikv${i}" & 62 done 63 sleep 5 64 65 # restore db 66 echo "restore start..." 67 run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --online 68 69 # TODO we should check whether the restore RPCs are send to the new TiKV. 70 table_count=$(run_sql "use $DB; show tables;" | grep "Tables_in" | wc -l) 71 if [ "$table_count" -ne "2" ];then 72 echo "TEST: [$TEST_NAME] failed!" 73 exit 1 74 fi 75 76 run_pd_ctl -u https://$PD_ADDR config set enable-placement-rules false 77 78 run_sql "DROP DATABASE $DB;"