github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/bucket/replication/setup_2site_existing_replication.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  echo "Running $0"
     4  
     5  set -x
     6  
     7  trap 'catch $LINENO' ERR
     8  
     9  # shellcheck disable=SC2120
    10  catch() {
    11  	if [ $# -ne 0 ]; then
    12  		echo "error on line $1"
    13  		for site in sitea siteb; do
    14  			echo "$site server logs ========="
    15  			cat "/tmp/${site}_1.log"
    16  			echo "==========================="
    17  			cat "/tmp/${site}_2.log"
    18  		done
    19  	fi
    20  
    21  	echo "Cleaning up instances of MinIO"
    22  	pkill minio
    23  	pkill -9 minio
    24  	rm -rf /tmp/multisitea
    25  	rm -rf /tmp/multisiteb
    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  sleep 10s
    60  
    61  export MC_HOST_sitea=http://minio:minio123@127.0.0.1:9001
    62  export MC_HOST_siteb=http://minio:minio123@127.0.0.1:9004
    63  
    64  ./mc mb sitea/bucket
    65  
    66  ## Create 100 files
    67  mkdir -p /tmp/data
    68  for i in $(seq 1 10); do
    69  	echo "T" >/tmp/data/file_${i}.txt
    70  done
    71  
    72  ./mc mirror /tmp/data sitea/bucket/
    73  ./mc version enable sitea/bucket
    74  
    75  ./mc cp /tmp/data/file_1.txt sitea/bucket/marker
    76  ./mc rm sitea/bucket/marker
    77  
    78  ./mc mb siteb/bucket/
    79  ./mc version enable siteb/bucket/
    80  
    81  echo "adding replication rule for site a -> site b"
    82  ./mc replicate add sitea/bucket/ \
    83  	--remote-bucket http://minio:minio123@127.0.0.1:9004/bucket
    84  
    85  remote_arn=$(./mc replicate ls sitea/bucket --json | jq -r .rule.Destination.Bucket)
    86  sleep 1
    87  
    88  ./mc replicate resync start sitea/bucket/ --remote-bucket "${remote_arn}"
    89  sleep 30s ## sleep for 30s idea is that we give 300ms per object.
    90  
    91  ./mc ls -r --versions sitea/bucket >/tmp/sitea.txt
    92  ./mc ls -r --versions siteb/bucket >/tmp/siteb.txt
    93  
    94  out=$(diff -qpruN /tmp/sitea.txt /tmp/siteb.txt)
    95  ret=$?
    96  if [ $ret -ne 0 ]; then
    97  	echo "BUG: expected no missing entries after replication: $out"
    98  	exit 1
    99  fi
   100  
   101  ./mc cp /tmp/data/file_1.txt sitea/bucket/marker_new
   102  ./mc rm sitea/bucket/marker_new
   103  
   104  sleep 12s ## sleep for 12s idea is that we give 100ms per object.
   105  
   106  ./mc ls -r --versions sitea/bucket >/tmp/sitea.txt
   107  ./mc ls -r --versions siteb/bucket >/tmp/siteb.txt
   108  
   109  out=$(diff -qpruN /tmp/sitea.txt /tmp/siteb.txt)
   110  ret=$?
   111  if [ $ret -ne 0 ]; then
   112  	echo "BUG: expected no 'diff' after replication: $out"
   113  	exit 1
   114  fi
   115  
   116  ./mc rm -r --force --versions sitea/bucket/marker
   117  sleep 14s ## sleep for 14s idea is that we give 100ms per object.
   118  
   119  ./mc ls -r --versions sitea/bucket >/tmp/sitea.txt
   120  ./mc ls -r --versions siteb/bucket >/tmp/siteb.txt
   121  
   122  out=$(diff -qpruN /tmp/sitea.txt /tmp/siteb.txt)
   123  ret=$?
   124  if [ $ret -ne 0 ]; then
   125  	echo "BUG: expected no 'diff' after replication: $out"
   126  	exit 1
   127  fi
   128  
   129  ./mc mb sitea/bucket-version/
   130  ./mc mb siteb/bucket-version
   131  
   132  ./mc version enable sitea/bucket-version/
   133  ./mc version enable siteb/bucket-version/
   134  
   135  echo "adding replication rule for site a -> site b"
   136  ./mc replicate add sitea/bucket-version/ \
   137  	--remote-bucket http://minio:minio123@127.0.0.1:9004/bucket-version
   138  
   139  ./mc mb sitea/bucket-version/directory/
   140  
   141  sleep 2s
   142  
   143  ./mc ls -r --versions sitea/bucket-version/ >/tmp/sitea_dirs.txt
   144  ./mc ls -r --versions siteb/bucket-version/ >/tmp/siteb_dirs.txt
   145  
   146  out=$(diff -qpruN /tmp/sitea_dirs.txt /tmp/siteb_dirs.txt)
   147  ret=$?
   148  if [ $ret -ne 0 ]; then
   149  	echo "BUG: expected no 'diff' after replication: $out"
   150  	exit 1
   151  fi
   152  
   153  ./mc rm -r --versions --force sitea/bucket-version/
   154  
   155  sleep 2s
   156  
   157  ./mc ls -r --versions sitea/bucket-version/ >/tmp/sitea_dirs.txt
   158  ./mc ls -r --versions siteb/bucket-version/ >/tmp/siteb_dirs.txt
   159  
   160  out=$(diff -qpruN /tmp/sitea_dirs.txt /tmp/siteb_dirs.txt)
   161  ret=$?
   162  if [ $ret -ne 0 ]; then
   163  	echo "BUG: expected no 'diff' after replication: $out"
   164  	exit 1
   165  fi
   166  
   167  ## check if we don't create delete markers on the directory objects, its always permanent delete.
   168  ./mc mb sitea/bucket-version/directory/
   169  
   170  sleep 2s
   171  
   172  ./mc rm -r --force sitea/bucket-version/
   173  
   174  sleep 2s
   175  
   176  ./mc ls -r --versions sitea/bucket-version/ >/tmp/sitea_dirs.txt
   177  ./mc ls -r --versions siteb/bucket-version/ >/tmp/siteb_dirs.txt
   178  
   179  out=$(diff -qpruN /tmp/sitea_dirs.txt /tmp/siteb_dirs.txt)
   180  ret=$?
   181  if [ $ret -ne 0 ]; then
   182  	echo "BUG: expected no 'diff' after replication: $out"
   183  	exit 1
   184  fi
   185  
   186  sitea_count=$(cat /tmp/sitea_dirs.txt | wc -l) # need to do it this way to avoid filename in the output
   187  siteb_count=$(cat /tmp/siteb_dirs.txt | wc -l) # need to do it this way to avoid filename in the output
   188  sitea_out=$(cat /tmp/sitea_dirs.txt)
   189  siteb_out=$(cat /tmp/siteb_dirs.txt)
   190  
   191  if [ $sitea_count -ne 0 ]; then
   192  	echo "BUG: expected no 'directory objects' left after deletion: ${sitea_out}"
   193  	exit 1
   194  fi
   195  
   196  if [ $siteb_count -ne 0 ]; then
   197  	echo "BUG: expected no 'directory objects' left after deletion: ${siteb_out}"
   198  	exit 1
   199  fi
   200  
   201  catch