NAS 局域网 IP 因重启被 DHCP 换过两次,磁盘/网络稳定性都不如已经跑着好几个 生产服务的甲骨文机器。整体搬迁:应用 + 数据库都搬走,NAS 只保留 Gitea(这个 仓库的源码托管,未动)。 ## 迁移过程(已核对无损) - MariaDB:NAS 导出(10.11 源库,处理了只有新版本才有的 `/*M!999999` 注释) → 导入甲骨文 MariaDB 10.3.39,**20 张表逐条精确 COUNT(*) 比对完全一致** - 冻结 NAS(停服务)后又 dump 一次核对,确认期间零数据差异,才继续删库 - NAS `garmin_health_lab` 已 DROP DATABASE,备份在本地 `~/Desktop/Work/backups/garmin_health_lab_nas_backup_20260912.sql.gz` - 应用部署到 `/opt/garmin-health-lab`,systemd 单元(`ubuntu` 用户,非 root),和这台机器上的 ai-gateway/auth-hub 同一套约定 - 公网:`https://garmin.zichuan.xyz`,DNS + Caddy 反代 + 自动 TLS,替代原来 `NAS frpc → 甲骨文:8124` 那条隧道(已从 NAS 的 frpc.toml 精确删除对应段, 其它转发未动,改完逐条复检过没打断) - auth-hub 回调地址换成新域名,NAS/旧端口那几条历史回调已清掉 - AI 网关配置改本地回环(网关现在同机了),触发真实生成验证过 ## 一个当场拦下来的风险 甲骨文部署完默认开着自动同步。迁移窗口期两边并行跑时,若两边的调度器同时去 刷新 Garmin 令牌,会撞上按账号计算的 SSO 限流(`GarminHealthLab` 仓库 2026-09-03 那次事故的根因,那次修复花了一整天)。确认账号级 auto_sync 设置 本来是关的、这次算侥幸没撞上——不是设计上的保险,所以迁移期间显式在甲骨文这边 加了 `AUTO_SYNC=false`,直接在运行进程里验证过生效,确认 NAS 已冻结、数据无 缺口后才打开。 ## 文档 / 脚本同步 CLAUDE.md 明确写过"部署位置会变,排障前先查、不要凭记忆"——这次是第二次踩中 同一类问题(上次是"NAS 有没有生产环境"判断错),所以把 CLAUDE.md / PROGRESS.md / README.md / docs/* 里的部署事实全部更新,NAS 时代的 `deploy/` 脚本加废弃 说明保留参考、不删除,新增 `deploy/push_oracle.sh`(当场跑通一次真实部署)。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
66 lines
2.6 KiB
Bash
Executable File
66 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Push this working tree to the Oracle box and restart it.
|
|
#
|
|
# Unlike deploy/push.sh (the retired NAS deployment), this target uses key
|
|
# auth and systemd — matching the convention every other service on that box
|
|
# already follows (ai-gateway, auth-hub, fam-edge, ...): code lives under
|
|
# /opt/<name>, gunicorn is a systemd unit, Caddy reverse-proxies a subdomain
|
|
# to a local port. Nothing here needs a password or sudo for the deploy
|
|
# itself; only the one-time systemd/Caddy setup did, and that is already done.
|
|
#
|
|
# ./deploy/push_oracle.sh [user@host] [ssh-key]
|
|
#
|
|
# Never touches backend/.env, .venv or the database on the far side.
|
|
set -e
|
|
|
|
HOST="${1:-ubuntu@129.146.26.249}"
|
|
KEY="${2:-$HOME/.ssh/oracle_new}"
|
|
APP=/opt/garmin-health-lab
|
|
REPO="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
sh_() { ssh -i "$KEY" -o BatchMode=yes "$HOST" "$@"; }
|
|
|
|
if [ ! -f "$REPO/client/build/index.html" ]; then
|
|
echo "client/build is missing — run 'npm run build' first" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# macOS bsdtar writes com.apple.provenance xattrs and ._ resource forks that
|
|
# the Linux side cannot read; --no-xattrs plus COPYFILE_DISABLE strip them.
|
|
TAR="tar czf - --no-xattrs"
|
|
export COPYFILE_DISABLE=1
|
|
|
|
echo "==> backend"
|
|
$TAR --exclude .venv --exclude .env --exclude __pycache__ \
|
|
--exclude '*.db' --exclude tests --exclude .pytest_cache --exclude static \
|
|
-C "$REPO/backend" . | sh_ "tar xzf - -C '$APP/backend'"
|
|
|
|
echo "==> static (cleared first, so stale JS chunks do not pile up)"
|
|
sh_ "rm -rf '$APP/backend/static' && mkdir -p '$APP/backend/static'"
|
|
$TAR -C "$REPO/client/build" . | sh_ "tar xzf - -C '$APP/backend/static'"
|
|
|
|
echo "==> pip install (in case requirements.txt changed)"
|
|
sh_ "$APP/backend/.venv/bin/pip install -q -r $APP/backend/requirements.txt"
|
|
|
|
echo "==> restart"
|
|
BEFORE=$(sh_ "systemctl show garmin-health-lab -p MainPID --value" || true)
|
|
sh_ "sudo systemctl restart garmin-health-lab"
|
|
sleep 2
|
|
AFTER=$(sh_ "systemctl show garmin-health-lab -p MainPID --value" || true)
|
|
if [ -z "$AFTER" ] || [ "$AFTER" = "0" ]; then
|
|
echo "service failed to come back up — check journalctl -u garmin-health-lab" >&2
|
|
exit 1
|
|
fi
|
|
if [ "$BEFORE" = "$AFTER" ]; then
|
|
echo "the main PID did not change ($AFTER) — the old process may still be" >&2
|
|
echo "serving and your changes are NOT live." >&2
|
|
exit 1
|
|
fi
|
|
echo "==> restarted: $BEFORE -> $AFTER"
|
|
|
|
echo "==> health"
|
|
sh_ "curl -sf -m 5 -o /dev/null -w 'local: %{http_code}\n' http://127.0.0.1:5500/api/health/status" \
|
|
|| echo "local: unreachable"
|
|
curl -sf -m 8 -o /dev/null -w "public (https://garmin.zichuan.xyz): %{http_code}\n" \
|
|
https://garmin.zichuan.xyz/api/health/status || echo "public: unreachable"
|