#!/bin/bash
set -e

echo "Backing up local DB..."
cp /app/ai-hub/data/ai_hub.db /app/ai-hub/data/ai_hub.db.bak || true

echo "Copying Production DB to accessible temporary location on host..."
sshpass -p "a6163484a" ssh -t -o ConnectTimeout=5 -o StrictHostKeyChecking=no axieyangb@192.168.68.113 "echo 'a6163484a' | sudo -S docker cp ai_hub_service:/app/data/ai_hub.db /tmp/ai_hub_prod.db && echo 'a6163484a' | sudo -S chown axieyangb:axieyangb /tmp/ai_hub_prod.db"

echo "Downloading Production DB..."
sshpass -p "a6163484a" scp -o StrictHostKeyChecking=no axieyangb@192.168.68.113:/tmp/ai_hub_prod.db /app/ai-hub/data/ai_hub.db

echo "Done! Local server now using Production DB state."
