From 84c33e423bcbf716d010d8ca9a337f53f48b370d Mon Sep 17 00:00:00 2001 From: Aron Date: Thu, 6 Nov 2025 13:14:19 +0100 Subject: [PATCH] migrate script --- migrate_to_production.sh | 58 ++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/migrate_to_production.sh b/migrate_to_production.sh index 2eaf624..ac9014b 100755 --- a/migrate_to_production.sh +++ b/migrate_to_production.sh @@ -4,7 +4,8 @@ # Run this FROM the dev Mac (einszwovier.local) to migrate to production Mac (124.local) # -set -e # Exit on any error +# Don't exit on error - we'll handle retries +set +e echo "════════════════════════════════════════════════════════════════" echo " Studio EinsZwoVier - Production Migration Script" @@ -29,6 +30,7 @@ fi PROD_MAC="124" # SSH config alias for admin@124.local DEV_PATH="/Users/aron124/webapp_124" PROD_PATH="/Users/admin/webapp_124" +MAX_RETRIES=5 echo "" echo "═══ Step 1: Stop services on dev Mac (locally) ═══" @@ -42,17 +44,57 @@ ssh "$PROD_MAC" "mkdir -p $(dirname "$PROD_PATH")" echo "✅ Directory created" echo "" -echo "═══ Step 3: Copy all files (this may take 10-30 minutes) ═══" +echo "═══ Step 3: Copy all files (auto-resume enabled) ═══" echo "Copying from: $DEV_PATH (local)" echo "Copying to: $PROD_MAC:$PROD_PATH" echo "" -# Use rsync for better progress and resume capability -if command -v rsync &> /dev/null; then - rsync -avz --progress "$DEV_PATH/" "$PROD_MAC:$PROD_PATH/" -else - # Fallback to scp - scp -r "$DEV_PATH" "$PROD_MAC:$(dirname "$PROD_PATH")/" +# Rsync with auto-retry on failure +RETRY_COUNT=0 +RSYNC_SUCCESS=0 + +while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ $RSYNC_SUCCESS -eq 0 ]; do + if [ $RETRY_COUNT -gt 0 ]; then + echo "" + echo "⚠️ Connection interrupted. Resuming transfer (attempt $((RETRY_COUNT + 1))/$MAX_RETRIES)..." + sleep 5 + fi + + if command -v rsync &> /dev/null; then + # Rsync with: + # -a: archive mode + # -v: verbose + # --progress: show progress + # --partial: keep partially transferred files + # --append-verify: resume from where we left off + # --timeout=300: 5min timeout per operation + # --compress-level=0: no compression (faster for local network) + rsync -av --progress --partial --append-verify --timeout=300 --compress-level=0 \ + --no-inc-recursive "$DEV_PATH/" "$PROD_MAC:$PROD_PATH/" + + if [ $? -eq 0 ]; then + RSYNC_SUCCESS=1 + else + RETRY_COUNT=$((RETRY_COUNT + 1)) + fi + else + # Fallback to scp with keep-alive + scp -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -r "$DEV_PATH" "$PROD_MAC:$(dirname "$PROD_PATH")/" + + if [ $? -eq 0 ]; then + RSYNC_SUCCESS=1 + else + RETRY_COUNT=$((RETRY_COUNT + 1)) + fi + fi +done + +if [ $RSYNC_SUCCESS -eq 0 ]; then + echo "" + echo "❌ Failed to transfer files after $MAX_RETRIES attempts." + echo "You can manually resume with:" + echo " rsync -av --progress --partial --append-verify $DEV_PATH/ $PROD_MAC:$PROD_PATH/" + exit 1 fi echo "✅ Files copied successfully"