github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_history/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  DB_COUNT=3
    20  
    21  for i in $(seq $DB_COUNT); do
    22      run_sql "CREATE DATABASE $DB${i};"
    23      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${i}
    24  done
    25  
    26  for i in $(seq $DB_COUNT); do
    27      row_count_ori[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}')
    28  done
    29  
    30  # Make sure BR reads YCSB data 20 seconds after, as BR will backup with "--timeage 10s".
    31  sleep 20
    32  
    33  run_sql "USE ${DB}1; DROP TABLE $TABLE;"
    34  for i in $(seq $DB_COUNT); do
    35      run_sql "DROP DATABASE ${DB}${i};"
    36  done
    37  
    38  # We expect above DDLs finish within 10s.
    39  # history backup full
    40  echo "backup start..."
    41  run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" --timeago "10s"
    42  
    43  # restore full
    44  echo "restore start..."
    45  run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR
    46  
    47  for i in $(seq $DB_COUNT); do
    48      row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}')
    49  done
    50  
    51  fail=false
    52  for i in $(seq $DB_COUNT); do
    53      if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then
    54          fail=true
    55          echo "TEST: [$TEST_NAME] fail on database $DB${i}"
    56      fi
    57      echo "database $DB${i} [original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}"
    58  done
    59  
    60  if $fail; then
    61      echo "TEST: [$TEST_NAME] failed!"
    62      exit 1
    63  fi
    64  
    65  for i in $(seq $DB_COUNT); do
    66      run_sql "DROP DATABASE $DB${i};"
    67  done