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

工作流程

  1. 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).
  2. TAKE the snapshot:
    npx convex export --path backup-<date>.zip
    (add
    --include-file-storage
    if the app stores files). This is the backup artifact; treat it as sensitive real data.
  3. 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
    npx convex export
    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.
  4. RESTORE DRILL (the half almost nobody does — this is the point): (a) PRECONDITION: a Preview Deploy Key as
    CONVEX_DEPLOY_KEY
    (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:
    npx convex deploy --preview-create restore-drill-<date>
    . (c) restore the snapshot into it:
    npx convex import backup-<date>.zip --deployment restore-drill-<date> --replace
    (import targets a deployment by NAME with
    --deployment
    ; there is no
    --preview-name
    on import). (d) ASSERT recovery: read the restored data back (MCP
    tables
    for row counts,
    data
    /
    runOneoffQuery
    for 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.
  5. 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:
    npx convex import backup.zip --replace --prod
    , gated by deploy-guard, with the post-snapshot-write-loss caveat stated).
  6. HYGIENE: delete local snapshot copies when done (real data); the drill preview auto-expires. Never commit a backup file.
  1. GUARD:deploy-guard — 对要备份的部署进行分类并通知(读取/导出操作是安全的;演练的恢复目标是临时预览环境,绝不是生产环境)。
  2. 创建快照:
    npx convex export --path backup-<date>.zip
    (如果应用存储文件,需添加
    --include-file-storage
    参数)。这是备份产物;需将其视为敏感的真实数据。
  3. 配置定期计划(持续执行部分):根据数据变化速度和可容忍的数据丢失量(RPO)推荐备份频率——例如,通过CI/cron每日执行
    npx convex export
    并将备份存储到用户可控的持久化存储中,同时设置保留期限。Convex平台自身也提供备份;此方案可添加一份用户自有、可移植的备份副本。
  4. 恢复演练(几乎没人完成的关键部分——这才是核心目的): (a) 前置条件:拥有作为
    CONVEX_DEPLOY_KEY
    的Preview Deploy Key(与migrate-rehearse的要求相同;属于付费层功能)。如果无法获取,则针对全新的个人开发部署进行演练并说明情况。 (b) 基于当前代码创建临时预览环境:
    npx convex deploy --preview-create restore-drill-<date>
    。 (c) 将快照恢复至该环境:
    npx convex import backup-<date>.zip --deployment restore-drill-<date> --replace
    (导入操作通过
    --deployment
    指定部署名称;导入命令不支持
    --preview-name
    参数)。 (d) 验证恢复结果:读取恢复后的数据(通过MCP
    tables
    获取行数,通过
    data
    /
    runOneoffQuery
    进行抽样检查),确认关键表已恢复且行数符合预期,并包含真实记录样本——若恢复“成功”但行数为0,则演练失败。如有可能,与源数据的行数进行对比。
  5. 清晰报告演练结果:包括备份内容、是否实际执行并验证了恢复(或演练失败的原因——失败的演练是最有价值的输出,可在真正的灾难发生前发现问题)、推荐的备份计划与保留期限,以及恢复至生产环境的手册(具体命令:
    npx convex import backup.zip --replace --prod
    ,需通过deploy-guard管控,并说明快照写入后的数据丢失风险)。
  6. 数据清理:完成后删除本地快照副本(真实数据);演练用的预览环境会自动过期。切勿提交备份文件至版本控制系统。

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的范畴。