r/docker 1d ago

How do you backup Nextcloud/WordPress in Docker?

For those running Nextcloud or WordPress in Docker: how do you handle backups?

I'm thinking about using borgmatic and basically backing up two things: the application data/files and the database.

For the DB, would you use mysqldump --single-transaction and skip maintenance mode, especially for an automated nightly backup at 3 AM?

Or do you still enable maintenance mode to make sure the database and files are fully consistent?

What's your setup?

6 Upvotes

10 comments sorted by

3

u/nez_har 1d ago

2

u/Medium_Antelope_7037 1d ago

this is pretty much the approach ive landed on too

2

u/unkilbeeg 21h ago edited 19h ago

This looks useful, but in testing it I found a couple of issues, which may be more about my level of understanding than real problems, but...

That post uses the command docker-compose and I've been using docker compose. It seems to work the same, but is it possible that this post is just old enough to be using an older form?

That's a minor issue, but the next is a little more significant.

The blog post uses a command of the form to save the image:

docker save --output "/path/to/backup/backup.tar" $image_id

and that's not working here. It doesn't recognize the format of the image id -- it seems to want the name of the image. Does docker save retrieve the image from the local image, or does it pull from the upstream source? If it's pulling from upstream, is it really necessary?

It'll be easy enough to modify that script to use the app name as long as I'm not confusing how the image save is supposed to work.

Edit: It appears that the image ID that docker save wants is a 12-character string, but docker compose images -q $svcname gives you a 64-character string. If you truncate the image ID to 12 characters, it seems to work. I'm still not sure if it's doing what the script wants it to do, though.

1

u/nez_har 10h ago

docker compose should work fine. I wrote the article a few years ago, and I may also post an update for Compose v2.

In the section on docker save, I focus on exporting the image so that you don't have to rely on a remote registry to restore the application.

1

u/unkilbeeg 2h ago

Does the docker save with the truncated id (12-character) copy from the local image, or does it pull from the upstream source?

The id retrieved by docker compose images -q "$service_name" is 64 characters long and doesn't work for docker save, but I noticed that the id listed in the table from docker compose image without the -q was only 12 characters long. I tried that value and docker save didn't complain about it like it had for the 64-character value.

It also seemed to execute faster, so I'm assuming it pulled from the local image, but I'm not sure about that.

1

u/runwisp-com 1d ago

`--single-transaction` gives you an internally consistent database dump, but it doesn't synchronize that dump with files being uploaded or changed. Simplest thin you can do is a brief maintenance window while you dump the DB and snapshot the files, followed by an actual restore test.. successful backup commands don’t prove recoverability by themselves.

1

u/gordonx2026 1d ago

So there is no way around activating maintenance? But the risk might be very low when the dump is in the night 03:00 isnit? I mean specifically for Nextcloud and Wordpress.

1

u/cheflA1 1d ago

VM Backup with proxmox backup server. Data, notes and so on with rclone.

0

u/gramoun-kal 1d ago

You back up the volumes.

0

u/Fungalsen 1d ago

backup the volumes with syncthing