pg_dump in directory format can't be done if extracted using docker exec #978

Closed
opened 2025-01-24 16:58:53 +00:00 by vitoyucepi · 5 comments

What I'm trying to do and why

I was just curious and tried to test pg_dump for #975.

postgresql_databases:
  - name: postgres
    username: postgres
    password: password
    format: directory
    pg_dump_command: docker exec postgres pg_dump

Steps to reproduce

  1. docker run --name database -e POSTGRES_PASSWORD=password -d postgres
  2. /etc/borgmatic.d/postgres.yaml
    repositories:
      - path: /tmp
    
    read_special: true
    
    postgresql_databases:
      - name: postgres
        username: postgres
        password: password
        format: directory
        pg_dump_command: docker exec postgres pg_dump
    
  3. borgmatic -c /etc/borgmatic.d/postgres.yaml create -v2

Actual behavior

The database tries to create dump in the database container, but borgmatic expects it in the local directory.

pg_dump: error: could not create directory "/tmp/borgmatic-aaaabbbb/./borgmatic/postgresql_databases/localhost/postgres": No such file or directory

Expected behavior

The problem is not so simple, I don't expect anything.

Other notes / implementation ideas

Add a note about this behavior in the documentation.

borgmatic version

1.9.6

borgmatic installation method

self built package in a container

Borg version

1.4.0

Python version

Python 3.12.8

Database version (if applicable)

15.2

Operating system and version

alpine:3.21

### What I'm trying to do and why I was just curious and tried to test `pg_dump` for #975. ```yaml postgresql_databases: - name: postgres username: postgres password: password format: directory pg_dump_command: docker exec postgres pg_dump ``` ### Steps to reproduce 1. `docker run --name database -e POSTGRES_PASSWORD=password -d postgres` 2. `/etc/borgmatic.d/postgres.yaml` ```yaml repositories: - path: /tmp read_special: true postgresql_databases: - name: postgres username: postgres password: password format: directory pg_dump_command: docker exec postgres pg_dump ``` 1. `borgmatic -c /etc/borgmatic.d/postgres.yaml create -v2` ### Actual behavior The database tries to create dump in the database container, but borgmatic expects it in the local directory. ``` pg_dump: error: could not create directory "/tmp/borgmatic-aaaabbbb/./borgmatic/postgresql_databases/localhost/postgres": No such file or directory ``` ### Expected behavior The problem is not so simple, I don't expect anything. ### Other notes / implementation ideas Add a note about this behavior in the documentation. ### borgmatic version 1.9.6 ### borgmatic installation method self built package in a container ### Borg version 1.4.0 ### Python version Python 3.12.8 ### Database version (if applicable) 15.2 ### Operating system and version alpine:3.21
Owner

Thanks for taking the time to file and describe this. Have you tried mounting the borgmatic runtime directory into the database container? See the docs here, which should be updated shortly with a correction about the runtime directory: https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#containers

Thanks for taking the time to file and describe this. Have you tried mounting the borgmatic runtime directory into the database container? See the docs here, which should be updated shortly with [a correction](https://projects.torsion.org/borgmatic-collective/borgmatic/commit/7551810ea60e43972d58fa725d765b08d84e590f) about the runtime directory: https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#containers
Author

tried mounting the borgmatic runtime directory

In my case this could be achieved by adding -v /tmp/borgmatic:/tmp/borgmatic to the docker run command and setting user_runtime_directory: /tmp/borgmatic. I think this would work fine, but without it I can't extract the directory from the container.

The configuration reference mentions borgmatic_runtime_directory only in one place.

borgmatic_source_directory:
type: string
description: |
Deprecated. Only used for locating database dumps and bootstrap
metadata within backup archives created prior to deprecation.
Replaced by borgmatic_runtime_directory and
borgmatic_state_directory. Defaults to ~/.borgmatic
example: /tmp/borgmatic
user_runtime_directory:
type: string
description: |
Path for storing temporary runtime data like streaming database
dumps and bootstrap metadata. borgmatic automatically creates and
uses a "borgmatic" subdirectory here. Defaults to $XDG_RUNTIME_DIR
or or $TMPDIR or $TEMP or /run/user/$UID.
example: /run/user/1001

> tried mounting the borgmatic runtime directory In my case this could be achieved by adding `-v /tmp/borgmatic:/tmp/borgmatic` to the `docker run` command and setting `user_runtime_directory: /tmp/borgmatic`. I think this would work fine, but without it I can't extract the directory from the container. The configuration reference mentions `borgmatic_runtime_directory` only in one place. https://projects.torsion.org/borgmatic-collective/borgmatic/src/commit/7551810ea60e43972d58fa725d765b08d84e590f/borgmatic/config/schema.yaml#L203-L218
Owner

I'm glad to hear it's working for you with a volume mount in place. The configuration file reference is unfortunately not exhaustive. It documents the individual options but not every use case of borgmatic. For that, the rest of the docs are needed. (Tangentially related: #942.) Please let me know though if there are any clarifications I can make to the docs so that this is easier for future users. Thanks!

I'm glad to hear it's working for you with a volume mount in place. The configuration file reference is unfortunately not exhaustive. It documents the individual options but not every use case of borgmatic. For that, the rest of the docs are needed. (Tangentially related: #942.) Please let me know though if there are any clarifications I can make to the docs so that this is easier for future users. Thanks!
Author

if there are any clarifications I can make to the docs

I'd say that 7551810e should explicitly mention that mounting the directory should be done when dumping the database in directory format. I have not experienced any problems when the format is custom.

> if there are any clarifications I can make to the docs I'd say that 7551810e should explicitly mention that mounting the directory should be done when dumping the database in directory format. I have not experienced any problems when the format is custom.
Owner

Good point! I forgot that non-directory-format dumps get conveniently exfiltrated from the database container via shell redirection. This is hopefully addressed now.

Good point! I forgot that non-directory-format dumps get conveniently exfiltrated from the database container via shell redirection. This is [hopefully addressed](https://projects.torsion.org/borgmatic-collective/borgmatic/commit/02451a8b303508c8cfbde8f60163ecf22c8188da) now.
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#978
No description provided.