convex-backup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- GENERATED from convex-agents content/capabilities/convex-backup.json — do not edit by hand. -->
<!-- GENERATED from convex-agents content/capabilities/convex-backup.json — do not edit by hand. -->
Back up — and prove the restore works
备份——并验证恢复功能可用
Every backup story has two halves and most people only do the first: taking the backup, and proving you can get it back. This capability does both — it sets up regular snapshot exports and then runs a RESTORE DRILL that actually recovers the data into a disposable preview and asserts it's intact. The drill reuses migrate-rehearse's exact primitives (snapshot export → preview deploy → snapshot import) pointed at recovery instead of a forward change, so the safety net is tested, not assumed.
每个备份方案都包含两部分,而大多数人只完成第一部分:创建备份,以及验证能否恢复数据。本能力可同时完成这两项任务——它会设置定期快照导出,然后运行恢复演练(RESTORE DRILL),将数据实际恢复至可丢弃的预览环境并验证数据完整性。该演练复用了migrate-rehearse的核心机制(快照导出→预览部署→快照导入),但目标是恢复而非正向变更,因此安全机制是经过实际测试的,而非假设可用。
Workflow
工作流程
- GUARD: deploy-guard — classify + announce the deployment being backed up (reading/exporting is safe; the drill's restore target is a throwaway preview, never prod).
- TAKE the snapshot: (add
npx convex export --path backup-<date>.zipif the app stores files). This is the backup artifact; treat it as sensitive real data.--include-file-storage - SCHEDULE it (the ongoing half): recommend a cadence matched to how fast the data changes and how much loss is tolerable (RPO) — e.g. a daily via CI/cron to durable storage the user controls, with a retention window. Convex's own platform backups exist; this adds a user-owned, portable copy.
npx convex export - RESTORE DRILL (the half almost nobody does — this is the point):
(a) PRECONDITION: a Preview Deploy Key as (same requirement as migrate-rehearse; a paid-tier feature). If unavailable, drill against a fresh personal dev deployment instead and say so. (b) create a throwaway preview from the CURRENT code:
CONVEX_DEPLOY_KEY. (c) restore the snapshot into it:npx convex deploy --preview-create restore-drill-<date>(import targets a deployment by NAME withnpx convex import backup-<date>.zip --deployment restore-drill-<date> --replace; there is no--deploymenton import). (d) ASSERT recovery: read the restored data back (MCP--preview-namefor row counts,tables/datafor spot-checks) and confirm the critical tables came back with the expected row counts and a sample of real records — a restore that 'succeeds' but lands 0 rows is a FAILED drill. Compare against the source's counts where available.runOneoffQuery - REPORT the drill result plainly: what was backed up, that the restore was ACTUALLY performed and verified (or that it FAILED and why — a failed drill is the most valuable output, found before a real disaster), the recommended schedule + retention, and the recovery runbook (the exact commands to restore to prod: , gated by deploy-guard, with the post-snapshot-write-loss caveat stated).
npx convex import backup.zip --replace --prod - HYGIENE: delete local snapshot copies when done (real data); the drill preview auto-expires. Never commit a backup file.
- GUARD:deploy-guard — 对要备份的部署进行分类并通知(读取/导出操作是安全的;演练的恢复目标是临时预览环境,绝不是生产环境)。
- 创建快照:(如果应用存储文件,需添加
npx convex export --path backup-<date>.zip参数)。这是备份产物;需将其视为敏感的真实数据。--include-file-storage - 配置定期计划(持续执行部分):根据数据变化速度和可容忍的数据丢失量(RPO)推荐备份频率——例如,通过CI/cron每日执行并将备份存储到用户可控的持久化存储中,同时设置保留期限。Convex平台自身也提供备份;此方案可添加一份用户自有、可移植的备份副本。
npx convex export - 恢复演练(几乎没人完成的关键部分——这才是核心目的):
(a) 前置条件:拥有作为的Preview Deploy Key(与migrate-rehearse的要求相同;属于付费层功能)。如果无法获取,则针对全新的个人开发部署进行演练并说明情况。 (b) 基于当前代码创建临时预览环境:
CONVEX_DEPLOY_KEY。 (c) 将快照恢复至该环境:npx convex deploy --preview-create restore-drill-<date>(导入操作通过npx convex import backup-<date>.zip --deployment restore-drill-<date> --replace指定部署名称;导入命令不支持--deployment参数)。 (d) 验证恢复结果:读取恢复后的数据(通过MCP--preview-name获取行数,通过tables/data进行抽样检查),确认关键表已恢复且行数符合预期,并包含真实记录样本——若恢复“成功”但行数为0,则演练失败。如有可能,与源数据的行数进行对比。runOneoffQuery - 清晰报告演练结果:包括备份内容、是否实际执行并验证了恢复(或演练失败的原因——失败的演练是最有价值的输出,可在真正的灾难发生前发现问题)、推荐的备份计划与保留期限,以及恢复至生产环境的手册(具体命令:,需通过deploy-guard管控,并说明快照写入后的数据丢失风险)。
npx convex import backup.zip --replace --prod - 数据清理:完成后删除本地快照副本(真实数据);演练用的预览环境会自动过期。切勿提交备份文件至版本控制系统。
Rules
规则
- A backup you have never restored is a hope, not a backup — always run (or offer to run) the restore DRILL, don't just take the export.
- The drill restores into a THROWAWAY preview (or dev), never prod; the restore target and the backup source are different deployments.
- Assert recovery, don't assume it: a restore that lands 0 rows is a FAILED drill — check critical-table row counts + a real-record sample against the source.
- A FAILED drill is the most valuable output — surface it loudly; that's the whole reason to drill before a real disaster.
- Schedule matched to RPO (how much data loss is tolerable); keep a user-owned portable copy alongside Convex's platform backups, with a retention window.
- Snapshots are sensitive real data: delete local copies when done, never commit them; the restore-to-prod runbook is deploy-guard-gated with the post-snapshot-write-loss caveat stated.
- Shares migrate-rehearse's snapshot+preview mechanics but aims them at RECOVERY, not a forward change — a forward schema change is migrate-rehearse.
- 从未恢复过的备份只是一种期望,而非真正的备份——务必运行(或主动提出运行)恢复演练,不要只做导出操作。
- 演练需将数据恢复至临时预览环境(或开发环境),绝不能是生产环境;恢复目标与备份源必须是不同的部署。
- 验证恢复结果,而非假设成功:若恢复后行数为0,则演练失败——需对比关键表的行数及真实记录样本与源数据是否一致。
- 失败的演练是最有价值的输出——需重点突出;这正是在真正灾难前进行演练的核心原因。
- 备份计划需与RPO(可容忍的数据丢失量)匹配;在Convex平台备份之外,保留一份用户自有、可移植的备份副本,并设置保留期限。
- 快照属于敏感真实数据:完成后删除本地副本,切勿提交至版本控制系统;恢复至生产环境的手册需通过deploy-guard管控,并说明快照写入后的数据丢失风险。
- 复用migrate-rehearse的快照+预览机制,但目标是恢复而非正向变更——正向 schema 变更属于migrate-rehearse的范畴。