Self-Hosting · Backups

Backing Up the Databases Inside Your Self-Hosted Apps

Most self-hosted apps keep their soul in a database: your Paperless index, your Immich library metadata, your Vaultwarden vaults. And the most common way people “back up” those apps — copying the container’s data folder while it runs — produces files that may not restore. This guide covers the correct tool for each database you’ll meet, how to schedule it, and how to prove the backup works before you need it.

Published Nov 20, 2026

Why copying the folder is not a backup

A running database holds recent writes in memory and in a write-ahead log, and it updates its files constantly. A file copy taken mid-flight captures an inconsistent slice — sometimes usable after crash recovery, sometimes not, and you find out which during the restore, which is the worst possible time. Databases ship their own backup tools precisely because a consistent backup has to be coordinated with the engine. The rule is simple: logical dump with the database’s own tool, or stop the database and copy cold. There is no third option that deserves the name backup.

PostgreSQL: pg_dump

Postgres is the database behind Immich, Paperless-ngx (in its common configuration), and many others. Its tool is pg_dump, which produces a consistent snapshot while the database keeps serving. In Docker, run it through the database container itself: docker exec <db-container> pg_dump -U <user> <database> and redirect the output to your backup location, ideally compressed. Use pg_dumpall when you also need users and roles (a full-cluster restore does). Schedule it nightly for busy apps; the dumps are small next to the media they describe. Our TrueNAS migration guide shows the failure mode this prevents: an app whose database lived outside its expected backup path, discovered mid-migration.

MariaDB and MySQL: mariadb-dump

Nextcloud’s common stack and many older apps use MariaDB. The equivalent tool is mariadb-dump (long invoked as mysqldump; MariaDB renamed its tools, and current versions use the new name). The flag that matters is --single-transaction, which takes a consistent InnoDB snapshot without locking the app out of its tables. As with Postgres, execute it inside the database container and store the output with the app’s other backup data.

SQLite: the .backup command, not cp

A long tail of apps — smaller tools, dashboards, single-file services — use SQLite, where the database is one file and the temptation to just copy it is strongest. SQLite provides the safe path: the .backup command in the sqlite3 shell, or VACUUM INTO 'file' in SQL, both of which produce a consistent copy from a live database using its own locking. If the app is stopped, a plain file copy is fine — cold copies are always fine. What is not fine is copying the lone .db file of a running app while ignoring its -wal companion; that pair is exactly how restores lose the last day of data.

Some apps want their own export

A few applications treat their database as an internal detail and offer a supported export instead — use it when it exists. Home Assistant’s backup system, Vaultwarden’s vault export (as a supplement, not a replacement), and Immich’s documented database dump procedure all fall in this family. The pattern to build: for every app you run, one line in your documentation naming where its irreplaceable data lives and which of these three methods covers it. Apps whose data is only media files (Jellyfin’s library, for instance) need their config folder, not a database strategy — know which kind each app is.

Scheduling and proving it

Wire the dumps into the same schedule as the rest of your backups — a small script or a dedicated backup container that runs the dumps first, then lets your normal tool (restic, Kopia, Duplicati; see our restic/Kopia guide) sweep the results offsite. Keep dumps for longer than feels necessary; they are tiny. Then do the part everyone skips: restore one dump into a throwaway container twice a year and open the app against it. A pg_dump that has never been restored is a hypothesis. Our 3-2-1 guide covers where these dumps sit in the wider strategy, and the drill guide turns the restore test into a routine.

Official documentation and references

Frequently asked questions

Can’t I just stop all my containers at night and copy everything?

You can — a cold copy is a valid backup, and for a small stack a nightly stop-copy-start script is a legitimate simple strategy. Its costs are downtime during the window and all-or-nothing scheduling. Logical dumps avoid both and scale better as the stack grows, which is why they are the default recommendation; but a cold copy you actually run beats a dump system you never finished setting up.

How often should I dump my databases?

Nightly is the sensible default for apps that change daily (photos, documents, passwords). Weekly is acceptable for slow-changing tools. Tie the dump schedule to the backup schedule so dumps never sit only on the same disk as the live database — a dump that dies with the host is not a backup.

Where should dumps be stored?

With the rest of the app’s backup set, then copied off the machine by your backup tool: another local device and one offsite or cloud copy, per the 3-2-1 pattern. Keep several generations — database corruption is often discovered days after it happened, and yesterday’s dump may already contain it.

How do I know if an app uses Postgres, MariaDB, or SQLite?

Check its Compose file: a separate db/database service means Postgres or MariaDB (the image name tells you which), while no database service usually means SQLite inside the app container or a file in its data folder. The app’s documentation almost always has a backup page naming its database — read it before choosing a method.

Related guides