diff --git a/NEWS b/NEWS index bc5f431e..2bbd7541 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ * #618: Add support for BORG_FILES_CACHE_TTL environment variable via "borg_files_cache_ttl" option in borgmatic's storage configuration. * #623: Fix confusing message when an error occurs running actions for a configuration file. + * #649: Add documentation on backing up a database running in a container: + https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#containers * #655: Fix error when databases are configured and a source directory doesn't exist. * Add code style plugins to enforce use of Python f-strings and prevent single-letter variables. To join in the pedantry, refresh your test environment with "tox --recreate". diff --git a/docs/how-to/backup-your-databases.md b/docs/how-to/backup-your-databases.md index bc21b659..3f819170 100644 --- a/docs/how-to/backup-your-databases.md +++ b/docs/how-to/backup-your-databases.md @@ -136,6 +136,53 @@ hooks: format: sql ``` +### Containers + +If your database is running within a Docker container and borgmatic is too, no +problem—simply configure borgmatic to connect to the container's name on its +exposed port. For instance: + +```yaml +hooks: + postgresql_databases: + - name: users + hostname: your-database-container-name + port: 5433 + username: postgres + password: trustsome1 +``` + +But what if borgmatic is running on the host? You can still connect to a +database container if its ports are properly exposed to the host. For +instance, when running the database container with Docker, you can specify +`--publish 127.0.0.1:5433:5432` so that it exposes the container's port 5432 +to port 5433 on the host (only reachable on localhost, in this case). Or the +same thing with Docker Compose: + +```yaml +services: + your-database-container-name: + image: postgres + ports: + - 127.0.0.1:5433:5432 +``` + +And then you can connect to the database from borgmatic running on the host: + +```yaml +hooks: + postgresql_databases: + - name: users + hostname: 127.0.0.1 + port: 5433 + username: postgres + password: trustsome1 +``` + +Of course, alter the ports in these examples to suit your particular database +system. + + ### No source directories New in version 1.7.1 If you @@ -154,7 +201,6 @@ hooks: ``` - ### External passwords If you don't want to keep your database passwords in your borgmatic