github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_db_online/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  # restore db
    45  echo "restore start..."
    46  run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --online
    47  
    48  table_count=$(run_sql "use $DB; show tables;" | grep "Tables_in" | wc -l)
    49  if [ "$table_count" -ne "2" ];then
    50      echo "TEST: [$TEST_NAME] failed!"
    51      exit 1
    52  fi
    53  
    54  run_sql "DROP DATABASE $DB;"