github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_gcs/run.sh (about) 1 #!/bin/bash 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 -eux 17 DB="$TEST_NAME" 18 TABLE="usertable" 19 DB_COUNT=3 20 21 GCS_HOST="localhost" 22 GCS_PORT=21808 23 BUCKET="test" 24 25 # we need set public-host for download file, or it will return 404 when using client to read. 26 bin/fake-gcs-server -scheme http -host $GCS_HOST -port $GCS_PORT -backend memory -public-host $GCS_HOST:$GCS_PORT & 27 i=0 28 while ! curl -o /dev/null -v -s "http://$GCS_HOST:$GCS_PORT/"; do 29 i=$(($i+1)) 30 if [ $i -gt 7 ]; then 31 echo 'Failed to start gcs-server' 32 exit 1 33 fi 34 sleep 2 35 done 36 37 # start oauth server 38 bin/oauth & 39 40 stop_gcs() { 41 killall -9 fake-gcs-server || true 42 killall -9 oauth || true 43 } 44 trap stop_gcs EXIT 45 46 rm -rf "$TEST_DIR/$DB" 47 mkdir -p "$TEST_DIR/$DB" 48 49 # start gcs-server 50 # Fill in the database 51 for i in $(seq $DB_COUNT); do 52 run_sql "CREATE DATABASE $DB${i};" 53 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} 54 done 55 56 # we need start a oauth server or gcs client will failed to handle request. 57 KEY=$(cat <<- EOF 58 { 59 "type": "service_account", 60 "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCT524vzG7uEVtX\nojcHby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SPSYWi8YCEbEpljmK+4eye/JZmviDpRYk+qcMf1\n4lRr85gm9OO9YiK1sf0+ufH9Vr5IDflFgG1HqFwHsAWANYdd/n9Z8eior1ehAurB\nHUO8EJEBlaGIfA+Bi7pF0w3kWQsJm5USKHSeGbh3ma4vOD8+eWBZBSCirQKBgQCe\n1uEq/sChnXtIXpgXg4Uc6xJ1tZy6VUgUdDulsjZklTUU+KYQa7QC5kKoFCtqK+It\nseiqiDIVDUa9Y0liTQotYwLQAT8kxJEZpF54oZFmUqX3mcy/QvYB2JIcrBkx4I7/\ndT2yHKX1CBpMZ7h41FMCquzrdaO5NTd+Td2FYrGSBQKBgEBnAerHh/NafYlVumlS\nVgouR9IketTegyEyntVyEvENx8OA5ZLMywCIKbPMFZgPR0RgDpyDxKauCU2E09e/\nboN76UOuOg11fknJh7vFbUbzM6BXvXVOTyX9ZtZBQcd5Y3tV+tYD1tHUgurGYWb+\nyHLBMOlXdpn0gZ4rwoIQgzD9\n-----END PRIVATE KEY-----\n", 61 "client_email": "test@email.com", 62 "token_uri": "http://localhost:5000/oauth/token" 63 } 64 EOF 65 ) 66 67 # save CREDENTIALS to file 68 echo $KEY > "tests/$TEST_NAME/config.json" 69 70 # export test CREDENTIALS for gcs oauth 71 export GOOGLE_APPLICATION_CREDENTIALS="tests/$TEST_NAME/config.json" 72 73 # create gcs bucket 74 curl -XPOST http://$GCS_HOST:$GCS_PORT/storage/v1/b -d '{"name":"test"}' 75 76 for i in $(seq $DB_COUNT); do 77 row_count_ori[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') 78 done 79 80 # new version backup full 81 echo "backup start..." 82 run_br --pd $PD_ADDR backup full -s "gcs://$BUCKET/$DB?endpoint=http://$GCS_HOST:$GCS_PORT/storage/v1/" 83 84 # old version backup full v4.0.8 and disable check-requirements 85 echo "v4.0.8 backup start..." 86 bin/brv4.0.8 backup full \ 87 -L "debug" \ 88 --ca "$TEST_DIR/certs/ca.pem" \ 89 --cert "$TEST_DIR/certs/br.pem" \ 90 --key "$TEST_DIR/certs/br.key" \ 91 --pd $PD_ADDR -s "gcs://$BUCKET/${DB}_old?endpoint=http://$GCS_HOST:$GCS_PORT/storage/v1/" --check-requirements=false 92 93 # clean up 94 for i in $(seq $DB_COUNT); do 95 run_sql "DROP DATABASE $DB${i};" 96 done 97 98 # new version restore full 99 echo "restore start..." 100 run_br restore full -s "gcs://$BUCKET/$DB?" --pd $PD_ADDR --gcs.endpoint="http://$GCS_HOST:$GCS_PORT/storage/v1/" 101 102 for i in $(seq $DB_COUNT); do 103 row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') 104 done 105 106 fail=false 107 for i in $(seq $DB_COUNT); do 108 if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then 109 fail=true 110 echo "TEST: [$TEST_NAME] fail on database $DB${i}" 111 fi 112 echo "database $DB${i} [original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}" 113 done 114 115 if $fail; then 116 echo "TEST: [$TEST_NAME] failed!" 117 exit 1 118 else 119 echo "TEST: [$TEST_NAME] new version successd!" 120 fi 121 122 # clean up 123 for i in $(seq $DB_COUNT); do 124 run_sql "DROP DATABASE $DB${i};" 125 done 126 127 echo "v4.0.8 version restore start..." 128 run_br restore full -s "gcs://$BUCKET/${DB}_old" --pd $PD_ADDR --gcs.endpoint="http://$GCS_HOST:$GCS_PORT/storage/v1/" 129 130 for i in $(seq $DB_COUNT); do 131 row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') 132 done 133 134 fail=false 135 for i in $(seq $DB_COUNT); do 136 if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then 137 fail=true 138 echo "TEST: [$TEST_NAME] fail on database $DB${i}" 139 fi 140 echo "database $DB${i} [original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}" 141 done 142 143 if $fail; then 144 echo "TEST: [$TEST_NAME] failed!" 145 exit 1 146 fi