github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/bucket/replication/setup_ilm_expiry_replication.sh (about) 1 #!/usr/bin/env bash 2 3 set -x 4 5 trap 'catch $LINENO' ERR 6 7 # shellcheck disable=SC2120 8 catch() { 9 if [ $# -ne 0 ]; then 10 echo "error on line $1" 11 for site in sitea siteb sitec sited; do 12 echo "$site server logs =========" 13 cat "/tmp/${site}_1.log" 14 echo "===========================" 15 cat "/tmp/${site}_2.log" 16 done 17 fi 18 19 echo "Cleaning up instances of MinIO" 20 pkill minio 21 pkill -9 minio 22 rm -rf /tmp/multisitea 23 rm -rf /tmp/multisiteb 24 rm -rf /tmp/multisitec 25 rm -rf /tmp/multisited 26 rm -rf /tmp/data 27 } 28 29 catch 30 31 set -e 32 export MINIO_CI_CD=1 33 export MINIO_BROWSER=off 34 export MINIO_ROOT_USER="minio" 35 export MINIO_ROOT_PASSWORD="minio123" 36 export MINIO_KMS_AUTO_ENCRYPTION=off 37 export MINIO_PROMETHEUS_AUTH_TYPE=public 38 export MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= 39 unset MINIO_KMS_KES_CERT_FILE 40 unset MINIO_KMS_KES_KEY_FILE 41 unset MINIO_KMS_KES_ENDPOINT 42 unset MINIO_KMS_KES_KEY_NAME 43 44 if [ ! -f ./mc ]; then 45 wget --quiet -O mc https://dl.minio.io/client/mc/release/linux-amd64/mc && 46 chmod +x mc 47 fi 48 49 minio server --address 127.0.0.1:9001 "http://127.0.0.1:9001/tmp/multisitea/data/disterasure/xl{1...4}" \ 50 "http://127.0.0.1:9002/tmp/multisitea/data/disterasure/xl{5...8}" >/tmp/sitea_1.log 2>&1 & 51 minio server --address 127.0.0.1:9002 "http://127.0.0.1:9001/tmp/multisitea/data/disterasure/xl{1...4}" \ 52 "http://127.0.0.1:9002/tmp/multisitea/data/disterasure/xl{5...8}" >/tmp/sitea_2.log 2>&1 & 53 54 minio server --address 127.0.0.1:9003 "http://127.0.0.1:9003/tmp/multisiteb/data/disterasure/xl{1...4}" \ 55 "http://127.0.0.1:9004/tmp/multisiteb/data/disterasure/xl{5...8}" >/tmp/siteb_1.log 2>&1 & 56 minio server --address 127.0.0.1:9004 "http://127.0.0.1:9003/tmp/multisiteb/data/disterasure/xl{1...4}" \ 57 "http://127.0.0.1:9004/tmp/multisiteb/data/disterasure/xl{5...8}" >/tmp/siteb_2.log 2>&1 & 58 59 minio server --address 127.0.0.1:9005 "http://127.0.0.1:9005/tmp/multisitec/data/disterasure/xl{1...4}" \ 60 "http://127.0.0.1:9006/tmp/multisitec/data/disterasure/xl{5...8}" >/tmp/sitec_1.log 2>&1 & 61 minio server --address 127.0.0.1:9006 "http://127.0.0.1:9005/tmp/multisitec/data/disterasure/xl{1...4}" \ 62 "http://127.0.0.1:9006/tmp/multisitec/data/disterasure/xl{5...8}" >/tmp/sitec_2.log 2>&1 & 63 64 minio server --address 127.0.0.1:9007 "http://127.0.0.1:9007/tmp/multisited/data/disterasure/xl{1...4}" \ 65 "http://127.0.0.1:9008/tmp/multisited/data/disterasure/xl{5...8}" >/tmp/sited_1.log 2>&1 & 66 minio server --address 127.0.0.1:9008 "http://127.0.0.1:9007/tmp/multisited/data/disterasure/xl{1...4}" \ 67 "http://127.0.0.1:9008/tmp/multisited/data/disterasure/xl{5...8}" >/tmp/sited_2.log 2>&1 & 68 69 # Wait to make sure all MinIO instances are up 70 sleep 20s 71 72 export MC_HOST_sitea=http://minio:minio123@127.0.0.1:9001 73 export MC_HOST_siteb=http://minio:minio123@127.0.0.1:9004 74 export MC_HOST_sitec=http://minio:minio123@127.0.0.1:9006 75 export MC_HOST_sited=http://minio:minio123@127.0.0.1:9008 76 77 ./mc mb sitea/bucket 78 ./mc mb sitec/bucket 79 80 ## Setup site replication 81 ./mc admin replicate add sitea siteb --replicate-ilm-expiry 82 83 ## Add warm tier 84 ./mc ilm tier add minio sitea WARM-TIER --endpoint http://localhost:9006 --access-key minio --secret-key minio123 --bucket bucket 85 86 ## Add ILM rules 87 ./mc ilm add sitea/bucket --transition-days 0 --transition-tier WARM-TIER --transition-days 0 --noncurrent-expire-days 2 --expire-days 3 --prefix "myprefix" --tags "tag1=val1&tag2=val2" 88 ./mc ilm rule list sitea/bucket 89 90 ## Check ilm expiry flag 91 ./mc admin replicate info sitea --json 92 flag1=$(./mc admin replicate info sitea --json | jq '.sites[0]."replicate-ilm-expiry"') 93 flag2=$(./mc admin replicate info sitea --json | jq '.sites[1]."replicate-ilm-expiry"') 94 if [ "$flag1" != "true" ]; then 95 echo "BUG: Expected ILM expiry replication not set for 'sitea'" 96 exit 1 97 fi 98 if [ "$flag2" != "true" ]; then 99 echo "BUG: Expected ILM expiry replication not set for 'siteb'" 100 exit 1 101 fi 102 103 ## Check if ILM expiry rules replicated 104 sleep 20 105 ./mc ilm rule list siteb/bucket 106 count=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules | length') 107 if [ $count -ne 1 ]; then 108 echo "BUG: ILM expiry rules not replicated to 'siteb'" 109 exit 1 110 fi 111 112 ## Check replication of rules content 113 expDays=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Expiration.Days') 114 noncurrentDays=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].NoncurrentVersionExpiration.NoncurrentDays') 115 if [ $expDays -ne 3 ]; then 116 echo "BUG: Incorrect expiry days '${expDays}' set for 'siteb'" 117 exit 1 118 fi 119 if [ $noncurrentDays -ne 2 ]; then 120 echo "BUG: Incorrect non current expiry days '${noncurrentDays}' set for siteb" 121 exit 1 122 fi 123 124 ## Make sure transition rule not replicated to siteb 125 tranDays=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Transition.Days') 126 if [ "${tranDays}" != "null" ]; then 127 echo "BUG: Transition rules as well copied to siteb" 128 exit 1 129 fi 130 131 ## Check replication of rules prefix and tags 132 prefix=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Prefix' | sed 's/"//g') 133 tagName1=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[0].Key' | sed 's/"//g') 134 tagVal1=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[0].Value' | sed 's/"//g') 135 tagName2=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[1].Key' | sed 's/"//g') 136 tagVal2=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[1].Value' | sed 's/"//g') 137 if [ "${prefix}" != "myprefix" ]; then 138 echo "BUG: ILM expiry rules prefix not replicated to 'siteb'" 139 exit 1 140 fi 141 if [ "${tagName1}" != "tag1" ] || [ "${tagVal1}" != "val1" ] || [ "${tagName2}" != "tag2" ] || [ "${tagVal2}" != "val2" ]; then 142 echo "BUG: ILM expiry rules tags not replicated to 'siteb'" 143 exit 1 144 fi 145 146 ## Check edit of ILM expiry rule and its replication 147 id=$(./mc ilm rule list sitea/bucket --json | jq '.config.Rules[] | select(.Expiration.Days==3) | .ID' | sed 's/"//g') 148 ./mc ilm edit --id "${id}" --expire-days "100" sitea/bucket 149 sleep 30 150 count1=$(./mc ilm rule list sitea/bucket --json | jq '.config.Rules[0].Expiration.Days') 151 count2=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Expiration.Days') 152 if [ $count1 -ne 100 ]; then 153 echo "BUG: Expiration days not changed on 'sitea'" 154 exit 1 155 fi 156 if [ $count2 -ne 100 ]; then 157 echo "BUG: Modified ILM expiry rule not replicated to 'siteb'" 158 exit 1 159 fi 160 161 ## Check disabling of ILM expiry rules replication 162 ./mc admin replicate update sitea --disable-ilm-expiry-replication 163 flag=$(./mc admin replicate info sitea --json | jq '.sites[] | select (.name=="sitea") | ."replicate-ilm-expiry"') 164 if [ "$flag" != "false" ]; then 165 echo "BUG: ILM expiry replication not disabled for 'sitea'" 166 exit 1 167 fi 168 flag=$(./mc admin replicate info siteb --json | jq '.sites[] | select (.name=="sitea") | ."replicate-ilm-expiry"') 169 if [ "$flag" != "false" ]; then 170 echo "BUG: ILM expiry replication not disabled for 'siteb'" 171 exit 1 172 fi 173 174 ## Perform individual updates of rules to sites 175 ./mc ilm edit --id "${id}" --expire-days "999" sitea/bucket 176 sleep 1 177 ./mc ilm edit --id "${id}" --expire-days "888" siteb/bucket # when ilm expiry re-enabled, this should win 178 179 ## Check re-enabling of ILM expiry rules replication 180 ./mc admin replicate update sitea --enable-ilm-expiry-replication 181 flag=$(./mc admin replicate info sitea --json | jq '.sites[] | select (.name=="sitea") | ."replicate-ilm-expiry"') 182 if [ "$flag" != "true" ]; then 183 echo "BUG: ILM expiry replication not enabled for 'sitea'" 184 exit 1 185 fi 186 flag=$(./mc admin replicate info siteb --json | jq '.sites[] | select (.name=="sitea") | ."replicate-ilm-expiry"') 187 if [ "$flag" != "true" ]; then 188 echo "BUG: ILM expiry replication not enabled for 'siteb'" 189 exit 1 190 fi 191 192 ## Check if latest updated rules get replicated to all sites post re-enable of ILM expiry rules replication 193 sleep 30 194 count1=$(./mc ilm rule list sitea/bucket --json | jq '.config.Rules[0].Expiration.Days') 195 count2=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Expiration.Days') 196 if [ $count1 -ne 888 ]; then 197 echo "BUG: Latest expiration days not updated on 'sitea'" 198 exit 1 199 fi 200 if [ $count2 -ne 888 ]; then 201 echo "BUG: Latest expiration days not updated on 'siteb'" 202 exit 1 203 fi 204 205 ## Check to make sure sitea transition rule is not overwritten 206 transDays=$(./mc ilm rule list sitea/bucket --json | jq '.config.Rules[0].Transition.Days') 207 if [ $transDays -ne 0 ] || [ "${transDays}" == "null" ]; then 208 echo "BUG: Transition rule on sitea seems to be overwritten" 209 exit 1 210 fi 211 212 ## Check replication of edit of prefix, tags and status of ILM Expiry Rules 213 ./mc ilm rule edit --id "${id}" --prefix "newprefix" --tags "ntag1=nval1&ntag2=nval2" --disable sitea/bucket 214 sleep 30 215 nprefix=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Prefix' | sed 's/"//g') 216 ntagName1=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[0].Key' | sed 's/"//g') 217 ntagVal1=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[0].Value' | sed 's/"//g') 218 ntagName2=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[1].Key' | sed 's/"//g') 219 ntagVal2=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Filter.And.Tags[1].Value' | sed 's/"//g') 220 st=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[0].Status' | sed 's/"//g') 221 if [ "${nprefix}" != "newprefix" ]; then 222 echo "BUG: ILM expiry rules prefix not replicated to 'siteb'" 223 exit 1 224 fi 225 if [ "${ntagName1}" != "ntag1" ] || [ "${ntagVal1}" != "nval1" ] || [ "${ntagName2}" != "ntag2" ] || [ "${ntagVal2}" != "nval2" ]; then 226 echo "BUG: ILM expiry rules tags not replicated to 'siteb'" 227 exit 1 228 fi 229 if [ "${st}" != "Disabled" ]; then 230 echo "BUG: ILM expiry rules status not replicated to 'siteb'" 231 exit 1 232 fi 233 234 ## Check replication of deleted ILM expiry rules 235 ./mc ilm rule remove --id "${id}" sitea/bucket 236 sleep 30 237 # should error as rule doesn't exist 238 error=$(./mc ilm rule list siteb/bucket --json | jq '.error.cause.message' | sed 's/"//g') 239 if [ "$error" != "The lifecycle configuration does not exist" ]; then 240 echo "BUG: Removed ILM expiry rule not replicated to 'siteb'" 241 exit 1 242 fi 243 244 ## Check addition of new replication site to existing site replication setup 245 # Add rules again as previous tests removed all 246 ./mc ilm add sitea/bucket --transition-days 0 --transition-tier WARM-TIER --transition-days 0 --noncurrent-expire-days 2 --expire-days 3 --prefix "myprefix" --tags "tag1=val1&tag2=val2" 247 ./mc admin replicate add sitea siteb sited 248 sleep 30 249 # Check site replication info and status for new site 250 sitesCount=$(mc admin replicate info sited --json | jq '.sites | length') 251 if [ ${sitesCount} -ne 3 ]; then 252 echo "BUG: New site 'sited' not appearing in site replication info" 253 exit 1 254 fi 255 flag3=$(./mc admin replicate info sited --json | jq '.sites[2]."replicate-ilm-expiry"') 256 if [ "${flag3}" != "true" ]; then 257 echo "BUG: ILM expiry replication not enabled for 'sited'" 258 exit 1 259 fi 260 rulesCount=$(./mc ilm rule list sited/bucket --json | jq '.config.Rules | length') 261 if [ ${rulesCount} -ne 1 ]; then 262 echo "BUG: ILM expiry rules not replicated to 'sited'" 263 exit 1 264 fi 265 prefix=$(./mc ilm rule list sited/bucket --json | jq '.config.Rules[0].Filter.And.Prefix' | sed 's/"//g') 266 tagName1=$(./mc ilm rule list sited/bucket --json | jq '.config.Rules[0].Filter.And.Tags[0].Key' | sed 's/"//g') 267 tagVal1=$(./mc ilm rule list sited/bucket --json | jq '.config.Rules[0].Filter.And.Tags[0].Value' | sed 's/"//g') 268 tagName2=$(./mc ilm rule list sited/bucket --json | jq '.config.Rules[0].Filter.And.Tags[1].Key' | sed 's/"//g') 269 tagVal2=$(./mc ilm rule list sited/bucket --json | jq '.config.Rules[0].Filter.And.Tags[1].Value' | sed 's/"//g') 270 if [ "${prefix}" != "myprefix" ]; then 271 echo "BUG: ILM expiry rules prefix not replicated to 'sited'" 272 exit 1 273 fi 274 if [ "${tagName1}" != "tag1" ] || [ "${tagVal1}" != "val1" ] || [ "${tagName2}" != "tag2" ] || [ "${tagVal2}" != "val2" ]; then 275 echo "BUG: ILM expiry rules tags not replicated to 'sited'" 276 exit 1 277 fi 278 279 ## Check replication of deleted ILM expiry rules when target has transition part as well 280 ## Only the expiry part of rules should get removed as part if replication of removal from 281 ## other site 282 id=$(./mc ilm rule list siteb/bucket --json | jq '.config.Rules[] | select(.Expiration.Days==3) | .ID' | sed 's/"//g') 283 # Remove rule from siteb 284 ./mc ilm rule remove --id "${id}" siteb/bucket 285 sleep 30 # allow to replicate 286 # sitea should still contain the transition portion of rule 287 transitionRuleDays=$(./mc ilm rule list sitea/bucket --json | jq '.config.Rules[0].Transition.Days') 288 expirationRuleDet=$(./mc ilm rule list sitea/bucket --json | jq '.config.Rules[0].Expiration') 289 if [ ${transitionRuleDays} -ne 0 ]; then 290 echo "BUG: Transition rules not retained as part of replication of deleted ILM expiry rules on 'sitea'" 291 exit 1 292 fi 293 if [ ${expirationRuleDet} != null ]; then 294 echo "BUG: removed ILM expiry rule not replicated to 'sitea'" 295 exit 1 296 fi 297 298 catch