#!/bin/bash
# =============================================================================
# 步骤 1：从原数据机拉取数据文件到迁移目标机（全量版）
# 仅传输数据：files/ kg_output/ kg_snapshot.json
# 在【迁移目标机】上执行本脚本
# 配置项请修改 migration_config.sh
# =============================================================================

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/migration_config.sh"

set -e

echo "=========================================="
echo "  kgrag 数据迁移脚本 - 步骤 1（全量）"
echo "  原数据机: ${SRC_SERVER}:${SRC_APP_DIR}"
echo "  目标代码目录: ${DST_CODE_DIR}"
echo "  目标文件目录: ${DST_FILES_DIR}"
echo "=========================================="

mkdir -p "${DST_FILES_DIR}"
mkdir -p "${DST_CODE_DIR}/kg_output"

echo ""
echo "[1/3] 原始文档 → ${DST_FILES_DIR}/ ..."
rsync -avz --progress ${RSYNC_EXTRA} \
    -e "ssh -p ${SRC_SSH_PORT}" \
    "${SRC_SERVER}:${SRC_APP_DIR}/files/" \
    "${DST_FILES_DIR}/"

echo ""
echo "[2/3] kg_output → ${DST_CODE_DIR}/kg_output/ ..."
rsync -avz --progress ${RSYNC_EXTRA} \
    -e "ssh -p ${SRC_SSH_PORT}" \
    "${SRC_SERVER}:${SRC_APP_DIR}/kg_output/" \
    "${DST_CODE_DIR}/kg_output/"

echo ""
echo "[3/3] kg_snapshot.json → ${DST_CODE_DIR}/ ..."
rsync -avz --progress ${RSYNC_EXTRA} \
    -e "ssh -p ${SRC_SSH_PORT}" \
    "${SRC_SERVER}:${SRC_APP_DIR}/kg_snapshot.json" \
    "${DST_CODE_DIR}/kg_snapshot.json"

echo ""
echo "=========================================="
echo "  数据迁移完成！"
echo "  下一步：执行 bash 02_load_neo4j.sh"
echo "=========================================="
