pg_dump_command: need detailed explanation #1020

Closed
opened 2025-03-08 20:34:06 +00:00 by gander · 4 comments

What I'm trying to do and why

Configure pg_dump_command to dump from the PostgreSQL container, since I can't update the PostgreSQL client.

Steps to reproduce

First attempt, exactly as in the documentation:

pg_dump_command: docker exec my_pg_container pg_dump

Second attempt, with attaching my configuration directory (I am using borgmatic.d)

pg_dump_command: docker run --rm -v /home/user/.config/borgmatic.d:/home/user/.config/borgmatic.d postgres:17-alpine pg_dump

Third attempt, with attaching the directory with the default configuration location:

pg_dump_command: docker run --rm -v /home/user/.config/borgmatic:/home/user/.config/borgmatic postgres:17-alpine pg_dump

And so on, I also tried with ~/.pgpass in host, in the container, still no success.

Actual behavior

An error occurred
Error running actions for repository
pg_dump: error: connection to server at "<REDACTED>" (<REDACTED>), port <REDACTED> failed: fe_sendauth: no password supplied
Command 'docker run --rm postgres:17-alpine pg_dump --no-password --clean --if-exists --host <REDACTED> --port <REDACTED> --username <REDACTED> --no-owner --format custom <REDACTED> > /run/user/<REDACTED>/./borgmatic/postgresql_databases/<REDACTED>/<REDACTED>' returned non-zero exit status 1.

Expected behavior

backup without error

Other notes / implementation ideas

I finally started debugging this configuration and found that all I had to do was do it this way to make it work:

pg_dump_command: docker run --rm -e PGPASSWORD postgres:17-alpine pg_dump

In my opinion, the documentation needs to explain in more detail how the password is passed to the tool (environment variable) and, for the docker example, add passing this environment variable through this option -e PGPASSWORD.

borgmatic version

1.9.13

borgmatic installation method

pipx install borgmatic

Borg version

1.4.0

Python version

3.11.4

Database version (if applicable)

17.3

Operating system and version

Ubuntu 23.04

### What I'm trying to do and why Configure `pg_dump_command` to dump from the PostgreSQL container, since I can't update the PostgreSQL client. ### Steps to reproduce First attempt, exactly as in the documentation: ``` pg_dump_command: docker exec my_pg_container pg_dump ``` Second attempt, with attaching my configuration directory (I am using borgmatic.d) ``` pg_dump_command: docker run --rm -v /home/user/.config/borgmatic.d:/home/user/.config/borgmatic.d postgres:17-alpine pg_dump ``` Third attempt, with attaching the directory with the default configuration location: ``` pg_dump_command: docker run --rm -v /home/user/.config/borgmatic:/home/user/.config/borgmatic postgres:17-alpine pg_dump ``` And so on, I also tried with `~/.pgpass` in `host`, in the `container`, still no success. ### Actual behavior ``` An error occurred Error running actions for repository pg_dump: error: connection to server at "<REDACTED>" (<REDACTED>), port <REDACTED> failed: fe_sendauth: no password supplied Command 'docker run --rm postgres:17-alpine pg_dump --no-password --clean --if-exists --host <REDACTED> --port <REDACTED> --username <REDACTED> --no-owner --format custom <REDACTED> > /run/user/<REDACTED>/./borgmatic/postgresql_databases/<REDACTED>/<REDACTED>' returned non-zero exit status 1. ``` ### Expected behavior backup without error ### Other notes / implementation ideas I finally started debugging this configuration and found that all I had to do was do it this way to make it work: ``` pg_dump_command: docker run --rm -e PGPASSWORD postgres:17-alpine pg_dump ``` In my opinion, the [documentation](https://torsion.org/borgmatic/docs/reference/configuration/) needs to explain in more detail how the password is passed to the tool (environment variable) and, for the docker example, add passing this environment variable through this option `-e PGPASSWORD`. ### borgmatic version 1.9.13 ### borgmatic installation method pipx install borgmatic ### Borg version 1.4.0 ### Python version 3.11.4 ### Database version (if applicable) 17.3 ### Operating system and version Ubuntu 23.04
Owner

Thanks for bringing this to my attention! I'm glad to hear you've got things working on your system now, but I'm not sure why it wasn't working to begin with. For instance, when I run a PostgreSQL container like this:

podman run -it --rm -p 5432:5432 -e POSTGRES_USER=test -e POSTGRES_DB=test -e POSTGRES_PASSWORD=pass --name postgresql docker.io/postgres:14.3

... and then exec into it like this:

podman exec -it postgresql bash
pg_dump --username test --format custom

... then I get the full database dump without being prompted for a password. Which is similar to the series of steps that borgmatic does when configured with pg_dump_command: docker exec postgresql pg_dump. My understanding is that the database password is not needed because exec-ing in bypasses that. From the docs:

Note 1: The PostgreSQL image sets up trust authentication locally so you may notice a password is not required when connecting from localhost (inside the same container). However, a password will be required if connecting from a different host/container.

So I'm not sure what's going wrong on your system. Can I get a look at the error you get when docker exec ... is configured in borgmatic? And what about exec-ing in and running pg_dump manually? Also, are you setting POSTGRES_PASSWORD when creating your PostgreSQL container?

Thanks for bringing this to my attention! I'm glad to hear you've got things working on your system now, but I'm not sure why it wasn't working to begin with. For instance, when I run a PostgreSQL container like this: ```bash podman run -it --rm -p 5432:5432 -e POSTGRES_USER=test -e POSTGRES_DB=test -e POSTGRES_PASSWORD=pass --name postgresql docker.io/postgres:14.3 ``` ... and then exec into it like this: ```bash podman exec -it postgresql bash pg_dump --username test --format custom ``` ... then I get the full database dump without being prompted for a password. Which is similar to the series of steps that borgmatic does when configured with `pg_dump_command: docker exec postgresql pg_dump`. My understanding is that the database password is not needed because exec-ing in bypasses that. From [the docs](https://github.com/docker-library/docs/blob/master/postgres/README.md#postgres_password): > Note 1: The PostgreSQL image sets up trust authentication locally so you may notice a password is not required when connecting from localhost (inside the same container). However, a password will be required if connecting from a different host/container. So I'm not sure what's going wrong on your system. Can I get a look at the error you get when `docker exec ...` is configured in borgmatic? And what about exec-ing in and running `pg_dump` manually? Also, are you setting `POSTGRES_PASSWORD` when creating your PostgreSQL container?
Author

I don't have a postgres container locally. I connect to a database on another server. However, I need to use the postgres container with the pg_dump client to connect to that database.

I don't have a postgres container locally. I connect to a database on another server. However, I need to use the postgres container with the pg_dump client to connect to that database.
Owner

Ah okay that makes more sense! I'll see if I can work this use case into the documentation.

Ah okay that makes more sense! I'll see if I can work this use case into the documentation.
Owner

Okay, I attempted to document this use case here:

https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#containers

Those new docs should get deployed shortly.

Thanks for the suggestion!

Okay, I attempted to document this use case here: https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#containers Those new docs should get deployed shortly. Thanks for the suggestion!
Sign in to join this conversation.
No milestone
No assignees
2 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#1020
No description provided.