migrate script

This commit is contained in:
Aron Petau 2025-11-06 13:14:19 +01:00
parent d220d2f034
commit 84c33e423b

View file

@ -4,7 +4,8 @@
# Run this FROM the dev Mac (einszwovier.local) to migrate to production Mac (124.local) # 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 "════════════════════════════════════════════════════════════════"
echo " Studio EinsZwoVier - Production Migration Script" echo " Studio EinsZwoVier - Production Migration Script"
@ -29,6 +30,7 @@ fi
PROD_MAC="124" # SSH config alias for admin@124.local PROD_MAC="124" # SSH config alias for admin@124.local
DEV_PATH="/Users/aron124/webapp_124" DEV_PATH="/Users/aron124/webapp_124"
PROD_PATH="/Users/admin/webapp_124" PROD_PATH="/Users/admin/webapp_124"
MAX_RETRIES=5
echo "" echo ""
echo "═══ Step 1: Stop services on dev Mac (locally) ═══" 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 "✅ Directory created"
echo "" 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 from: $DEV_PATH (local)"
echo "Copying to: $PROD_MAC:$PROD_PATH" echo "Copying to: $PROD_MAC:$PROD_PATH"
echo "" echo ""
# Use rsync for better progress and resume capability # Rsync with auto-retry on failure
if command -v rsync &> /dev/null; then RETRY_COUNT=0
rsync -avz --progress "$DEV_PATH/" "$PROD_MAC:$PROD_PATH/" RSYNC_SUCCESS=0
else
# Fallback to scp while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ $RSYNC_SUCCESS -eq 0 ]; do
scp -r "$DEV_PATH" "$PROD_MAC:$(dirname "$PROD_PATH")/" 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 fi
echo "✅ Files copied successfully" echo "✅ Files copied successfully"