Skip to content

Commit

Permalink
With the "create" action and the "--list" ("--files") flag, only show…
Browse files Browse the repository at this point in the history
… excluded files at verbosity 2 (#620).
  • Loading branch information
witten committed Mar 2, 2023
1 parent dbf8301 commit a071e02
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
1.7.8.dev0
* #620: With the "create" action and the "--list" ("--files") flag, only show excluded files at
verbosity 2.
* #621: Add optional authentication to the ntfy monitoring hook.
* With the "create" action, only one of "--list" ("--files") and "--progress" flags can be used.
This lines up with the new behavior in Borg 2.0.0b5.
Expand Down
28 changes: 27 additions & 1 deletion borgmatic/borg/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ def make_exclude_flags(location_config, exclude_filename=None):
)


def make_list_filter_flags(local_borg_version, dry_run):
'''
Given the local Borg version and whether this is a dry run, return the corresponding flags for
passing to "--list --filter". The general idea is that excludes are shown for a dry run or when
the verbosity is debug.
'''
base_flags = 'AME'
show_excludes = logger.isEnabledFor(logging.DEBUG)

if feature.available(feature.Feature.EXCLUDED_FILES_MINUS, local_borg_version):
if show_excludes or dry_run:
return f'{base_flags}+-'
else:
return base_flags

if show_excludes:
return f'{base_flags}x-'
else:
return f'{base_flags}-'


DEFAULT_ARCHIVE_NAME_FORMAT = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'


Expand Down Expand Up @@ -343,6 +364,7 @@ def create_archive(
upload_rate_limit = storage_config.get('upload_rate_limit', None)
umask = storage_config.get('umask', None)
lock_wait = storage_config.get('lock_wait', None)
list_filter_flags = make_list_filter_flags(local_borg_version, dry_run)
files_cache = location_config.get('files_cache')
archive_name_format = storage_config.get('archive_name_format', DEFAULT_ARCHIVE_NAME_FORMAT)
extra_borg_options = storage_config.get('extra_borg_options', {}).get('create', '')
Expand Down Expand Up @@ -401,7 +423,11 @@ def create_archive(
+ (('--remote-path', remote_path) if remote_path else ())
+ (('--umask', str(umask)) if umask else ())
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
+ (('--list', '--filter', 'AMEx+-') if list_files and not json and not progress else ())
+ (
('--list', '--filter', list_filter_flags)
if list_files and not json and not progress
else ()
)
+ (('--dry-run',) if dry_run else ())
+ (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
+ flags.make_repository_archive_flags(repository, archive_name_format, local_borg_version)
Expand Down
2 changes: 2 additions & 0 deletions borgmatic/borg/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Feature(Enum):
RLIST = 8
RINFO = 9
MATCH_ARCHIVES = 10
EXCLUDED_FILES_MINUS = 11


FEATURE_TO_MINIMUM_BORG_VERSION = {
Expand All @@ -27,6 +28,7 @@ class Feature(Enum):
Feature.RLIST: parse_version('2.0.0a2'), # borg rlist
Feature.RINFO: parse_version('2.0.0a2'), # borg rinfo
Feature.MATCH_ARCHIVES: parse_version('2.0.0b3'), # borg --match-archives
Feature.EXCLUDED_FILES_MINUS: parse_version('2.0.0b5'), # --list --filter uses "-" for excludes
}


Expand Down
Loading

0 comments on commit a071e02

Please sign in to comment.