Browse Source

add archive options

Vandal 4 months ago
parent
commit
9356924418
2 changed files with 45 additions and 23 deletions
  1. 18 16
      borgmatic/borg/recreate.py
  2. 27 7
      borgmatic/commands/arguments.py

+ 18 - 16
borgmatic/borg/recreate.py

@@ -4,7 +4,7 @@ import borgmatic.borg.environment
 import borgmatic.config.paths
 import borgmatic.execute
 from borgmatic.borg.create import make_exclude_flags, make_list_filter_flags, write_patterns_file
-from borgmatic.borg.flags import make_repository_archive_flags
+from borgmatic.borg import flags
 
 logger = logging.getLogger(__name__)
 
@@ -28,27 +28,22 @@ def recreate_archive(
     Executes the recreate command with the given arguments.
     '''
     lock_wait = config.get('lock_wait', None)
-
-    if archive is None:
-        logger.error('Please provide a valid archive name.')
-        return
-
-    repo_archive_arg = make_repository_archive_flags(repository, archive, local_borg_version)
     exclude_flags = make_exclude_flags(config)
+    compression = config.get('compression', None)
 
     # Write patterns to a temporary file and use that file with --patterns-from.
     patterns_file = write_patterns_file(
         patterns, borgmatic.config.paths.get_working_directory(config)
     )
 
-    recreate_cmd = (
+    recreate_command = (
         (local_path, 'recreate')
         + (('--remote-path', remote_path) if remote_path else ())
-        + (
-            ('--path', recreate_arguments.path)
-            if hasattr(recreate_arguments, 'path') and recreate_arguments.path
-            else ()
-        )
+        # + (
+        #     ('--path', recreate_arguments.path)
+        #     if recreate_arguments.path
+        #     else ()
+        # )
         + (('--log-json',) if global_arguments.log_json else ())
         + (('--lock-wait', str(lock_wait)) if lock_wait is not None else ())
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
@@ -60,11 +55,18 @@ def recreate_archive(
                 '--filter',
                 make_list_filter_flags(local_borg_version, global_arguments.dry_run),
             )
-            if hasattr(recreate_arguments, 'list') and recreate_arguments.list
+            if recreate_arguments.list
             else ()
         )
+        + (('--target', recreate_arguments.target) if recreate_arguments.target else ())
+        + (('--comment', f'"{recreate_arguments.comment}"') if recreate_arguments.comment else ())
+        + (('--compression', compression) if compression else ())
         + exclude_flags
-        + repo_archive_arg
+        + (
+            flags.make_repository_archive_flags(repository, archive, local_borg_version)
+            if archive
+            else flags.make_repository_flags(repository, local_borg_version)
+        )
     )
 
     if global_arguments.dry_run:
@@ -72,7 +74,7 @@ def recreate_archive(
         return
 
     borgmatic.execute.execute_command(
-        full_command=recreate_cmd,
+        full_command=recreate_command,
         output_log_level=logging.INFO,
         environment=borgmatic.borg.environment.make_environment(config),
         working_directory=borgmatic.config.paths.get_working_directory(config),

+ 27 - 7
borgmatic/commands/arguments.py

@@ -1556,18 +1556,38 @@ def make_parsers():
     recreate_group = recreate_parser.add_argument_group('recreate arguments')
     recreate_group.add_argument(
         '--repository',
-        help='Path of the repository containing the archive',
+        help='Path of repository containing archive to recreate, defaults to the configured repository if there is only one, quoted globs supported',
     )
     recreate_group.add_argument(
         '--archive',
-        help='Name of the archive to recreate',
+        help='Archive name, hash, or series to recreate',
+    )
+    # recreate_group.add_argument(
+    #     '--path',
+    #     metavar='PATH',
+    #     dest='path',
+    #     help='Path to recreate the repository/archive',
+    #     required=True,
+    # )
+    recreate_group.add_argument(
+        '--list', dest='list', action='store_true', help='Show per-file details'
     )
     recreate_group.add_argument(
-        '--path',
-        metavar='PATH',
-        dest='paths',
-        action='append',
-        help='Path to recreate the repository/archive',
+        '--target',
+        metavar='TARGET',
+        help='Name of new archive name',
+    )
+    recreate_group.add_argument(
+        '--comment',
+        metavar='COMMENT',
+        help='Add a comment text to the archive, if archive not provided, consider all archives',
+    )
+    recreate_group.add_argument(
+        '--compression',
+        '-C',
+        dest='compression',
+        metavar='COMPRESSION',
+        help='Select compression algorithm',
     )
     recreate_group.add_argument(
         '-h', '--help', action='help', help='Show this help message and exit'