Database restore hooks for PostgreSQL #229

Closed
opened 2019-10-22 23:23:15 +00:00 by witten · 2 comments
Owner

What I'm trying to do and why

For a real killer feature, the database hook feature begun in #225 could also trigger during borgmatic extract. Specifically, it could restore your databases from dumps.. and not just extract your plain files! So if you're restoring on a completely fresh system, you could get up and running relatively quickly—including your databases—without no manual work.

Other notes / implementation ideas

For safety reasons, database restores should probably not be completely automatic when running borgmatic extract, because then it'd be easy to accidentally destroy or replace a production database. Instead, you should have to provide an explicit command-line flag to borgmatic extract that explicitly requests a database to restore (or "all"). Or maybe there should be a completely separate sub-command: borgmatic restore-postgresql.

Another consideration: When restoring, it may be necessary to include explicit support for restoring to a host other than the one that a database dump originally came from. That's because the original database host may be toast, and the user is trying to spin up a new replacement host with a different hostname. In that case, a --rewrite-hostname flag may be necessary.

Another: Should there be a way to pass arbitrary arguments through from borgmatic restore to pg_restore?

Yet another thought: If, during restores, borgmatic relies on databases being defined in the borgmatic configuration file, then that poses a bit of a problem: The user may not have backed up /etc/borgmatic/config.yaml, and yet may still want to restore their databases. Two different ideas on how to deal with this:

  1. Implement a general-purpose feature for borgmatic to backup its own configuration file(s), e.g. to ~/.borgmatic/config.yaml / ~/.borgmatic/borgmatic.d/. (This would be part of a separate ticket.) Note that there are security implications to think through here, since config file can contain credentials. Then, when restoring a database, optionally first restore a config file so that the databases are known and configured.

  2. Alternatively, when writing a database dump into ~/.borgmatic/postgresql_databases/..., also write out metadata about the database into a separate file (hostname, username, password(?), etc.) alongside the dump. That way, during restore, if borgmatic's config file isn't configured for any databases, you still have the connection metadata necessary to restore a given database!

#### What I'm trying to do and why For a real killer feature, the database hook feature begun in #225 could also trigger during `borgmatic extract`. Specifically, it could restore your databases from dumps.. and not just extract your plain files! So if you're restoring on a completely fresh system, you could get up and running relatively quickly—including your databases—without no manual work. #### Other notes / implementation ideas For safety reasons, database restores should probably not be completely automatic when running `borgmatic extract`, because then it'd be easy to accidentally destroy or replace a production database. Instead, you should have to provide an explicit command-line flag to `borgmatic extract` that explicitly requests a database to restore (or "all"). Or maybe there should be a completely separate sub-command: `borgmatic restore-postgresql`. Another consideration: When restoring, it may be necessary to include explicit support for restoring to a host other than the one that a database dump originally came from. That's because the original database host may be toast, and the user is trying to spin up a new replacement host with a different hostname. In that case, a `--rewrite-hostname` flag may be necessary. Another: Should there be a way to pass arbitrary arguments through from `borgmatic restore` to `pg_restore`? Yet another thought: If, during restores, borgmatic relies on databases being defined in the borgmatic configuration file, then that poses a bit of a problem: The user may not have backed up `/etc/borgmatic/config.yaml`, and yet may still want to restore their databases. Two different ideas on how to deal with this: 1. Implement a general-purpose feature for borgmatic to backup its own configuration file(s), e.g. to `~/.borgmatic/config.yaml` / `~/.borgmatic/borgmatic.d/`. (This would be part of a separate ticket.) Note that there are security implications to think through here, since config file can contain credentials. Then, when restoring a database, optionally first restore a config file so that the databases are known and configured. 2. Alternatively, when writing a database dump into `~/.borgmatic/postgresql_databases/...`, also write out metadata about the database into a separate file (hostname, username, password(?), etc.) alongside the dump. That way, during restore, if borgmatic's config file isn't configured for any databases, you still have the connection metadata necessary to restore a given database!
Author
Owner

Yet another thought: If, during restores, borgmatic relies on databases being defined in the borgmatic configuration file, then that poses a bit of a problem

Decided to just document around this for now: Encouraging users to backup their borgmatic configuration files.

> Yet another thought: If, during restores, borgmatic relies on databases being defined in the borgmatic configuration file, then that poses a bit of a problem Decided to just document around this for now: Encouraging users to backup their borgmatic configuration files.
Author
Owner

Released in 1.4.1.

Released in 1.4.1.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#229
No description provided.