Why:
The service manager could create and run postgres instances but had no
way to retarget a port explicitly, back data up, clone an instance to
another port, or move a database between instances — the user asked for
exactly these operations.
Evidence:
- "set <name> [--port N] [--host H] [--apply] [--tag T...]": explicit
registration change; running postgres requires --apply (stop → rewrite
registration → start); port availability checked against both
registrations and live listeners. Verified: 8890→8895 with data intact
and DSN updated, old port freed; refusal without --apply.
- "db backup <name> [--db X] [--out F]": pg_dump -Fc into
runtime/<name>/backups/ (0600) with pg_restore --list self-check;
"db backups" lists them.
- "db restore <name> --file F [--db X] [--force]": restores into a new db
or refuses on a non-empty target unless --force (drop with FORCE +
recreate + restore), reporting table counts afterwards. Verified all
three paths.
- "db clone <src> <dst> [--port P] [--password PW] [--tag] [--online]":
default physical clone (brief source stop, cp -a of pgdata minus
postmaster files, new registration, source restarted on its own port);
--online copies via dump/restore without stopping the source (verified
source pid unchanged). Clone lands on the requested or derived port.
- "db copy <src> <dst> [--db X] [--force]": single-database logical move
between two running instances with the same non-empty-target guard.
"db ls <name>" lists databases.
- Fixed during verification: clone/copy leaked the CLI --port into the
source restart path (source briefly came up on the clone's port); the
address overrides are now cleared inside those commands.
Impact:
All operations stay inside runtime/<name>/, append to history.jsonl, and
reuse the existing safety constraints (own-process stop, port conflicts
reported not seized, secrets in 0600 files). Overwriting a non-empty
database requires an explicit --force everywhere. Makefile help line
mentions the new db subcommands.
Refs: .task/feature-svc-db-ops.md(任务卡=PR 描述)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
feature/svc-db-ops 任务卡
任务主记录:<PR 链接,task-finish 时填写>;状态:进行中;owner:weichen
基线与授权
d54bfdd8e9仅改 Dev 仓
scripts/svc.sh(及 Makefile 帮助行);不碰主检出 .video_agent/(已本地 exclude)。目标与非目标
目标(scripts/svc.sh 数据库运维扩展,均沿用既有登记/事件/安全边界):
set <name> [--port N] [--host H] [--apply] [--tag T...]:显式变更登记。postgres 换端口运行中须 --apply(stop→改登记→start);未运行直接生效;端口冲突预检(登记+监听双查)。
agent/static 的 set 只改 tags(换端口走 restart --port)。
db backup <name> [--db X] [--out F]:pg_dump -Fc → runtime//backups/-.dump(600),pg_restore --list 自校验;
db backups列表。db restore <name> --file F [--db X] [--force]:恢复;目标库非空拒绝覆盖,--force 才DROP WITH (FORCE)+重建+恢复;完成后回显表数。
db clone <src> <dst> [--port P] [--password PW] [--tag T] [--online]:默认物理克隆(短暂停源→cp -a pgdata→登记目标(新端口/继承用户库认证)→复启源;目标不自动启动);
--online 走 dump/restore 不停源(目标须已 create+start)。
db copy <src> <dst> [--db X] [--force]:跨实例单库逻辑复制(双方须运行;目标非空须 --force)。db ls <name>:列出实例内数据库。非目标:agent SQLite 备份(本轮不做,记剩余项);不做定时/增量备份;不做跨主机传输;
restore/clone 不删除备份文件;不动后端二进制(无 migrate 子命令,迁移=数据搬运)。
同步记录
d54bfdd8e9d54bfdd8e9关键实现约定
本就在环境目录而非 pgdata,不随 cp 传播。
结果与验证(完成后填写)
set(换端口/标签,运行中须 --apply)、db backup/backups/ restore(pg_dump -Fc + 归档自检 + --force 覆盖防护)、db clone(默认物理:短暂停源→cp pgdata→登记目标→复启源;--online 不停源)、
db copy(跨实例单库,--force 防护)、db ls;显式参数 pg_run/dump/restore 助手、svc_set_key 单键改写、check_port_available。Makefile 帮助行同步。
测试中发现并修复 CLI --port 泄漏进源复启的 bug(clone/copy 入口清空地址覆盖)。
本轮;restore --force 的 DROP WITH (FORCE) 需 PG13+(宿主 18 满足)。