github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_debug_meta/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  
    20  run_sql "CREATE DATABASE $DB;"
    21  go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB
    22  
    23  table_region_sql="SELECT COUNT(*) FROM information_schema.tikv_region_status WHERE db_name = '$DB' AND table_name = '$TABLE';"
    24  for i in $(seq 10); do
    25      regioncount=$(run_sql "$table_region_sql" | awk '/COUNT/{print $2}')
    26      [ $regioncount -ge 5 ] && break
    27      sleep 3
    28  done
    29  run_sql "$table_region_sql"
    30  
    31  row_count_ori=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}')
    32  
    33  # backup table
    34  echo "backup start..."
    35  run_br --pd $PD_ADDR backup table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB"
    36  
    37  run_sql "DROP DATABASE $DB;"
    38  
    39  # Test validate decode
    40  run_br validate decode -s "local://$TEST_DIR/$DB"
    41  
    42  # should generate backupmeta.json
    43  if [ ! -f "$TEST_DIR/$DB/backupmeta.json" ]; then
    44      echo "TEST: [$TEST_NAME] decode failed!"
    45      exit 1
    46  fi
    47  
    48  # Test validate encode
    49  run_br validate encode -s "local://$TEST_DIR/$DB"
    50  
    51  # should generate backupmeta_from_json
    52  if [ ! -f "$TEST_DIR/$DB/backupmeta_from_json" ]; then
    53      echo "TEST: [$TEST_NAME] encode failed!"
    54      exit 1
    55  fi
    56  
    57  # replace backupmeta
    58  mv "$TEST_DIR/$DB/backupmeta_from_json" "$TEST_DIR/$DB/backupmeta"
    59  
    60  # restore table
    61  echo "restore start..."
    62  run_br --pd $PD_ADDR restore table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB"
    63  
    64  row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}')
    65  
    66  if [ "${row_count_ori}" != "${row_count_new}" ];then
    67      echo "TEST: [$TEST_NAME] failed!, row count not equal after restore"
    68      exit 1
    69  fi
    70  
    71  run_sql "DROP DATABASE $DB;"