top | item 37801252

(no title)

lucas_codes | 2 years ago

How do people usually backup their self-hosted docker services using postgres? I have been using docker-volume-backup [0] and just saving the postgres data directory, but I've found it requires a minute of downtime to backup properly.

[0] https://github.com/offen/docker-volume-backup

discuss

order

poorlyknit|2 years ago

pg_dump [0] (or pg_dumpall, linked there) sounds like what you want to use. You could docker exec into the postgres container, then copy the dump from the volume to your backup location on the host.

A bit more contrived than copying the volume but you don't need to shut down the server. There's probably some scripts out there for doing this in a structured way but I usually do it more or less manually/use a bash script.

[0]: https://www.postgresql.org/docs/current/app-pgdump.html

jhot|2 years ago

docker-compose --env-file .env exec postgres /usr/bin/pg_dump -U postgres "$db_name" | gzip -9 > "$BACKUP_ROOT/postgres/${NOW}.${db_name}.sql.gz"

darnir|2 years ago

Specifically in the case of paperless-ngx, I use their export facility from a cron job. The export is plaintext and contains all the information needed to recreate the postgres db and the learned identifiers. In case of a disk failure (and I've had one with my paperless store), I just reimported the previous days backup from my offline backup of paperless' export.

andix|2 years ago

For now I only backuped some databases with a pg_dump one liner triggered from a cron job on the docker host (via docker exec or docker run --rm). No idea how this scales for big databases. But for your regular home server <10 GB databases this should just work.

asmor|2 years ago

restic container with all volumes mounted to /backup/<volumename> (and . to /backup/self - use named volumes, not binds) in my composefile with scale 0 and a backup.sh that's essentially

docker compose down && docker compose run backup && docker compose up -d

The restore procedure is the same, you restore the composefile through restic on the host and then `docker compose run backup restic restore latest --exclude "/data/self/*" --target /`

I find it's fast enough because restic is incremental, but if you can set this up on a filesystem with snapshots that would be a great option too.

Restic takes a bit of fiddling around too. I mount a prepared ssh config, a known hosts file and a private key.

mastax|2 years ago

ZFS snapshots