#!/bin/bash set -e # Configuration # Since "ssh ai30" works directly (via ~/.ssh/config or keys), we use it directly. # SERVER_USER and SERVER_IP are implicit in the "ai30" alias. SERVER_ALIAS="ai30" REMOTE_DIR="/data/ai-platform/hxops" BACKEND_CONTAINER="hxops-backend" echo "=== Starting Full Server Sync & Update ===" echo "Target: $SERVER_ALIAS (Using SSH alias)" # 1. Sync Backend Code echo ">>> [1/4] Syncing backend code..." # Exclude venv, __pycache__, local db, etc. rsync -avz --exclude 'venv' --exclude '__pycache__' --exclude '*.pyc' --exclude 'local_test.db' \ backend/ $SERVER_ALIAS:$REMOTE_DIR/backend/ # 2. Sync Frontend Build echo ">>> [2/4] Syncing frontend build..." rsync -avz frontend/dist/ $SERVER_ALIAS:$REMOTE_DIR/frontend/dist/ # 3. Restart Services echo ">>> [3/4] Restarting services..." ssh $SERVER_ALIAS "cd $REMOTE_DIR && \ docker compose down && \ docker compose up -d --build" # 4. Update Database Data echo ">>> [4/4] Updating database data (Password & Seeds)..." # Ensure we run seed_production.py to update admin password to Hxit@54321 # We use 'flask db upgrade' but if it fails due to existing tables, we proceed to seeding. # The '|| true' allows the script to continue if migration fails. ssh $SERVER_ALIAS "cd $REMOTE_DIR && \ echo 'Checking/Creating database...' && \ docker compose exec -T $BACKEND_CONTAINER python3 init_db.py && \ echo 'Running migrations (ignoring errors if tables exist)...' && \ docker compose exec -T $BACKEND_CONTAINER flask db upgrade || echo 'Migration step had errors, possibly existing tables. Continuing...' && \ echo 'Running seed script...' && \ docker compose exec -T $BACKEND_CONTAINER python3 seed_production.py" echo "=== Sync & Update Complete! ===" echo "You can now login at http://192.168.100.230:8890" echo "Username: admin" echo "Password: Hxit@54321"