Troubleshooting
Start with bakelite doctor. It runs the same checks the daemon depends on
(backend reachable, credentials, WAL mode, key loads, file access as the replicating
account, the systemd sandbox) without changing anything, and names what failed. Then
bakelite status for what the daemon is doing now, and journalctl -u bakelite for
the full error.
Each entry below is symptom → cause → fix.
The database isn't in WAL mode
Symptom. doctor fails its WAL mode check with
PRAGMA journal_mode = delete; set PRAGMA journal_mode=WAL, or the daemon log shows
could not switch to WAL mode (journal_mode is "delete").
Cause. bakelite follows the -wal file, so the database has to use SQLite's
write-ahead log. The daemon switches a database to WAL itself on startup, but SQLite
won't change the journal mode while another connection has the database open in
rollback mode, or when the file or its directory is read-only.
Fix. Switch it once from your application, or with the app stopped:
sqlite3 /var/lib/app/app.db 'PRAGMA journal_mode=WAL;'
WAL mode persists in the file. If your application sets journal_mode on every
open, make sure it sets WAL. WAL needs shared memory, so the database must be on a
local filesystem, not NFS or SMB.
Permission denied on .bakelite/
Symptom. The daemon log or a command shows
permission denied at /var/lib/app/.bakelite/... — bakelite needs write access to the database's directory.
Under systemd you may instead see Read-only file system (os error 30) for a path
you can write to from a shell.
Cause. bakelite writes SQLite's -wal/-shm files and its own .bakelite/
directory (lock, cursor, status) beside each database, so the replicating account
needs write access to the directory, not only the file. Under the packaged unit,
ProtectSystem=strict makes everything read-only except the paths in
ReadWritePaths=; a database directory missing from that list gets EROFS.
Fix.
- Check who replicates the database: by default its file's owner (
run_as = "owner").doctorchecks access as that account. If you setrun_as, that account needs write access to the directory. - Add the database directory (and a
filebackend's directory) toReadWritePaths=.sudo bakelite init --forceregenerates the drop-in from your config; by hand, usesudo systemctl edit bakelite.doctorreports a missing or stale entry under systemd sandbox.
"Another bakelite daemon is already replicating this database"
Symptom. The daemon logs
another bakelite daemon is already replicating this database; skipping it, or
compact / prune / reencrypt stop with
another bakelite process (probably the daemon) is holding the lock at <path>; stop it first.
Cause. Each database has one exclusive lock at
<db_dir>/.bakelite/<db_file>.lock, so two daemons can't replicate the same file.
The lock is an flock, which the kernel drops when the holding process exits, so a
leftover lock file is never stale: something is running and holds it. The lock is
keyed by the file's real path, so two config entries (or a [[database]] and a
[[database_group]] glob) that reach the same file through different names or a
symlink also collide.
Fix. Find the holder with sudo lsof <lock path>. Usually it's a second daemon
(a hand-started bakelite daemon next to the systemd unit, or a second unit); stop
it. For compact, prune and reencrypt, stop the daemon first or, for prune,
let the daemon's own prune_interval do it. Don't delete the lock file to get past
the error: the holder keeps its lock, and a later process could take a second one.
S3 credentials, 403 Forbidden
Symptom. At startup:
no S3 credentials found in the environment. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in /etc/bakelite/bakelite.env.
Or doctor fails backend reachable with listing backups failed: ..., and the
error mentions 403 Forbidden, AccessDenied, InvalidAccessKeyId, or
SignatureDoesNotMatch.
Cause. bakelite reads S3 keys from the environment, loading
/etc/bakelite/bakelite.env itself at startup. A 403 means the keys were sent and
refused. The usual reasons: the wrong key pair; a region that doesn't match the
bucket; a missing endpoint for R2/B2/MinIO; an IAM policy without
s3:ListBucket on the bucket or s3:PutObject / s3:GetObject /
s3:DeleteObject on the prefix; or a host clock far enough off that signatures
expire.
Fix.
- Put the keys in
/etc/bakelite/bakelite.env(mode0600). Values already set in the environment win over the file. - To use EC2/ECS/EKS instance or role credentials, set
BAKELITE_AWS_USE_DEFAULT_CREDENTIAL_CHAIN=1. bakelite doesn't query instance metadata otherwise. - Check
endpointandregionagainst the provider's docs (S3-compatible), and attach the least-privilege policy. - Re-run
bakelite doctor --db <name>until backend reachable passes.
The backend is unreachable
Symptom. bakelite status shows backing off, with the last error and how long
it has been failing; status --check reports backing off.
Cause. A running replicator lost its backend (network down, endpoint outage, expired credentials). It retries with backoff, starting at one second and doubling to a five-minute cap. Nothing is lost while it waits: bakelite holds a read lock, so SQLite keeps the unshipped commits in the WAL until they ship. The WAL grows meanwhile, because it can't be checkpointed past what hasn't shipped.
Fix. Fix the backend. The daemon catches up on the next successful retry, with no restart needed. On a long outage, watch the WAL's size and the free space on the database's disk.
The same holds at startup. If the backend is unreachable when the daemon starts a
database (while it reads the replica's state, or uploads the first full backup),
status shows backing off with the error, and the database starts replicating on
the first retry after the backend comes back. Some startup errors don't retry,
because waiting can't fix them:
- a configuration problem;
- a replica written by a newer bakelite (see versioning);
- an encryption key that can't decrypt the replica (
the configured encryption key can't decrypt …: wrong key, or the object is corrupt/tampered), usually a replica written under a different key or passphrase; - an unencrypted replica while encryption is on with
require_encrypted(the default): runbakelite reencrypt, or setrequire_encrypted = falsewhile you migrate (see at-rest encryption).
These stop that database with the reason in status; fix the cause and restart the
daemon. A key mismatch counts only once it's certain: an object that merely arrives
damaged or incomplete is retried like any other backend failure. bakelite doctor
reports the wrong-key and unencrypted cases under replica format.
Too many databases for the OS limits
Symptom. With hundreds of databases, bakelite status shows some as
backing off, with an error such as:
file watcher error: failed to watch /srv/app: the inotify watch limit is reached (fs.inotify.max_user_watches=8192)file watcher error: failed to create the file watcher: the inotify instance limit is reached (fs.inotify.max_user_instances=128)the process file-descriptor limit is reached (RLIMIT_NOFILE=1024), or SQLite'sunable to open database filewhen a database is opened
Cause. Each database holds about five open files, and on Linux each database
directory takes one inotify watch. The kernel caps open files per process
(RLIMIT_NOFILE) and inotify watches per user (fs.inotify.max_user_watches).
bakelite uses one inotify instance per daemon or worker process, however many
databases it runs, so the instance error means other programs running as the same
user have used up fs.inotify.max_user_instances.
Nothing is lost while this lasts. A database without a watcher still replicates, on
the safety_poll timer (30 seconds by default) instead of on every commit. A
database that couldn't be opened retries on its own, after 1 second at first and
backing off to every 5 minutes. Both recover without a restart once the limit
allows.
Fix. The packaged unit sets LimitNOFILE=1048576, and the daemon raises its soft
open-file limit to the hard limit at startup. The fd limit only bites under a
hand-written unit or a shell with a low hard limit: add LimitNOFILE=1048576 to the
unit, or raise ulimit -Hn. Raise the inotify limits with:
sudo tee /etc/sysctl.d/90-bakelite-inotify.conf <<'EOF'
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 524288
EOF
sudo sysctl --system
bakelite doctor warns when these limits are too low for the databases in the
config. Putting many databases in one directory uses one watch for all of them. See
Running many databases for sizing.
The restore point is before the earliest backup
Symptom. bakelite restore --timestamp ... (or --index) fails with
restore error: no snapshot available to restore from.
Cause. A restore starts from the newest full backup at or before the target. If
the target is earlier than every full backup still kept, because retention or
max_backups / max_total_size pruned the older ones, or because the target predates
the first backup, there's nothing to start from. The same error on a plain
restore means the replica has no backups yet.
Fix. Run bakelite list --db <name> to see the restorable spans, and pick a time
inside one. To keep older points restorable, lengthen retention (or raise the size
and count caps). A pruned backup can't be recovered.
status --check fails on lag or verify age
Symptom. bakelite status --check (or the bakelite-check.timer unit) exits
non-zero with lines such as:
UNHEALTHY (1 database(s)):
- app: lag 14m > 10m
- app: last clean verify 2d ago > 36h
Other reasons it prints: backing off, stale, stopped, not running,
never verified, last verify found problems, and mirror <label> failing: ....
Cause and fix, per reason:
lag ... > ...— the newest commit in the WAL hasn't shipped withinmax_lag. The daemon is up but behind: backing off on a backend error (see above), or writes outpacing uploads.bakelite statusshows which. If the lag is expected (a big bootstrap, a slow link), raise[checks] max_lag.last clean verify ... ago > .../never verified— no verify has passed withinmax_verify_age. Either verify isn't scheduled (set[checks] verify, ormax_verify_agewithoutverifyhas nothing feeding it), or it's failing: look for the verify job in the daemon log, or runbakelite verify --db <name>by hand. A newly configured database readsnever verifieduntil its first job, about five minutes after the daemon starts.last verify found problems— verify ran and found damage. Runbakelite verify --db <name>for the details; with two or more destinations,bakelite repair --db <name>heals copies that are bad on one destination and good on another.stale/not running/stopped— the daemon (or this database's replicator) isn't running. Checksystemctl status bakeliteand the journal.mirror ... failing— anasyncmirror's last pass errored, usually credentials or an unreachable endpoint for that destination. Replication to thesyncdestinations is unaffected.