github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/buildscripts/heal-inconsistent-versions.sh (about) 1 #!/bin/bash -e 2 3 set -E 4 set -o pipefail 5 set -x 6 7 WORK_DIR="$PWD/.verify-$RANDOM" 8 MINIO_CONFIG_DIR="$WORK_DIR/.minio" 9 MINIO=("$PWD/minio" --config-dir "$MINIO_CONFIG_DIR" server) 10 11 if [ ! -x "$PWD/minio" ]; then 12 echo "minio executable binary not found in current directory" 13 exit 1 14 fi 15 16 if [ ! -x "$PWD/minio" ]; then 17 echo "minio executable binary not found in current directory" 18 exit 1 19 fi 20 21 function start_minio_4drive() { 22 start_port=$1 23 24 export MINIO_ROOT_USER=minio 25 export MINIO_ROOT_PASSWORD=minio123 26 export MC_HOST_minio="http://minio:minio123@127.0.0.1:${start_port}/" 27 unset MINIO_KMS_AUTO_ENCRYPTION # do not auto-encrypt objects 28 export MINIO_CI_CD=1 29 30 mkdir ${WORK_DIR} 31 C_PWD=${PWD} 32 if [ ! -x "$PWD/mc" ]; then 33 MC_BUILD_DIR="mc-$RANDOM" 34 if ! git clone --quiet https://github.com/minio/mc "$MC_BUILD_DIR"; then 35 echo "failed to download https://github.com/minio/mc" 36 purge "${MC_BUILD_DIR}" 37 exit 1 38 fi 39 40 (cd "${MC_BUILD_DIR}" && go build -o "$C_PWD/mc") 41 42 # remove mc source. 43 purge "${MC_BUILD_DIR}" 44 fi 45 46 "${MINIO[@]}" --address ":$start_port" "${WORK_DIR}/disk{1...4}" >"${WORK_DIR}/server1.log" 2>&1 & 47 pid=$! 48 disown $pid 49 sleep 5 50 51 if ! ps -p ${pid} 1>&2 >/dev/null; then 52 echo "server1 log:" 53 cat "${WORK_DIR}/server1.log" 54 echo "FAILED" 55 purge "$WORK_DIR" 56 exit 1 57 fi 58 59 "${PWD}/mc" mb --with-versioning minio/bucket 60 61 for i in $(seq 1 4); do 62 "${PWD}/mc" cp /etc/hosts minio/bucket/testobj 63 64 sudo chown -R root. "${WORK_DIR}/disk${i}" 65 66 "${PWD}/mc" cp /etc/hosts minio/bucket/testobj 67 68 sudo chown -R ${USER}. "${WORK_DIR}/disk${i}" 69 done 70 71 for vid in $("${PWD}/mc" ls --json --versions minio/bucket/testobj | jq -r .versionId); do 72 "${PWD}/mc" cat --vid "${vid}" minio/bucket/testobj | md5sum 73 done 74 75 pkill minio 76 sleep 3 77 } 78 79 function main() { 80 start_port=$(shuf -i 10000-65000 -n 1) 81 82 start_minio_4drive ${start_port} 83 } 84 85 function purge() { 86 rm -rf "$1" 87 } 88 89 (main "$@") 90 rv=$? 91 purge "$WORK_DIR" 92 exit "$rv"