From 4feec081a889cb9873b50fbbfbbdfbbac2fbea8e Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 18 Sep 2025 16:13:24 -0700 Subject: [PATCH 1/2] Clarify "container:" documentation about borgmatic running inside a container (#1116). --- docs/how-to/backup-your-databases.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/how-to/backup-your-databases.md b/docs/how-to/backup-your-databases.md index 807a54ac..1256a05b 100644 --- a/docs/how-to/backup-your-databases.md +++ b/docs/how-to/backup-your-databases.md @@ -228,9 +228,10 @@ postgresql_databases: password: trustsome1 ``` -borgmatic uses the `docker`/`podman` CLI to figure out the container IP to -connect to. But `container:` does not work when borgmatic itself is running in a -container; in that case, use `hostname:` as described above. +borgmatic uses the `docker` or `podman` command to figure out the container IP +to connect to. But `container:` doesn't work when borgmatic itself is running in +a container—unless the `docker` or `podman` command works inside that container. +But you can always use `hostname:` as described above. Prior to version 2.0.8 If you're running an older version of borgmatic on the host, you can publish your database From a388b17271ad9acd9c93aca0d1bbd65302c11f01 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 18 Sep 2025 19:22:45 -0700 Subject: [PATCH 2/2] No longer defaulting Dump(hostname=...) to "localhost" (#1116). --- borgmatic/actions/restore.py | 10 +++++++--- borgmatic/hooks/data_source/mariadb.py | 4 ++-- borgmatic/hooks/data_source/mongodb.py | 2 +- borgmatic/hooks/data_source/mysql.py | 4 ++-- borgmatic/hooks/data_source/postgresql.py | 2 +- tests/unit/actions/test_restore.py | 6 +++--- tests/unit/hooks/data_source/test_dump.py | 4 ++-- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/borgmatic/actions/restore.py b/borgmatic/actions/restore.py index ac25bfd7..95f5539b 100644 --- a/borgmatic/actions/restore.py +++ b/borgmatic/actions/restore.py @@ -23,7 +23,7 @@ UNSPECIFIED = object() Dump = collections.namedtuple( 'Dump', ('hook_name', 'data_source_name', 'hostname', 'port', 'label', 'container'), - defaults=('localhost', None, None, None), + defaults=(None, None, None, None), ) @@ -108,7 +108,7 @@ def get_configured_data_source(config, restore_dump): Dump( hook_name, hook_data_source.get('name'), - hook_data_source.get('hostname', 'localhost'), + hook_data_source.get('hostname'), hook_data_source.get('port'), hook_data_source.get('label') or UNSPECIFIED, hook_data_source.get('container'), @@ -389,7 +389,11 @@ def collect_dumps_from_archive( except (ValueError, TypeError): port = None - dumps_from_archive.add(Dump(hook_name, data_source_name, hostname, port)) + dumps_from_archive.add( + Dump( + hook_name, data_source_name, None if hostname == 'localhost' else hostname, port + ) + ) # We've successfully parsed the dump path, so need to probe any further. break diff --git a/borgmatic/hooks/data_source/mariadb.py b/borgmatic/hooks/data_source/mariadb.py index fc73fa24..ec255aef 100644 --- a/borgmatic/hooks/data_source/mariadb.py +++ b/borgmatic/hooks/data_source/mariadb.py @@ -305,7 +305,7 @@ def dump_data_sources( borgmatic.actions.restore.Dump( 'mariadb_databases', database_name, - database.get('hostname', 'localhost'), + database.get('hostname'), database.get('port'), database.get('label'), database.get('container'), @@ -331,7 +331,7 @@ def dump_data_sources( borgmatic.actions.restore.Dump( 'mariadb_databases', database['name'], - database.get('hostname', 'localhost'), + database.get('hostname'), database.get('port'), database.get('label'), database.get('container'), diff --git a/borgmatic/hooks/data_source/mongodb.py b/borgmatic/hooks/data_source/mongodb.py index b41d8c5b..ccbf6144 100644 --- a/borgmatic/hooks/data_source/mongodb.py +++ b/borgmatic/hooks/data_source/mongodb.py @@ -62,7 +62,7 @@ def dump_data_sources( borgmatic.actions.restore.Dump( 'mongodb_databases', name, - database.get('hostname', 'localhost'), + database.get('hostname'), database.get('port'), database.get('label'), database.get('container'), diff --git a/borgmatic/hooks/data_source/mysql.py b/borgmatic/hooks/data_source/mysql.py index 51710b6e..9b2fae4f 100644 --- a/borgmatic/hooks/data_source/mysql.py +++ b/borgmatic/hooks/data_source/mysql.py @@ -236,7 +236,7 @@ def dump_data_sources( borgmatic.actions.restore.Dump( 'mysql_databases', database_name, - database.get('hostname', 'localhost'), + database.get('hostname'), database.get('port'), database.get('label'), database.get('container'), @@ -262,7 +262,7 @@ def dump_data_sources( borgmatic.actions.restore.Dump( 'mysql_databases', database['name'], - database.get('hostname', 'localhost'), + database.get('hostname'), database.get('port'), database.get('label'), database.get('container'), diff --git a/borgmatic/hooks/data_source/postgresql.py b/borgmatic/hooks/data_source/postgresql.py index 84c7982b..9187cc1c 100644 --- a/borgmatic/hooks/data_source/postgresql.py +++ b/borgmatic/hooks/data_source/postgresql.py @@ -165,7 +165,7 @@ def dump_data_sources( borgmatic.actions.restore.Dump( 'postgresql_databases', database_name, - database.get('hostname', 'localhost'), + database.get('hostname'), database.get('port'), database.get('label'), database.get('container'), diff --git a/tests/unit/actions/test_restore.py b/tests/unit/actions/test_restore.py index 997cdd26..372bfbc0 100644 --- a/tests/unit/actions/test_restore.py +++ b/tests/unit/actions/test_restore.py @@ -160,15 +160,15 @@ def test_dumps_match_compares_two_dumps_while_respecting_unspecified_values( ( ( module.Dump('postgresql_databases', 'foo'), - 'foo@localhost (postgresql_databases)', + 'foo (postgresql_databases)', ), ( module.Dump(module.UNSPECIFIED, 'foo'), - 'foo@localhost', + 'foo', ), ( module.Dump('postgresql_databases', module.UNSPECIFIED), - 'unspecified@localhost (postgresql_databases)', + 'unspecified (postgresql_databases)', ), ( module.Dump('postgresql_databases', 'foo', 'host'), diff --git a/tests/unit/hooks/data_source/test_dump.py b/tests/unit/hooks/data_source/test_dump.py index a53628ea..2ea45b63 100644 --- a/tests/unit/hooks/data_source/test_dump.py +++ b/tests/unit/hooks/data_source/test_dump.py @@ -69,7 +69,7 @@ def test_write_data_source_dumps_metadata_writes_json_to_file(): assert ( dumps_stream.getvalue() - == '{"dumps": [{"container": null, "data_source_name": "foo", "hook_name": "databases", "hostname": "localhost", "label": null, "port": null}, {"container": null, "data_source_name": "bar", "hook_name": "databases", "hostname": "localhost", "label": null, "port": null}]}' + == '{"dumps": [{"container": null, "data_source_name": "foo", "hook_name": "databases", "hostname": null, "label": null, "port": null}, {"container": null, "data_source_name": "bar", "hook_name": "databases", "hostname": null, "label": null, "port": null}]}' ) @@ -90,7 +90,7 @@ def test_write_data_source_dumps_metadata_with_operating_system_error_raises(): def test_parse_data_source_dumps_metadata_converts_json_to_dump_instances(): - dumps_json = '{"dumps": [{"data_source_name": "foo", "hook_name": "databases", "hostname": "localhost", "port": null}, {"data_source_name": "bar", "hook_name": "databases", "hostname": "example.org", "port": 1234}]}' + dumps_json = '{"dumps": [{"data_source_name": "foo", "hook_name": "databases", "hostname": null, "port": null}, {"data_source_name": "bar", "hook_name": "databases", "hostname": "example.org", "port": 1234}]}' assert module.parse_data_source_dumps_metadata( dumps_json, 'borgmatic/databases/dumps.json'