Repository navigation
Conversation
…rade.sh issue #227: - docs/deployment/backup-restore.md:pg_dump -Fc 备份 / pg_restore --clean --if-exists 恢复 / 命名卷 tar 兜底三组可复制命令;硬前提(迁移不可逆)与 SECURITY_KEY 一致性前置 - scripts/backup.sh:di-backup-<版本>-<时间戳>.dump + sha256;compose 容器内 pg_dump 优先, 回退本机 pg_dump + DATABASE_URL;版本取 /health/detail(R-100),缺失时回退镜像 tag - scripts/upgrade.sh:备份 → 迁移顺序前置检查(dry-run → -apply → 再放量红线)→ 换版本 → 轮询 ready 60s → 失败打印旧 TAG 起容器 + pg_restore 两条回滚命令;判据是 HTTP 200 非容器状态; ready 端点优先 /health/ready(R-100),404 回退 /health - 文档收口:production.md §7 改为指向 runbook 并同步迁移顺序红线;docker.md 升级段引用; docs/AGENTS.md 索引与 README 导航补条目 验证:bash -n + shellcheck 0 告警;compose 实跑 --dry-run 产出 113 条目 dump 且 ready 真实调用; 故障注入:停 postgres → 备份步骤快速失败;坏 DATABASE_URL 重建 → 60s 判失败并打印回滚命令
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
做了什么(issue #227 / R-102)
docs/deployment/backup-restore.md(新增):开头硬前提「迁移不可逆,回滚唯一手段是 restore」+SECURITY_KEY一致性引用 production.md §7;三组可复制命令——pg_dump -Fc备份(compose 容器内 / 外部 PG 两条路 + 一键脚本)、pg_restore --clean --if-exists恢复、命名卷docker run … alpine tar czf兜底等价命令(附跨大版本数据目录的警示);升级 runbook 与迁移顺序红线(dry-run 看报告 →-apply写库 → 再放量新版本)+ 失败回滚两步。scripts/backup.sh(新增):产出di-backup-<版本>-<时间戳>.dump并打印 sha256;自动探测 compose 容器data-insights-postgres走docker exec pg_dump,否则用本机pg_dump+DATABASE_URL(环境变量或仓库根.env,与后端同优先级、不覆盖已有 env)。scripts/upgrade.sh(新增):备份 → 迁移前置检查(红线作为显式步骤;交互确认,非交互需--yes)→TAG=<new> docker compose up -d→ 轮询 ready 60s(判据是 HTTP 200,不是容器状态——迁移失败时进程根本不监听端口)→ 失败打印两条回滚命令(旧 TAG 起容器 +pg_restore指向本次备份)。支持--dry-run(只备份 + 打印迁移步骤 + 真实调用一次 ready 判据)与--yes。production.md§7 改为指向 runbook 并同步迁移顺序红线;docker.mdCompose 升级段引用 runbook;docs/AGENTS.md索引与README.md文档导航补条目。关键设计:对 R-100(未合 PR #242)的探测回退
issue 依赖 R-100 的
/health/detail(版本串)与/health/ready(判据来源),两者尚未合入 master。脚本做成探测回退,R-100 合入后零改动自动用上完整判据:GET /health/detail的version→ 回退 app 容器镜像 tag → 回退unknown;/health/ready非 404 则以它为准 → 回退/health(master 现状:只证进程活着)。/health不探库,所以 R-100 合入前,ready 判据对「postgres 停但进程活着」不敏感;这正是 R-100 的 ready 要补的能力。怎么验证的
bash -n+shellcheck(0.11.0)两脚本 0 error;upgrade.sh --dry-run:产出 113 条目的pg_dump -Fc备份 + sha256,pg_restore -l校验 dump 可读,ready 判据被真实调用,rc=0;docker stop data-insights-postgres后重跑 → 备份步骤快速失败,报错指明「容器不在且 DATABASE_URL 未设置」;DATABASE_URL重建 app(模拟「迁移失败进程不监听端口」)→ 60s 内 ready 判失败(严格按秒轮询到 60)→ 打印旧 TAG 起容器 +pg_restore两条回滚命令,rc=1。go test/pnpm build:check,代码零改动)。顺手发现(不在本 PR 修,建议另立 issue)
docker-compose.allinone.yml对全新部署当前是坏的:postgres:18-alpine新入口(ChangePGDATAin 18+ to/var/lib/postgresql/MAJOR/dockerdocker-library/postgres#1259)要求数据卷挂载在/var/lib/postgresql(大版本子目录布局),现挂/var/lib/postgresql/data会让 postgres 容器启动即退出(Error: in 18+ … unused mount/volume)。验证时用 /tmp 覆盖文件(!override改挂载点)绕过;修 compose 涉及存量部署的数据布局迁移,超出本 issue 范围。$VAR后紧跟全角标点会把多字节字符并进变量名,set -u下误报 unbound variable——两个脚本已全量排查并加花括号(${VAR}(形式),review 时请留意不要改回去。