Litestream stops replicating after switching to a new or emptied backup bucket

未关闭
#233 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
56/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
sqlite, typescript

调研方向

Start in scripts/run-cloud-boot.js and trace when start_replication() runs; then read the README section on Automated backups and check how the deployment supplies BUCKET_NAME. Reproduce or inspect the empty-bucket case with Litestream 0.5.17, and compare the proposed reset and bucket-marker approaches. Done when replication recovers after a bucket change or emptying, or the documented reset procedure clearly covers both cloud and VPS deployments.

由索引模型根据 Issue 内容生成。

描述

What happens

When a site with automated backups starts using a new or empty bucket, Litestream never writes the database to it. That covers a changed BUCKET_NAME, a new Tigris bucket after moving the app to another Fly org, or a bucket whose db/ folder was cleared.

Litestream's local state in /data/.db.sqlite3-litestream still matches the old replica. Seeing the empty bucket, it tries to upload from the first transaction. Those LTX files were cleaned up locally long ago, so every sync fails:

level=ERROR msg="monitor error" ... error="open ltx file /data/.db.sqlite3-litestream/ltx/0/0000000000000001-0000000000000001.ltx: no such file or directory" hint="LTX file is missing. ... Run 'litestream reset <db>' or delete the .sqlite-litestream directory and restart."

It doesn't recover on its own. The site stays up, and the rest of the backup layer keeps working: the boot sweep uploads all assets, and the daily snapshot lands in snapshots/. So the bucket looks healthy while db/ stays empty, and point-in-time recovery is off without anyone noticing unless they read the logs.

Seen on veitsdorf (Litestream 0.5.17) after moving the app to another Fly org and creating a new Tigris bucket.

Workaround

Reset Litestream's local state, which doesn't touch the database, then restart:

fly ssh console -a <app> -C "litestream reset -config /app/scripts/litestream.yml /data/db.sqlite3"
fly machine restart <machine-id> -a <app>

After the restart, Litestream uploads a fresh snapshot and the errors stop. litestream ltx -config /app/scripts/litestream.yml /data/db.sqlite3 lists it.

Running the reset while replication is running logs cannot verify wal state errors until the restart. That's harmless, but it shows the reset belongs before replication starts.

Possible fixes

  • In scripts/run-cloud-boot.js, before start_replication(): if the local metadata directory exists but the replica has no LTX files, run litestream reset. This costs one list request per boot and also covers a bucket emptied in place.
  • Or record which bucket the local state belongs to, for example BUCKET_NAME and the endpoint in a marker file, and reset when it changes. That needs no network call, but it misses a bucket emptied in place.
  • At minimum, document how to change the bucket in README → Automated backups, including the reset step. VPS deployments that change BUCKET_NAME through pnpm vps:env set hit the same problem.
  • Check whether a newer Litestream release recovers from this on its own. If it does, upgrading would make the rest unnecessary.
主要语言
TypeScript
星标
1.8k
派生
148
平均合并
2 小时 47 分钟
30 天内合并 PR
13

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

michael/editable 的其他 Issue

查看 michael/editable 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。