github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_backup_version/run.sh (about) 1 #!/bin/bash 2 # 3 # Copyright 2021 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 # example 20 # "cluster_id": 6931331682760961243 21 expected_cluster_id=`run_curl "https://$PD_ADDR/pd/api/v1/members" | grep "cluster_id"` 22 # example 23 #"4.0.10" 24 expected_cluster_version=`run_curl "https://$PD_ADDR/pd/api/v1/config/cluster-version"` 25 unset BR_LOG_TO_TERM 26 27 function check_version() { 28 folder=$1 29 expected_br_version=$2 30 # FIXME we had strange log here, ignore it temporary 31 # [INFO] [data_slow_query.go:144] ["Telemetry slow query stats initialized"] [currentSQBInfo={xxx}] 32 br_version=`run_br -s "local://$TEST_DIR/$folder" debug decode --field "BrVersion" | grep -v INFO | grep -v log` 33 [[ $br_version =~ $expected_br_version ]] 34 cluster_version=`run_br -s "local://$TEST_DIR/$folder" debug decode --field "ClusterVersion" | grep -v INFO | grep -v log` 35 [[ $cluster_version =~ $expected_cluster_version ]] 36 cluster_id=`run_br -s "local://$TEST_DIR/$folder" debug decode --field "ClusterId" | grep -v INFO | grep -v log | sed -n -e '1p'` 37 [[ $expected_cluster_id =~ $cluster_id ]] 38 } 39 40 # backup empty using BR 41 echo "backup start..." 42 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/br_version_1" 43 if [ $? -ne 0 ]; then 44 echo "TEST: [$TEST_NAME] failed on backup empty cluster version!" 45 exit 1 46 fi 47 48 check_version "br_version_1" "BR" 49 50 # backup empty using BR via SQL 51 echo "backup start..." 52 run_sql "BACKUP DATABASE $DB TO \"local://$TEST_DIR/br_version_2\"" 53 54 # FIXME: uncomment this after TiDB updates this BR dependency 55 # check_version "br_version_2" "TiDB" 56 57 # create a database and insert some data 58 run_sql "CREATE DATABASE $DB;" 59 run_sql "CREATE TABLE $DB.usertable1 ( \ 60 YCSB_KEY varchar(64) NOT NULL, \ 61 FIELD0 varchar(1) DEFAULT NULL, \ 62 PRIMARY KEY (YCSB_KEY) \ 63 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" 64 # insert one row to make sure table is restored. 65 run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");" 66 67 # backup tables using BR 68 echo "backup start..." 69 run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/br_version_3" 70 if [ $? -ne 0 ]; then 71 echo "TEST: [$TEST_NAME] failed on backup empty cluster version!" 72 exit 1 73 fi 74 75 check_version "br_version_3" "BR" 76 77 # backup tables using BR via SQL 78 echo "backup start..." 79 run_sql "BACKUP DATABASE $DB TO \"local://$TEST_DIR/br_version_4\"" 80 81 # FIXME: uncomment this after TiDB updates this BR dependency 82 # check_version "br_version_4" "TiDB" 83 84 run_sql "DROP DATABASE $DB" 85 echo "TEST: [$TEST_NAME] successed!"