github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_incremental_only_ddl/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  
    22  echo "load data..."
    23  # create database
    24  run_sql "CREATE DATABASE IF NOT EXISTS $DB;"
    25  # create table
    26  run_sql "CREATE TABLE IF NOT EXISTS ${DB}.${TABLE} (c1 INT);"
    27  # insert records
    28  for i in $(seq $ROW_COUNT); do
    29      run_sql "INSERT INTO ${DB}.${TABLE}(c1) VALUES ($i);"
    30  done
    31  
    32  # full backup
    33  echo "full backup start..."
    34  run_br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/full" --db $DB -t $TABLE
    35  # run ddls
    36  echo "run ddls..."
    37  run_sql "RENAME TABLE ${DB}.${TABLE} to ${DB}.${TABLE}1;"
    38  run_sql "DROP TABLE ${DB}.${TABLE}1;"
    39  run_sql "DROP DATABASE ${DB};"
    40  run_sql "CREATE DATABASE ${DB};"
    41  run_sql "CREATE TABLE ${DB}.${TABLE}1 (c2 CHAR(255));"
    42  run_sql "RENAME TABLE ${DB}.${TABLE}1 to ${DB}.${TABLE};"
    43  run_sql "TRUNCATE TABLE ${DB}.${TABLE};"
    44  
    45  # incremental backup
    46  echo "incremental backup start..."
    47  last_backup_ts=$(run_br validate decode --field="end-version" -s "local://$TEST_DIR/$DB/full" | grep -oE "^[0-9]+")
    48  run_br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/inc" --db $DB -t $TABLE --lastbackupts $last_backup_ts
    49  
    50  run_sql "DROP DATABASE $DB;"
    51  
    52  # full restore
    53  echo "full restore start..."
    54  run_br restore table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB/full" --pd $PD_ADDR
    55  row_count_full=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}')
    56  # check full restore
    57  if [ "${row_count_full}" != "${ROW_COUNT}" ];then
    58      echo "TEST: [$TEST_NAME] full restore fail on database $DB"
    59      exit 1
    60  fi
    61  # incremental restore
    62  echo "incremental restore start..."
    63  fail=false
    64  run_br restore table --db $DB --table $TABLE -s "local://$TEST_DIR/$DB/inc" --pd $PD_ADDR || fail=true
    65  if $fail; then
    66      echo "TEST: [$TEST_NAME] incremental restore fail on database $DB"
    67      exit 1
    68  fi
    69  
    70  run_sql "DROP DATABASE $DB;"