github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/site-replication/run-ssec-object-replication.sh (about) 1 #!/usr/bin/env bash 2 3 # shellcheck disable=SC2120 4 exit_1() { 5 cleanup 6 7 echo "minio1 ============" 8 cat /tmp/minio1_1.log 9 echo "minio2 ============" 10 cat /tmp/minio2_1.log 11 12 exit 1 13 } 14 15 cleanup() { 16 echo -n "Cleaning up instances of MinIO ..." 17 pkill minio || sudo pkill minio 18 pkill -9 minio || sudo pkill -9 minio 19 rm -rf /tmp/minio{1,2} 20 echo "done" 21 } 22 23 cleanup 24 25 export MINIO_CI_CD=1 26 export MINIO_BROWSER=off 27 export MINIO_ROOT_USER="minio" 28 export MINIO_ROOT_PASSWORD="minio123" 29 30 # Create certificates for TLS enabled MinIO 31 echo -n "Setup certs for MinIO instances ..." 32 wget -O certgen https://github.com/minio/certgen/releases/latest/download/certgen-linux-amd64 && chmod +x certgen 33 ./certgen --host localhost 34 mkdir -p ~/.minio/certs 35 mv public.crt ~/.minio/certs || sudo mv public.crt ~/.minio/certs 36 mv private.key ~/.minio/certs || sudo mv private.key ~/.minio/certs 37 echo "done" 38 39 # Start MinIO instances 40 echo -n "Starting MinIO instances ..." 41 minio server --address ":9001" --console-address ":10000" /tmp/minio1/{1...4}/disk{1...4} /tmp/minio1/{5...8}/disk{1...4} >/tmp/minio1_1.log 2>&1 & 42 minio server --address ":9002" --console-address ":11000" /tmp/minio2/{1...4}/disk{1...4} /tmp/minio2/{5...8}/disk{1...4} >/tmp/minio2_1.log 2>&1 & 43 echo "done" 44 45 if [ ! -f ./mc ]; then 46 echo -n "Downloading MinIO client ..." 47 wget -O mc https://dl.min.io/client/mc/release/linux-amd64/mc && 48 chmod +x mc 49 echo "done" 50 fi 51 52 sleep 10 53 54 export MC_HOST_minio1=https://minio:minio123@localhost:9001 55 export MC_HOST_minio2=https://minio:minio123@localhost:9002 56 57 # Prepare data for tests 58 echo -n "Preparing test data ..." 59 mkdir -p /tmp/data 60 echo "Hello world" >/tmp/data/plainfile 61 echo "Hello from encrypted world" >/tmp/data/encrypted 62 touch /tmp/data/defpartsize 63 shred -s 500M /tmp/data/defpartsize 64 touch /tmp/data/custpartsize 65 shred -s 500M /tmp/data/custpartsize 66 echo "done" 67 68 # Add replication site 69 ./mc admin replicate add minio1 minio2 --insecure 70 # sleep for replication to complete 71 sleep 30 72 73 # Create bucket in source cluster 74 echo "Create bucket in source MinIO instance" 75 ./mc mb minio1/test-bucket --insecure 76 77 # Load objects to source site 78 echo "Loading objects to source MinIO instance" 79 ./mc cp /tmp/data/plainfile minio1/test-bucket --insecure 80 ./mc cp /tmp/data/encrypted minio1/test-bucket --encrypt-key "minio1/test-bucket/encrypted=iliketobecrazybutnotsomuchreally" --insecure 81 ./mc cp /tmp/data/defpartsize minio1/test-bucket --encrypt-key "minio1/test-bucket/defpartsize=iliketobecrazybutnotsomuchreally" --insecure 82 ./mc put /tmp/data/custpartsize minio1/test-bucket --encrypt-key "minio1/test-bucket/custpartsize=iliketobecrazybutnotsomuchreally" --insecure --part-size 50MiB 83 sleep 120 84 85 # List the objects from source site 86 echo "Objects from source instance" 87 ./mc ls minio1/test-bucket --insecure 88 count1=$(./mc ls minio1/test-bucket/plainfile --insecure | wc -l) 89 if [ "${count1}" -ne 1 ]; then 90 echo "BUG: object minio1/test-bucket/plainfile not found" 91 exit_1 92 fi 93 count2=$(./mc ls minio1/test-bucket/encrypted --insecure | wc -l) 94 if [ "${count2}" -ne 1 ]; then 95 echo "BUG: object minio1/test-bucket/encrypted not found" 96 exit_1 97 fi 98 count3=$(./mc ls minio1/test-bucket/defpartsize --insecure | wc -l) 99 if [ "${count3}" -ne 1 ]; then 100 echo "BUG: object minio1/test-bucket/defpartsize not found" 101 exit_1 102 fi 103 count4=$(./mc ls minio1/test-bucket/custpartsize --insecure | wc -l) 104 if [ "${count4}" -ne 1 ]; then 105 echo "BUG: object minio1/test-bucket/custpartsize not found" 106 exit_1 107 fi 108 109 # List the objects from replicated site 110 echo "Objects from replicated instance" 111 ./mc ls minio2/test-bucket --insecure 112 repcount1=$(./mc ls minio2/test-bucket/plainfile --insecure | wc -l) 113 if [ "${repcount1}" -ne 1 ]; then 114 echo "BUG: object test-bucket/plainfile not replicated" 115 exit_1 116 fi 117 repcount2=$(./mc ls minio2/test-bucket/encrypted --insecure | wc -l) 118 if [ "${repcount2}" -ne 1 ]; then 119 echo "BUG: object test-bucket/encrypted not replicated" 120 exit_1 121 fi 122 repcount3=$(./mc ls minio2/test-bucket/defpartsize --insecure | wc -l) 123 if [ "${repcount3}" -ne 1 ]; then 124 echo "BUG: object test-bucket/defpartsize not replicated" 125 exit_1 126 fi 127 128 repcount4=$(./mc ls minio2/test-bucket/custpartsize --insecure | wc -l) 129 if [ "${repcount4}" -ne 1 ]; then 130 echo "BUG: object test-bucket/custpartsize not replicated" 131 exit_1 132 fi 133 134 # Stat the SSEC objects from source site 135 echo "Stat minio1/test-bucket/encrypted" 136 ./mc stat minio1/test-bucket/encrypted --encrypt-key "minio1/test-bucket/encrypted=iliketobecrazybutnotsomuchreally" --insecure --json 137 stat_out1=$(./mc stat minio1/test-bucket/encrypted --encrypt-key "minio1/test-bucket/encrypted=iliketobecrazybutnotsomuchreally" --insecure --json) 138 src_obj1_etag=$(echo "${stat_out1}" | jq '.etag') 139 src_obj1_size=$(echo "${stat_out1}" | jq '.size') 140 src_obj1_md5=$(echo "${stat_out1}" | jq '.metadata."X-Amz-Server-Side-Encryption-Customer-Key-Md5"') 141 echo "Stat minio1/test-bucket/defpartsize" 142 ./mc stat minio1/test-bucket/defpartsize --encrypt-key "minio1/test-bucket/defpartsize=iliketobecrazybutnotsomuchreally" --insecure --json 143 stat_out2=$(./mc stat minio1/test-bucket/defpartsize --encrypt-key "minio1/test-bucket/defpartsize=iliketobecrazybutnotsomuchreally" --insecure --json) 144 src_obj2_etag=$(echo "${stat_out2}" | jq '.etag') 145 src_obj2_size=$(echo "${stat_out2}" | jq '.size') 146 src_obj2_md5=$(echo "${stat_out2}" | jq '.metadata."X-Amz-Server-Side-Encryption-Customer-Key-Md5"') 147 echo "Stat minio1/test-bucket/custpartsize" 148 ./mc stat minio1/test-bucket/custpartsize --encrypt-key "minio1/test-bucket/custpartsize=iliketobecrazybutnotsomuchreally" --insecure --json 149 stat_out3=$(./mc stat minio1/test-bucket/custpartsize --encrypt-key "minio1/test-bucket/custpartsize=iliketobecrazybutnotsomuchreally" --insecure --json) 150 src_obj3_etag=$(echo "${stat_out3}" | jq '.etag') 151 src_obj3_size=$(echo "${stat_out3}" | jq '.size') 152 src_obj3_md5=$(echo "${stat_out3}" | jq '.metadata."X-Amz-Server-Side-Encryption-Customer-Key-Md5"') 153 154 # Stat the SSEC objects from replicated site 155 echo "Stat minio2/test-bucket/encrypted" 156 ./mc stat minio2/test-bucket/encrypted --encrypt-key "minio2/test-bucket/encrypted=iliketobecrazybutnotsomuchreally" --insecure --json 157 stat_out1_rep=$(./mc stat minio2/test-bucket/encrypted --encrypt-key "minio2/test-bucket/encrypted=iliketobecrazybutnotsomuchreally" --insecure --json) 158 rep_obj1_etag=$(echo "${stat_out1_rep}" | jq '.etag') 159 rep_obj1_size=$(echo "${stat_out1_rep}" | jq '.size') 160 rep_obj1_md5=$(echo "${stat_out1_rep}" | jq '.metadata."X-Amz-Server-Side-Encryption-Customer-Key-Md5"') 161 echo "Stat minio2/test-bucket/defpartsize" 162 ./mc stat minio2/test-bucket/defpartsize --encrypt-key "minio2/test-bucket/defpartsize=iliketobecrazybutnotsomuchreally" --insecure --json 163 stat_out2_rep=$(./mc stat minio2/test-bucket/defpartsize --encrypt-key "minio2/test-bucket/defpartsize=iliketobecrazybutnotsomuchreally" --insecure --json) 164 rep_obj2_etag=$(echo "${stat_out2_rep}" | jq '.etag') 165 rep_obj2_size=$(echo "${stat_out2_rep}" | jq '.size') 166 rep_obj2_md5=$(echo "${stat_out2_rep}" | jq '.metadata."X-Amz-Server-Side-Encryption-Customer-Key-Md5"') 167 echo "Stat minio2/test-bucket/custpartsize" 168 ./mc stat minio2/test-bucket/custpartsize --encrypt-key "minio2/test-bucket/custpartsize=iliketobecrazybutnotsomuchreally" --insecure --json 169 stat_out3_rep=$(./mc stat minio2/test-bucket/custpartsize --encrypt-key "minio2/test-bucket/custpartsize=iliketobecrazybutnotsomuchreally" --insecure --json) 170 rep_obj3_etag=$(echo "${stat_out3_rep}" | jq '.etag') 171 rep_obj3_size=$(echo "${stat_out3_rep}" | jq '.size') 172 rep_obj3_md5=$(echo "${stat_out3_rep}" | jq '.metadata."X-Amz-Server-Side-Encryption-Customer-Key-Md5"') 173 174 # Check the etag and size of replicated SSEC objects 175 if [ "${rep_obj1_etag}" != "${src_obj1_etag}" ]; then 176 echo "BUG: Etag: '${rep_obj1_etag}' of replicated object: 'minio2/test-bucket/encrypted' doesn't match with source value: '${src_obj1_etag}'" 177 exit_1 178 fi 179 if [ "${rep_obj1_size}" != "${src_obj1_size}" ]; then 180 echo "BUG: Size: '${rep_obj1_size}' of replicated object: 'minio2/test-bucket/encrypted' doesn't match with source value: '${src_obj1_size}'" 181 exit_1 182 fi 183 if [ "${rep_obj2_etag}" != "${src_obj2_etag}" ]; then 184 echo "BUG: Etag: '${rep_obj2_etag}' of replicated object: 'minio2/test-bucket/defpartsize' doesn't match with source value: '${src_obj2_etag}'" 185 exit_1 186 fi 187 if [ "${rep_obj2_size}" != "${src_obj2_size}" ]; then 188 echo "BUG: Size: '${rep_obj2_size}' of replicated object: 'minio2/test-bucket/defpartsize' doesn't match with source value: '${src_obj2_size}'" 189 exit_1 190 fi 191 if [ "${rep_obj3_etag}" != "${src_obj3_etag}" ]; then 192 echo "BUG: Etag: '${rep_obj3_etag}' of replicated object: 'minio2/test-bucket/custpartsize' doesn't match with source value: '${src_obj3_etag}'" 193 exit_1 194 fi 195 if [ "${rep_obj3_size}" != "${src_obj3_size}" ]; then 196 echo "BUG: Size: '${rep_obj3_size}' of replicated object: 'minio2/test-bucket/custpartsize' doesn't match with source value: '${src_obj3_size}'" 197 exit_1 198 fi 199 200 # Check content of replicated SSEC objects 201 ./mc cat minio2/test-bucket/encrypted --encrypt-key "minio2/test-bucket/encrypted=iliketobecrazybutnotsomuchreally" --insecure 202 ./mc cat minio2/test-bucket/defpartsize --encrypt-key "minio2/test-bucket/defpartsize=iliketobecrazybutnotsomuchreally" --insecure >/dev/null || exit_1 203 ./mc cat minio2/test-bucket/custpartsize --encrypt-key "minio2/test-bucket/custpartsize=iliketobecrazybutnotsomuchreally" --insecure >/dev/null || exit_1 204 205 # Check the MD5 checksums of encrypted objects from source and target 206 if [ "${src_obj1_md5}" != "${rep_obj1_md5}" ]; then 207 echo "BUG: MD5 checksum of object 'minio2/test-bucket/encrypted' doesn't match with source. Expected: '${src_obj1_md5}', Found: '${rep_obj1_md5}'" 208 exit_1 209 fi 210 if [ "${src_obj2_md5}" != "${rep_obj2_md5}" ]; then 211 echo "BUG: MD5 checksum of object 'minio2/test-bucket/defpartsize' doesn't match with source. Expected: '${src_obj2_md5}', Found: '${rep_obj2_md5}'" 212 exit_1 213 fi 214 if [ "${src_obj3_md5}" != "${rep_obj3_md5}" ]; then 215 echo "BUG: MD5 checksum of object 'minio2/test-bucket/custpartsize' doesn't match with source. Expected: '${src_obj3_md5}', Found: '${rep_obj3_md5}'" 216 exit_1 217 fi 218 219 cleanup