Explorar o código

Add support for "borgmatic borg debug" command (#538).

Dan Helfman %!s(int64=3) %!d(string=hai) anos
pai
achega
5b615d51a4
Modificáronse 3 ficheiros con 45 adicións e 3 borrados
  1. 1 0
      NEWS
  2. 10 3
      borgmatic/borg/borg.py
  3. 34 0
      tests/unit/borg/test_borg.py

+ 1 - 0
NEWS

@@ -5,6 +5,7 @@
    https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/#check-frequency
    https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/#check-frequency
  * #536: Fix generate-borgmatic-config to support more complex schema changes like the new
  * #536: Fix generate-borgmatic-config to support more complex schema changes like the new
    Healthchecks configuration options when the "--source" flag is used.
    Healthchecks configuration options when the "--source" flag is used.
+ * #538: Add support for "borgmatic borg debug" command.
  * Add Bash completion script so you can tab-complete the borgmatic command-line. See the
  * Add Bash completion script so you can tab-complete the borgmatic command-line. See the
    documentation for more information:
    documentation for more information:
    https://torsion.org/borgmatic/docs/how-to/set-up-backups/#shell-completion
    https://torsion.org/borgmatic/docs/how-to/set-up-backups/#shell-completion

+ 10 - 3
borgmatic/borg/borg.py

@@ -7,6 +7,8 @@ logger = logging.getLogger(__name__)
 
 
 
 
 REPOSITORYLESS_BORG_COMMANDS = {'serve', None}
 REPOSITORYLESS_BORG_COMMANDS = {'serve', None}
+BORG_COMMANDS_WITH_SUBCOMMANDS = {'key', 'debug'}
+BORG_SUBCOMMANDS_WITHOUT_REPOSITORY = (('debug', 'info'), ('debug', 'convert-profile'))
 
 
 
 
 def run_arbitrary_borg(
 def run_arbitrary_borg(
@@ -22,15 +24,20 @@ def run_arbitrary_borg(
     try:
     try:
         options = options[1:] if options[0] == '--' else options
         options = options[1:] if options[0] == '--' else options
 
 
-        # Borg's "key" command has a sub-command ("export", etc.) that must follow it.
-        command_options_start_index = 2 if options[0] == 'key' else 1
+        # Borg commands like "key" have a sub-command ("export", etc.) that must follow it.
+        command_options_start_index = 2 if options[0] in BORG_COMMANDS_WITH_SUBCOMMANDS else 1
         borg_command = tuple(options[:command_options_start_index])
         borg_command = tuple(options[:command_options_start_index])
         command_options = tuple(options[command_options_start_index:])
         command_options = tuple(options[command_options_start_index:])
     except IndexError:
     except IndexError:
         borg_command = ()
         borg_command = ()
         command_options = ()
         command_options = ()
 
 
-    repository_archive = '::'.join((repository, archive)) if repository and archive else repository
+    if borg_command in BORG_SUBCOMMANDS_WITHOUT_REPOSITORY:
+        repository_archive = None
+    else:
+        repository_archive = (
+            '::'.join((repository, archive)) if repository and archive else repository
+        )
 
 
     full_command = (
     full_command = (
         (local_path,)
         (local_path,)

+ 34 - 0
tests/unit/borg/test_borg.py

@@ -131,3 +131,37 @@ def test_run_arbitrary_borg_passes_key_sub_command_to_borg_before_repository():
     module.run_arbitrary_borg(
     module.run_arbitrary_borg(
         repository='repo', storage_config={}, options=['key', 'export'],
         repository='repo', storage_config={}, options=['key', 'export'],
     )
     )
+
+
+def test_run_arbitrary_borg_passes_debug_sub_command_to_borg_before_repository():
+    flexmock(module).should_receive('execute_command').with_args(
+        ('borg', 'debug', 'dump-manifest', 'repo', 'path'),
+        output_log_level=logging.WARNING,
+        borg_local_path='borg',
+    )
+
+    module.run_arbitrary_borg(
+        repository='repo', storage_config={}, options=['debug', 'dump-manifest', 'path'],
+    )
+
+
+def test_run_arbitrary_borg_with_debug_info_command_does_not_pass_borg_repository():
+    flexmock(module).should_receive('execute_command').with_args(
+        ('borg', 'debug', 'info'), output_log_level=logging.WARNING, borg_local_path='borg',
+    )
+
+    module.run_arbitrary_borg(
+        repository='repo', storage_config={}, options=['debug', 'info'],
+    )
+
+
+def test_run_arbitrary_borg_with_debug_convert_profile_command_does_not_pass_borg_repository():
+    flexmock(module).should_receive('execute_command').with_args(
+        ('borg', 'debug', 'convert-profile', 'in', 'out'),
+        output_log_level=logging.WARNING,
+        borg_local_path='borg',
+    )
+
+    module.run_arbitrary_borg(
+        repository='repo', storage_config={}, options=['debug', 'convert-profile', 'in', 'out'],
+    )