Skip to content

Durability & backup

FileDB lets you trade write throughput against your crash-loss window with the --sync flag:

ModeBehaviourTrade-off
noneRely on the OS to flush pages.Fastest; loses the last unflushed writes on a crash.
intervalfsync on a timer (--sync-interval, default 1s).Balanced; bounded loss window.
alwaysfsync on every write.Safest; slowest.

The embedded façade (filedb.Open) defaults to interval (~1s) — a sensible middle ground for in-process use.

  • Writes are append-only — nothing is modified in place, so a crash mid-write can only ever leave a torn trailing line, never corrupt existing data.
  • Every segment entry carries a CRC32C checksum. On read, a mismatch is reported rather than silently returning wrong data — so on-disk bit-rot is caught, not propagated.
  • The in-memory id index is persisted with its own checksum for fast, verified restarts.

filedb-cli backup streams a consistent gzip snapshot of the live database — no need to stop the server:

Terminal window
filedb-cli backup --out filedb-$(date +%F).tar.gz --api-key dev-key

Restore is deliberately boring — it’s just a tarball:

Terminal window
tar xzf filedb-2026-07-10.tar.gz -C ./restored-data
filedb serve --data ./restored-data --api-key dev-key

A background goroutine per collection merges and deduplicates sealed segments, reclaiming space from superseded and expired records. It kicks in on an interval (--compact-interval, default 5m) or when the dirty ratio crosses --compact-dirty (default 0.30). Operators can also force a synchronous pass:

Terminal window
filedb-cli compact users --api-key dev-key