Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgresql backup #314

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

sivertism
Copy link
Contributor

@sivertism sivertism commented Oct 6, 2024

Postgresql backup

Hi, thought I'd have a go at enabling backups for postgresql, as it stores a lot of important data, for example for Nextcloud.

I'm not sure what the best way to do it is, so below are some of my thoughts.

One-shot backup vs per-service backup

I suppose there are many ways to set up the backup, but the simplest seems to be pg_dumpall which dumps all tables, schema, users etc. into an SQL file which can be piped back to psql to reproduce the DB. This is nice because it is simple, and because users etc. are preserved. It's also pretty nice for services that don't really have any state but their database -- they get backups for free.

Another way to do it would be to have each service back up its own database, i.e. nextcloud uses pg_dump to back up only the nextcloud database. The main advantage here, I suppose, is that the database dumped for nextcloud is (probably) in sync with the nextcloud backup. The main drawback is that it's a lot more code to set up, as it'd have to be done for all relevant services, and I'm guessing that restoring from backup might be a bit more challenging. At the very least, we'd have to restore from many backed up sql files.

Existing nixpkgs service

There is an existing service for backup from postgresql, but I thought it was better to use our own script. Both because it is very simple, and because it's easier to align the pg_dump with restic backups using the backup contract hooks.

Implementation and testing

I haven't tested out the implementation yet, and I'm not sure whether just putting the backup script in the default for the backup option is the right way to go?

@sivertism sivertism marked this pull request as draft October 6, 2024 10:04
@sivertism sivertism changed the title initial attempt Postgresql backup Oct 6, 2024
@ibizaman
Copy link
Owner

ibizaman commented Oct 7, 2024

I’ll need to look into more details and play with it but the general idea is what I had in mind indeed. Thank you for putting in the work!

@ibizaman ibizaman added this to the 1.0.0 milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants