Skip to content

backups: lnd and clightning databases are copied live; a restored channel.db can lose funds #95

Closed

Description

@ostermayer

Commit: 1528ecf (master, 2026-10-16). File: modules/backups.nix, with docs/services.md and test/tests.py.

What I found

The duplicity file list includes the whole lnd and clightning data directories (modules/backups.nix, the includeFileList). The backup runs while the daemons run. So it copies lnd/.../channel.db and clightning/.../lightningd.sqlite3 live. The unit only waits for the PostgreSQL dumps. Nothing stops or pauses lnd or clightning, and nothing takes a consistent snapshot.

  1. A torn copy. A database file copied during writes may not open after a restore. For lnd this is the bbolt channel.db. For clightning it's the SQLite file and its WAL.

  2. Stale channel state. If a user restores an older channel.db and starts lnd, lnd publishes old channel state. The peer then takes the channel funds through the penalty path. lnd's own guidance is to recover from the seed plus channel.backup, and never from a copied channel.db. The backups module makes that path look normal: the whole directory is in the backup and the docs don't warn.

The test in test/tests.py stops bitcoind before it starts duplicity and checks only that hsm_secret, lnd-seed-mnemonic and wallet.dat are present. It doesn't cover the live-copy case for lnd or clightning.

Proposal

  • lnd: exclude channel.db from the backup (- ${lnd.dataDir}/chain/*/channel.db style line before the include) or document that the lnd part of the backup is for lnd-seed-mnemonic, channel.backup and tls.* only. channel.backup is safe to copy live. lnd rewrites it atomically.
  • clightning: point users to services.clightning.replication, which this repo already has, for the database. Keep hsm_secret in the duplicity backup.
  • docs: add a short warning to the backups section of docs/services.md: never restore a copied channel.db or lightningd.sqlite3 to a node that was online after the copy. Use the seed and channel.backup for lnd and the replication module for clightning.
  • test: check that the backup doesn't contain channel.db.

I can send a PR for the exclude lines and the docs if you want it.

Activity

  1. ostermayer commented on Oct 17, 2026

    @ostermayer
    CollaboratorAuthor

    Astra's grading of a later run on the same commit pointed at one more live copy. modules/backups.nix line 63 includes the whole bitcoind data directory, so the wallet databases are copied while bitcoind runs, without backupwallet. Same fix shape as above: stop the service or use the daemon's own backup call. LLM review (Kimi K3 max, GLM 5.3 max, GPT-6 Astra xhigh) flagged this. I verified it against the code.

  2. added
    area: modules
    type: bug
    on Oct 23, 2026
  3. added 2 commits that reference this issue on Nov 18, 2026
    6ad3427
    8d18c0e
  4. added a commit that references this issue on Nov 18, 2026
    3b50f0a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: modulestype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions