How to back up Nextcloud in Docker (2026)
Backing up Nextcloud means capturing three layers at once: a consistent dump of its MariaDB, PostgreSQL and MySQL databases, the 2 data volumes where files live, and the compose/.env config. Dockstash scans the stack, runs the right dump command, and restics every layer to your storage VPS.
What Nextcloud stores
| Compose services | nextcloud, mariadb, redis |
|---|---|
| Databases detected | mariadb, postgres, mysql |
| Data volumes | nextcloud_data (/var/www/html/data), db_data (/var/lib/mysql) |
| Config paths | docker-compose.yml, .env, config/config.php |
The backup plan
- Enable maintenance mode (recommended). Put Nextcloud into maintenance mode (occ maintenance:mode --on) so files and database stay consistent with each other during the backup window.
- Dump the database. Run mariadb-dump/mysqldump --single-transaction (or pg_dumpall for a Postgres backend) to capture file metadata, shares, and user accounts consistently.
- Capture the data directory and config. Restic the nextcloud_data volume (all user files) and config/config.php plus .env. File contents on disk must match the metadata in the database dump.
Restoring Nextcloud
Nextcloud file metadata in the database must match the files on disk — back up both under maintenance mode. Restore config.php with the same instanceid, secret, and passwordsalt or the instance rejects the data.
Back up Nextcloud in one click All guides
Last updated: July 2026
Frequently asked questions
Do Nextcloud files and database need to be consistent?
Yes. The database holds file metadata, shares, and sync state; the data directory holds the actual files. If they drift, sync breaks. Back them up together, ideally under maintenance mode.
Which database does Nextcloud use?
Commonly MariaDB or MySQL, sometimes PostgreSQL. Dockstash detects which and dumps it correctly — --single-transaction for MariaDB/MySQL or pg_dumpall for Postgres.
What in config.php matters for restore?
The instanceid, secret, and passwordsalt values. Restore them exactly or Nextcloud will not decrypt existing data or accept the restored database.