scripts(scripts): 🔨 Implement MinIO replication script for cross-cluster/bucket data synchronization

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-05-16 21:56:01 -07:00
parent aed3afee66
commit 4c08f82912

44
scripts/replicate-minio.sh Executable file
View file

@ -0,0 +1,44 @@
#!/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://<endpoint> <access> <secret>" >&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."