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

Closed
wants to merge 1 commit into from
Closed

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
@ibizaman
Copy link
Owner

I continued your work in PR #344

I adapted it to use the new database backup contract. Sorry I couldn't continue on your PR but I can't add commits in your fork.

@ibizaman ibizaman closed this Nov 12, 2024
@sivertism
Copy link
Contributor Author

That's great, thank you! I'll try it out when I've got time to play with the server again 👍

ibizaman added a commit that referenced this pull request Nov 12, 2024
This PR continues the work started in
#314

I had to create my own PR since I couldn't add commits on the fork.

---------

Co-authored-by: sivertism <[email protected]>
@ibizaman
Copy link
Owner

Btw I'm working on better documentation, mostly helping readers in setting up their system, so hopefully that will help you too when you get to it.

@inayet
Copy link

inayet commented Nov 14, 2024

Hi @ibizaman and @sivertism thank you to both of you for continuously improving selfhostblocks!

Qq - Will the docs be updated automatically where there are changes noted in CHANGELOG.md https://github.com/ibizaman/selfhostblocks/blob/main/CHANGELOG.md ?

I found this cool tool that is old but still being developed primarily used for Python development called nbdev https://github.com/fastai/nbdev where the docs and code are interlinked the best way I can describe it that documentation changes when the code changes. However I don't know if nbdev can be used / ported over to nix* ecosystem. Or does nix* have their own version of nbdev?

I think such tool would be great to use so that when something is changed the rest of the docs/code is updated so that when new comers starts to play with selfhostblocks they are *not derailed because of changes that happened and were not noted or updated in other areas of the docs/code

@ibizaman
Copy link
Owner

ibizaman commented Nov 14, 2024

@inayet actually the documentation on https://shb.skarabox.com is generated from the code! The top-level file is https://github.com/ibizaman/selfhostblocks/blob/main/docs/manual.md and things get imported from there. Then when I merge a PR, this workflow gets started which ultimately deploys the documentation. I agree it's pretty cool to have that!

To develop locally, I run this command to refresh the documentation:

nix shell nixpkgs#entr --command bash -c 'find . | entr nix build .#manualHtml --offline'

Then in my browser I open the corresponding html file.

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.

3 participants