github.com/percona/percona-xtradb-cluster-operator@v1.14.0/e2e-tests/pitr/run (about) 1 #!/bin/bash 2 3 set -o errexit 4 5 test_dir=$(realpath $(dirname $0)) 6 . ${test_dir}/../functions 7 8 set_debug 9 10 GTID_PATTERN='[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}:[0-9]+' 11 12 if [[ $IMAGE_PXC =~ 5\.7 ]]; then 13 echo "Skipping PITR test because 5.7 doesn't support it!" 14 exit 0 15 fi 16 17 write_test_data() { 18 local cluster=$1 19 local config=$2 20 local size="${3:-3}" 21 local sleep="${4:-10}" 22 local secretsFile="${5:-$conf_dir/secrets.yml}" 23 local pxcClientFile="${6:-$conf_dir/client.yml}" 24 25 local proxy=$(get_proxy "$cluster") 26 27 desc 'write test data' 28 if [[ $IMAGE_PXC =~ 5\.7 ]] && [[ "$(is_keyring_plugin_in_use "$cluster")" ]]; then 29 encrypt='ENCRYPTION=\"Y\"' 30 fi 31 run_mysql \ 32 "CREATE DATABASE IF NOT EXISTS test; use test; CREATE TABLE IF NOT EXISTS test (id int PRIMARY KEY) $encrypt;" \ 33 "-h $proxy -uroot -proot_password" 34 run_mysql \ 35 'INSERT test.test (id) VALUES (100500); INSERT test.test (id) VALUES (100501); INSERT test.test (id) VALUES (100502);' \ 36 "-h $proxy -uroot -proot_password" 37 sleep 30 38 for i in $(seq 0 $((size - 1))); do 39 compare_mysql_cmd "select-3" "SELECT * from test.test;" "-h $cluster-pxc-$i.$cluster-pxc -uroot -proot_password" 40 done 41 42 if [ "$(is_keyring_plugin_in_use "$cluster")" ]; then 43 table_must_be_encrypted "$cluster" "test" 44 fi 45 } 46 47 write_data_for_pitr() { 48 local cluster=$1 49 local proxy=$(get_proxy "$cluster") 50 51 desc "write data for pitr" 52 run_mysql \ 53 'INSERT test.test (id) VALUES (100503); INSERT test.test (id) VALUES (100504); INSERT test.test (id) VALUES (100505);' \ 54 "-h $proxy -uroot -proot_password" 55 } 56 57 check_latest_restorable_time() { 58 local backup=$1 59 60 desc 'check latest restorable time' 61 latest_restorable_time=$(kubectl_bin get pxc-backup ${backup} -o jsonpath='{.status.latestRestorableTime}') 62 if [[ ${latest_restorable_time} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}T ]]; then 63 echo "Latest restorable time is ${latest_restorable_time}" 64 else 65 echo "Latest restorable time is not set" 66 exit 1 67 fi 68 } 69 70 main() { 71 create_infra $namespace 72 deploy_cert_manager 73 kubectl_bin apply -f "$test_dir/conf/issuer.yml" 74 kubectl_bin apply -f "$test_dir/conf/cert.yml" 75 sleep 25 76 # We are using minio with tls enabled to check if `verifyTLS: false` works fine 77 start_minio "tls-minio" 78 79 cluster="pitr" 80 spinup_pxc "$cluster" "$test_dir/conf/$cluster.yml" 81 82 run_backup "$cluster" "on-pitr-minio" 83 84 desc 'check for passwords leak' 85 check_passwords_leak 86 87 write_test_data "$cluster" 88 89 # test changing xtrabackup password 90 desc "changing xtrabackup password multiple times" 91 patch_secret "my-cluster-secrets" "xtrabackup" "$(echo -n "pass1" | base64)" 92 wait_cluster_consistency ${cluster} 3 2 93 patch_secret "my-cluster-secrets" "xtrabackup" "$(echo -n "pass2" | base64)" 94 wait_cluster_consistency ${cluster} 3 2 95 patch_secret "my-cluster-secrets" "xtrabackup" "$(echo -n "pass3" | base64)" 96 wait_cluster_consistency ${cluster} 3 2 97 98 compare_kubectl secret/${cluster}-mysql-init 99 100 desc 'show binlog events' 101 proxy=$(get_proxy "$cluster") 102 run_mysql "SHOW BINLOG EVENTS IN 'binlog.000005';" "-h ${proxy} -uroot -proot_password" 103 run_mysql "SHOW BINLOG EVENTS IN 'binlog.000006';" "-h ${proxy} -uroot -proot_password" 104 105 time_now=$(run_mysql "SELECT now();" "-h ${proxy} -uroot -proot_password") 106 gtid=$(run_mysql "SELECT @@gtid_executed;" "-h ${proxy} -uroot -proot_password" | $sed 's/\([a-f0-9-]\{36\}\):[0-9]*-\([0-9]*\).*/\1:\2/') 107 108 if [[ ! ${gtid} =~ ${GTID_PATTERN} ]]; then 109 printf "Some garbage --> %s <-- instead of legit GTID. Exiting" ${gtid} 110 exit 1 111 fi 112 113 write_data_for_pitr "$cluster" 114 sleep 120 # need to wait while collector catch new data 115 check_latest_restorable_time "on-pitr-minio" 116 117 timeout=60 118 binlogs_exist=0 119 for i in $(seq 2 3); do 120 binlogs_exist=$( 121 kubectl_bin run -n "${NAMESPACE}" -i --rm aws-cli --image=perconalab/awscli --restart=Never -- \ 122 /usr/bin/env AWS_ACCESS_KEY_ID=some-access-key AWS_SECRET_ACCESS_KEY=some-secret-key AWS_DEFAULT_REGION=us-east-1 \ 123 /usr/bin/aws --endpoint-url https://minio-service:9000 --no-verify-ssl s3 ls operator-testing/binlogs/ | grep -c "binlog" | cat 124 exit "${PIPESTATUS[0]}" 125 ) 126 if [ "$binlogs_exist" -eq 0 ]; then 127 sleep "$((timeout * i))" 128 fi 129 done 130 131 if [ "$binlogs_exist" -eq 0 ]; then 132 echo "Binlogs are not found in S3" 133 exit 1 134 fi 135 136 run_recovery_check_pitr "$cluster" "restore-on-pitr-minio-gtid" "on-pitr-minio" "select-2" "" "" "$gtid" 137 desc "done gtid type" 138 139 desc 'check for passwords leak' 140 check_passwords_leak 141 142 sleep 60 143 if [[ $(kubectl get pxc-backup on-pitr-minio -o jsonpath='{.status.conditions}' | grep -c 'Binlog with GTID set') -eq 1 ]]; then 144 echo "Binlog gap detected" 145 exit 1 146 fi 147 148 run_recovery_check_pitr "$cluster" "restore-on-pitr-minio-time" "on-pitr-minio" "select-3" "$time_now" "" "" 149 desc "done date type" 150 sleep 60 151 if [[ $(kubectl get pxc-backup on-pitr-minio -o jsonpath='{.status.conditions}' | grep -c 'Binlog with GTID set') -eq 1 ]]; then 152 echo "Binlog gap detected" 153 exit 1 154 fi 155 156 dest=$(sed 's,/,\\/,g' <<<$(kubectl get pxc-backup on-pitr-minio -o jsonpath='{.status.destination}')) 157 run_recovery_check_pitr "$cluster" "restore-on-pitr-minio" "on-pitr-minio" "select-4" "" "$dest" "" 158 desc "done latest type" 159 sleep 60 160 if [[ $(kubectl get pxc-backup on-pitr-minio -o jsonpath='{.status.conditions}' | grep -c 'Binlog with GTID set') -eq 1 ]]; then 161 echo "Binlog gap detected" 162 exit 1 163 fi 164 165 destroy $namespace 166 desc "test passed" 167 } 168 169 main