diff options
author | doc <doc@filenotfound.org> | 2025-06-30 20:11:52 +0000 |
---|---|---|
committer | doc <doc@filenotfound.org> | 2025-06-30 20:11:52 +0000 |
commit | 41e897f4945aaf8fbcdf0b12ac2f08c5e6ae0458 (patch) | |
tree | db7c3520fd91abc3cf56b1a52095d23f3a80d059 /migrationtoblock.sh |
Diffstat (limited to 'migrationtoblock.sh')
-rwxr-xr-x | migrationtoblock.sh | 72 |
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." |