From 26fd41da92e262e68fc87e24fd1e828937984f50 Mon Sep 17 00:00:00 2001 From: Vandal <86826719+VandalByte@users.noreply.github.com> Date: Thu, 27 Mar 2025 22:18:34 +0530 Subject: [PATCH] add rest of flags --- borgmatic/actions/recreate.py | 4 ++-- borgmatic/borg/recreate.py | 30 +++++++++++++++--------------- borgmatic/commands/arguments.py | 21 +++++++++++++-------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/borgmatic/actions/recreate.py b/borgmatic/actions/recreate.py index 53ee7fce..3cef7762 100644 --- a/borgmatic/actions/recreate.py +++ b/borgmatic/actions/recreate.py @@ -23,9 +23,9 @@ def run_recreate( repository, recreate_arguments.repository ): if recreate_arguments.archive: - logger.info(f'Recreating archive {recreate_arguments.archive}') + logger.answer(f'Recreating archive {recreate_arguments.archive}') else: - logger.info('Recreating repository') + logger.answer('Recreating repository') # Collect and process patterns. processed_patterns = process_patterns( diff --git a/borgmatic/borg/recreate.py b/borgmatic/borg/recreate.py index 640bcd05..ea2a2081 100644 --- a/borgmatic/borg/recreate.py +++ b/borgmatic/borg/recreate.py @@ -1,4 +1,5 @@ import logging +import shlex from datetime import datetime import borgmatic.borg.environment @@ -10,15 +11,6 @@ from borgmatic.borg.create import make_exclude_flags, make_list_filter_flags, wr logger = logging.getLogger(__name__) -def is_valid_timestamp(time_str): - try: - # Attempt to parse the time string using the expected format - datetime.strptime(time_str, r"%Y-%m-%dT%H:%M:%S") - return True - except ValueError: - return False - - def recreate_archive( repository, archive, @@ -37,15 +29,11 @@ def recreate_archive( Executes the recreate command with the given arguments. ''' - if recreate_arguments.timestamp and not is_valid_timestamp(recreate_arguments.timestamp): - logger.error( - 'Please provide a valid timestamp of format: yyyy-mm-ddThh:mm:ss. Example: 2025-03-26T14:45:59' - ) - return lock_wait = config.get('lock_wait', None) exclude_flags = make_exclude_flags(config) compression = config.get('compression', None) + chunker_params = config.get('chunker_params', None) # Write patterns to a temporary file and use that file with --patterns-from. patterns_file = write_patterns_file( @@ -80,8 +68,20 @@ def recreate_archive( if recreate_arguments.target and recreate_arguments.archive else () ) - + (('--comment', f'"{recreate_arguments.comment}"') if recreate_arguments.comment else ()) + + ( + ('--comment', shlex.quote(recreate_arguments.comment)) + if recreate_arguments.comment + else () + ) + + (('--timestamp', recreate_arguments.timestamp) if recreate_arguments.timestamp else ()) + (('--compression', compression) if compression else ()) + + (('--chunker-params', chunker_params) if chunker_params else ()) + + flags.make_match_archives_flags( + recreate_arguments.match_archives or archive or config.get('match_archives'), + config.get('archive_name_format'), + local_borg_version, + ) + + (('--recompress', recreate_arguments.recompress) if recreate_arguments.recompress else ()) + exclude_flags + ( flags.make_repository_archive_flags(repository, archive, local_borg_version) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index f9d0e7af..689959ce 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -1582,17 +1582,22 @@ def make_parsers(): 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 the compression algorithm', - ) recreate_group.add_argument( '--timestamp', metavar='TIMESTAMP', - help='Manually specify the archive creation date/time (UTC, yyyy-mm-ddThh:mm:ss format)', + help='Manually specify the archive creation date/time (UTC)', + ) + recreate_group.add_argument( + '-a', + '--match-archives', + '--glob-archives', + metavar='PATTERN', + help='Only consider archive names, hashes, or series matching this pattern', + ) + recreate_group.add_argument( + '--recompress', + metavar='MODE', + help='Recompress data chunks according to MODE: [if-different (default), always, never]', ) recreate_group.add_argument( '-h', '--help', action='help', help='Show this help message and exit'