summaryrefslogtreecommitdiff
path: root/migrationtoblock.sh
diff options
context:
space:
mode:
authordoc <doc@filenotfound.org>2025-06-30 20:11:52 +0000
committerdoc <doc@filenotfound.org>2025-06-30 20:11:52 +0000
commit41e897f4945aaf8fbcdf0b12ac2f08c5e6ae0458 (patch)
treedb7c3520fd91abc3cf56b1a52095d23f3a80d059 /migrationtoblock.sh
commit of legacy codeHEADmaster
Diffstat (limited to 'migrationtoblock.sh')
-rwxr-xr-xmigrationtoblock.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/migrationtoblock.sh b/migrationtoblock.sh
new file mode 100755
index 0000000..3cc75fe
--- /dev/null
+++ b/migrationtoblock.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+# === CONFIG ===
+SRC="/mnt/raid5/minio-data/linodeassets"
+DST="/mnt/mastodon-assets"
+MOUNTPOINT="/home/mastodon/live/public/system"
+LOGFILE="/var/log/mastodon_asset_migration_$(date +%Y%m%d_%H%M%S).log"
+
+log() {
+ echo "[$(date '+%F %T')] $*" | tee -a "$LOGFILE"
+}
+
+verify_sync() {
+ local src_count=$(find "$SRC" -type f | wc -l)
+ local dst_count=$(find "$DST" -type f | wc -l)
+ local src_bytes=$(du -sb "$SRC" | awk '{print $1}')
+ local dst_bytes=$(du -sb "$DST" | awk '{print $1}')
+
+ echo "--- Verification Results ---" | tee -a "$LOGFILE"
+ echo "Files: $src_count โ†’ $dst_count" | tee -a "$LOGFILE"
+ echo "Bytes: $src_bytes โ†’ $dst_bytes" | tee -a "$LOGFILE"
+
+ if [[ "$src_count" -ne "$dst_count" || "$src_bytes" -ne "$dst_bytes" ]]; then
+ echo "โŒ MISMATCH detected. Please review the rsync log." | tee -a "$LOGFILE"
+ else
+ echo "โœ… Verified: source and destination match." | tee -a "$LOGFILE"
+ fi
+ echo "---------------------------" | tee -a "$LOGFILE"
+}
+
+# === PHASE 1: Live Sync ===
+log "๐Ÿš€ Starting Phase 1: Live rsync"
+rsync -aAXv --progress "$SRC/" "$DST/" | tee -a "$LOGFILE"
+
+# === Stop Mastodon ===
+log "๐Ÿ›‘ Stopping Mastodon services..."
+systemctl stop mastodon-web mastodon-sidekiq mastodon-streaming || {
+ log "โŒ Failed to stop Mastodon services"; exit 1;
+}
+
+# === PHASE 2: Final Sync ===
+log "๐Ÿ” Starting Phase 2: Final rsync with --delete"
+rsync -aAXv --delete "$SRC/" "$DST/" | tee -a "$LOGFILE"
+
+# === Bind Mount Cutover ===
+log "๐Ÿ”— Swapping in block storage as $MOUNTPOINT"
+if [[ -d "$MOUNTPOINT" ]]; then
+ mv "$MOUNTPOINT" "${MOUNTPOINT}.bak" || {
+ log "โŒ Could not move existing mountpoint"; exit 1;
+ }
+fi
+
+mkdir -p "$MOUNTPOINT"
+mount --bind "$DST" "$MOUNTPOINT"
+grep -q "$MOUNTPOINT" /etc/fstab || echo "$DST $MOUNTPOINT none bind 0 0" >> /etc/fstab
+log "[โœ“] Bind mount active and persisted"
+
+# === Permissions ===
+log "๐Ÿ”ง Fixing permissions on $DST"
+chown -R mastodon:mastodon "$DST"
+
+# === Restart Mastodon ===
+log "๐Ÿš€ Restarting Mastodon services..."
+systemctl start mastodon-web mastodon-sidekiq mastodon-streaming || {
+ log "โŒ Failed to restart Mastodon services"; exit 1;
+}
+
+# === VERIFY ===
+log "๐Ÿงช Verifying file count and byte totals"
+verify_sync
+
+log "๐ŸŽ‰ Migration completed successfully. Mastodon is live on block storage."