From cf846ab8ac7c772a600e294108fab130e47bfd35 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 17 Jun 2018 15:12:43 -0700 Subject: [PATCH] Support for Borg prune --umask option (#69). --- NEWS | 4 +++- borgmatic/borg/prune.py | 32 ++++++++++++++----------- borgmatic/tests/unit/borg/test_prune.py | 17 +++++++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index c934648..5702229 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -1.1.16.dev0 +1.2.0 * #61: Support for Borg --list option via borgmatic command-line to list all archives. * #61: Support for Borg --info option via borgmatic command-line to display summary information. * #62: Update README to mention other ways of installing borgmatic. @@ -9,6 +9,8 @@ * #60: Add "Persistent" flag to systemd timer example. * #63: Support for Borg --nobsdflags option to skip recording bsdflags (e.g. NODUMP, IMMUTABLE) in archive. + * #69: Support for Borg prune --umask option using value of existing "umask" option in borgmatic's + storage configuration. * Update tox.ini to only assume Python 3.x instead of Python 3.4 specifically. * Add ~/.config/borgmatic/config.yaml to default configuration path probing. * Document how to develop on and contribute to borgmatic. diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index c6e0ce6..09e1c9b 100644 --- a/borgmatic/borg/prune.py +++ b/borgmatic/borg/prune.py @@ -39,23 +39,27 @@ def prune_archives(verbosity, dry_run, repository, storage_config, retention_con retention config dict, prune Borg archives according to the retention policy specified in that configuration. ''' - remote_path_flags = ('--remote-path', remote_path) if remote_path else () + umask = storage_config.get('umask', None) lock_wait = storage_config.get('lock_wait', None) - lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else () - verbosity_flags = { - VERBOSITY_SOME: ('--info', '--stats',), - VERBOSITY_LOTS: ('--debug', '--stats', '--list'), - }.get(verbosity, ()) - dry_run_flags = ('--dry-run',) if dry_run else () full_command = ( - local_path, 'prune', - repository, - ) + tuple( - element - for pair in _make_prune_flags(retention_config) - for element in pair - ) + remote_path_flags + lock_wait_flags + verbosity_flags + dry_run_flags + ( + local_path, 'prune', + repository, + ) + tuple( + element + for pair in _make_prune_flags(retention_config) + for element in pair + ) + + (('--remote-path', remote_path) if remote_path else ()) + + (('--umask', str(umask)) if umask else ()) + + (('--lock-wait', str(lock_wait)) if lock_wait else ()) + + { + VERBOSITY_SOME: ('--info', '--stats',), + VERBOSITY_LOTS: ('--debug', '--stats', '--list'), + }.get(verbosity, ()) + + (('--dry-run',) if dry_run else ()) + ) logger.debug(' '.join(full_command)) subprocess.check_call(full_command) diff --git a/borgmatic/tests/unit/borg/test_prune.py b/borgmatic/tests/unit/borg/test_prune.py index 9289d0b..6e3a20d 100644 --- a/borgmatic/tests/unit/borg/test_prune.py +++ b/borgmatic/tests/unit/borg/test_prune.py @@ -153,6 +153,23 @@ def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters( ) +def test_prune_archives_with_umask_calls_borg_with_umask_parameters(): + storage_config = {'umask': '077'} + retention_config = flexmock() + flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return( + BASE_PRUNE_FLAGS, + ) + insert_subprocess_mock(PRUNE_COMMAND + ('--umask', '077')) + + module.prune_archives( + verbosity=None, + dry_run=False, + repository='repo', + storage_config=storage_config, + retention_config=retention_config, + ) + + def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters(): storage_config = {'lock_wait': 5} retention_config = flexmock()