Răsfoiți Sursa

Change the default value for the "--original-hostname" flag from "localhost" to no host specified (#985).

Dan Helfman 4 luni în urmă
părinte
comite
b2d61ade4e
3 a modificat fișierele cu 21 adăugiri și 15 ștergeri
  1. 3 0
      NEWS
  2. 7 4
      borgmatic/actions/restore.py
  3. 11 11
      tests/unit/actions/test_restore.py

+ 3 - 0
NEWS

@@ -8,6 +8,9 @@
    subdirectories.
  * #983: Fix the Btrfs hook to support subvolumes with names like "@home", different from their
    mount points.
+ * #985: Change the default value for the "--original-hostname" flag from "localhost" to no host
+   specified. This way, the "restore" action works without a hostname if there's a single matching
+   dump.
 
 1.9.8
  * #979: Fix root patterns so they don't have an invalid "sh:" prefix before getting passed to Borg.

+ 7 - 4
borgmatic/actions/restore.py

@@ -57,7 +57,7 @@ def render_dump_metadata(dump):
     Given a Dump instance, make a display string describing it for use in log messages.
     '''
     name = 'unspecified' if dump.data_source_name is UNSPECIFIED else dump.data_source_name
-    hostname = dump.hostname or 'localhost'
+    hostname = dump.hostname or UNSPECIFIED
     port = None if dump.port is UNSPECIFIED else dump.port
 
     if port:
@@ -343,12 +343,15 @@ def get_dumps_to_restore(restore_arguments, dumps_from_archive):
                     else UNSPECIFIED
                 ),
                 data_source_name=name,
-                hostname=restore_arguments.original_hostname or 'localhost',
+                hostname=restore_arguments.original_hostname or UNSPECIFIED,
                 port=restore_arguments.original_port,
             )
-            for name in restore_arguments.data_sources
+            for name in restore_arguments.data_sources or (UNSPECIFIED,)
         }
-        if restore_arguments.data_sources
+        if restore_arguments.hook
+        or restore_arguments.data_sources
+        or restore_arguments.original_hostname
+        or restore_arguments.original_port
         else {
             Dump(
                 hook_name=UNSPECIFIED,

+ 11 - 11
tests/unit/actions/test_restore.py

@@ -575,11 +575,11 @@ def test_get_dumps_to_restore_gets_requested_dumps_found_in_archive():
     }
     flexmock(module).should_receive('dumps_match').and_return(False)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'foo'),
+        module.Dump(module.UNSPECIFIED, 'foo', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'foo'),
     ).and_return(True)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'bar'),
+        module.Dump(module.UNSPECIFIED, 'bar', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'bar'),
     ).and_return(True)
 
@@ -644,11 +644,11 @@ def test_get_dumps_to_restore_with_all_in_requested_dumps_finds_all_archive_dump
     }
     flexmock(module).should_receive('dumps_match').and_return(False)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'foo'),
+        module.Dump(module.UNSPECIFIED, 'foo', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'foo'),
     ).and_return(True)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'bar'),
+        module.Dump(module.UNSPECIFIED, 'bar', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'bar'),
     ).and_return(True)
 
@@ -673,11 +673,11 @@ def test_get_dumps_to_restore_with_all_in_requested_dumps_plus_additional_reques
     }
     flexmock(module).should_receive('dumps_match').and_return(False)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'foo'),
+        module.Dump(module.UNSPECIFIED, 'foo', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'foo'),
     ).and_return(True)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'bar'),
+        module.Dump(module.UNSPECIFIED, 'bar', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'bar'),
     ).and_return(True)
 
@@ -698,11 +698,11 @@ def test_get_dumps_to_restore_with_all_in_requested_dumps_plus_additional_reques
 def test_get_dumps_to_restore_raises_for_multiple_matching_dumps_in_archive():
     flexmock(module).should_receive('dumps_match').and_return(False)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'foo'),
+        module.Dump(module.UNSPECIFIED, 'foo', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'foo'),
     ).and_return(True)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'foo'),
+        module.Dump(module.UNSPECIFIED, 'foo', hostname=module.UNSPECIFIED),
         module.Dump('mariadb_databases', 'foo'),
     ).and_return(True)
     flexmock(module).should_receive('render_dump_metadata').and_return('test')
@@ -725,7 +725,7 @@ def test_get_dumps_to_restore_raises_for_multiple_matching_dumps_in_archive():
 def test_get_dumps_to_restore_raises_for_all_in_requested_dumps_and_requested_dumps_missing_from_archive():
     flexmock(module).should_receive('dumps_match').and_return(False)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump(module.UNSPECIFIED, 'foo'),
+        module.Dump(module.UNSPECIFIED, 'foo', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'foo'),
     ).and_return(True)
     flexmock(module).should_receive('render_dump_metadata').and_return('test')
@@ -750,7 +750,7 @@ def test_get_dumps_to_restore_with_requested_hook_name_filters_dumps_found_in_ar
     }
     flexmock(module).should_receive('dumps_match').and_return(False)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump('postgresql_databases', 'foo'),
+        module.Dump('postgresql_databases', 'foo', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'foo'),
     ).and_return(True)
 
@@ -775,7 +775,7 @@ def test_get_dumps_to_restore_with_requested_shortened_hook_name_filters_dumps_f
     }
     flexmock(module).should_receive('dumps_match').and_return(False)
     flexmock(module).should_receive('dumps_match').with_args(
-        module.Dump('postgresql_databases', 'foo'),
+        module.Dump('postgresql_databases', 'foo', hostname=module.UNSPECIFIED),
         module.Dump('postgresql_databases', 'foo'),
     ).and_return(True)