Optionally pass through PostgreSQL environment variables in database hook #370

Closed
opened 2020-11-18 18:53:42 +00:00 by witten · 4 comments
Owner

Reported by hugokernel on IRC.

What I'm trying to do and why

Backup a database with borgmatic via the PostgreSQL database hook, passing through some of the credentials or connection information via PG* environment variables so that I don't have to specify them in borgmatic's configuration file.

Perhaps I'm using Docker and environment variables are more convenient for this purpose. Perhaps I already have them in the environment for some other usage. Perhaps I have several databases with the same settings or credentials, and I don't want to have to repeat the configuration for each one in borgmatic's database hook.

Other notes / implementation ideas

Any existing PG* environment variables are not passed through from borgmatic to PostgreSQL today because PGSSLMODE is set unconditionally in the new environment that borgmatic passes to PostgreSQL: https://projects.torsion.org/witten/borgmatic/src/branch/master/borgmatic/hooks/postgresql.py#L25

Adding a conditional around that line would make the environment empty, which would pass env=None to the PostgreSQL call, which would in effect default to borgmatic's own environment.

Reported by `hugokernel` on IRC. #### What I'm trying to do and why Backup a database with borgmatic via the PostgreSQL database hook, passing through some of the credentials or connection information via `PG*` environment variables so that I don't have to specify them in borgmatic's configuration file. Perhaps I'm using Docker and environment variables are more convenient for this purpose. Perhaps I already have them in the environment for some other usage. Perhaps I have several databases with the same settings or credentials, and I don't want to have to repeat the configuration for each one in borgmatic's database hook. #### Other notes / implementation ideas Any existing `PG*` environment variables are not passed through from borgmatic to PostgreSQL today because `PGSSLMODE` is set unconditionally in the new environment that borgmatic passes to PostgreSQL: https://projects.torsion.org/witten/borgmatic/src/branch/master/borgmatic/hooks/postgresql.py#L25 Adding a conditional around that line would make the environment empty, which would pass `env=None` to the PostgreSQL call, which would in effect default to borgmatic's own environment.
Author
Owner

Some relevant discussion with a related proposal on #546.

Some relevant discussion with a related proposal on #546.
Author
Owner

There's a new feature implemented as part of #546 for environment variable interpolation, very related to this ticket although not exactly the same. See the documentation at https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/

There's a new feature implemented as part of #546 for environment variable interpolation, very related to this ticket although not exactly the same. See the documentation at https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/
witten added the
good first issue
label 2023-02-04 21:26:22 +00:00
Author
Owner

Well this took an embarrassingly long time to implement. Fixed in main.

Well this took an embarrassingly long time to implement. Fixed in main.
Author
Owner

Released in borgmatic 1.8.8!

Released in borgmatic 1.8.8!
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#370
No description provided.