浏览代码

Merge branch 'main' into fix-borg-2-latest-archive

Dan Helfman 2 天之前
父节点
当前提交
4ced5150f4

+ 7 - 3
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

+ 2 - 2
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'),

+ 1 - 1
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'),

+ 2 - 2
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'),

+ 1 - 1
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'),

+ 4 - 3
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.
 
 <span class="minilink minilink-addedin">Prior to version 2.0.8</span> If you're
 running an older version of borgmatic on the host, you can publish your database

+ 3 - 3
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'),

+ 2 - 2
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'