#!/usr/bin/env bash # Replicate objects from vps-0 (hot) → black (cold) for the platform's MinIO buckets. # Uses `mc mirror`, which is incremental + idempotent. # # Run on BLACK, on a cron/systemd-timer (e.g., every 15 min). # Buckets configured below — extend BUCKETS array as new ones are created. set -euo pipefail # mc alias names — configure once via `mc alias set ...` SRC_ALIAS="${SRC_ALIAS:-platform-vps0}" DST_ALIAS="${DST_ALIAS:-platform-black}" # Buckets to replicate (extend as features add new buckets) BUCKETS=( "platform-media" "platform-uploads" "platform-exports" ) if ! command -v mc &>/dev/null; then echo "ERROR: mc (minio client) not found" >&2 echo " install: dnf install minio-mc OR https://min.io/docs/minio/linux/reference/minio-mc.html" >&2 exit 1 fi # Sanity: aliases must exist for alias in "$SRC_ALIAS" "$DST_ALIAS"; do if ! mc alias list | grep -q "^${alias}\b"; then echo "ERROR: mc alias '${alias}' not configured. Run:" >&2 echo " mc alias set ${alias} https:// " >&2 exit 1 fi done for bucket in "${BUCKETS[@]}"; do echo "==> mirror ${SRC_ALIAS}/${bucket} → ${DST_ALIAS}/${bucket}" # --overwrite: replace newer on dst with newer on src; --remove: prune deletes mc mirror --overwrite --remove \ "${SRC_ALIAS}/${bucket}" "${DST_ALIAS}/${bucket}" \ 2>&1 | tail -5 done echo "done."