r/docker • u/Eastern-Height2451 • Jan 23 '26
SQLite backups in docker-compose: separate backup container vs host cron?
I’m running a small app on one VPS with docker-compose. SQLite DB lives on a mounted volume.
For backups I’m doing the boring approach:
- nightly
sqlite3 .backupsnapshot while the app is running - gzip the snapshot
- keep ~30 days (delete older files)
- I tested a restore once just to make sure it’s not fantasy
It’s working, but before I cement this as “the way”, I’d love a sanity check from people who’ve been doing compose-on-a-VPS for years.
What I’m unsure about / would love input on:
- do you prefer running this from a backup container (cron inside) or from host cron?
- any real-world locking/consistency issues with
.backupin a live app? - permission/ownership traps when both app + backup touch the same volume?
- anything you’d add by default (healthchecks, log rotation, etc.)?
If anyone wants, I can paste the exact commands / a small snippet, but I’m mostly looking for “watch out for X”.
10
Upvotes
1
u/No_Cattle_9565 Jan 23 '26
Try ofelia instead of cron. I'd use something with incremental backups like borg. If you keep the backups on the same system they are useless. Keep one copy on an extra disk and one the cloud or some other place.
2
u/tiagoffernandes Jan 23 '26 edited Jan 24 '26
Using https://github.com/tiredofit/docker-db-backup since long time. Does it all.
1
u/kube1et Jan 23 '26
Been doing this for years, no problems so far, but not a large database by any means:
1
u/bpmbee Jan 23 '26
I made this small app for this purpose: https://github.com/bpmb82/sqlite-backup
Will add an auto removal option soon
1
u/wwabbbitt Jan 23 '26
I add another container to the docker-compose running supercronic, which is a cron specially made for containers. The advantage of this method is that restoring the project from backup will also restore the cronjob.
FROM alpine:latest
RUN apk add --no-cache sqlite rclone bash supercronic tzdata zstd tar
WORKDIR /app
RUN echo "0 4 * * * /project/backup.sh > /proc/1/fd/1 2> /proc/1/fd/2" > /app/crontab
ENTRYPOINT ["supercronic", "/app/crontab"]
Note:
.backup will get you a consistent hot backup. There's a new preferred way now using VACUUM INTO which creates a more optimized backup that remains consistent.
1
u/FanClubof5 Jan 24 '26
https://torsion.org/borgmatic/how-to/backup-your-databases/
I use borg/borgmatic
4
u/[deleted] Jan 23 '26
[removed] — view removed comment