From 0012e0cdea8d4b6b57c50721ad39e946d95559b5 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 13 Feb 2016 10:59:43 -0800 Subject: [PATCH] Support borg create --umask. (Merge PR from ypid.) --- NEWS | 1 + atticmatic/backends/borg.py | 2 ++ atticmatic/backends/shared.py | 4 +++- atticmatic/tests/unit/backends/test_shared.py | 15 +++++++++++++++ sample/config | 2 ++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 1b0963f..412e8bc 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ * Fixed handling of repeated spaces in source_directories which resulted in backup up everything. * Added support for --one-file-system for Borg. + * Support borg create --umask. 0.1.7 diff --git a/atticmatic/backends/borg.py b/atticmatic/backends/borg.py index 6105a05..d99af4a 100644 --- a/atticmatic/backends/borg.py +++ b/atticmatic/backends/borg.py @@ -20,6 +20,7 @@ CONFIG_FORMAT = ( ( option('encryption_passphrase', required=False), option('compression', required=False), + option('umask', required=False), ), ), shared.CONFIG_FORMAT[2], # retention @@ -34,6 +35,7 @@ CONFIG_FORMAT = ( initialize = partial(shared.initialize, command=COMMAND) + create_archive = partial(shared.create_archive, command=COMMAND) prune_archives = partial(shared.prune_archives, command=COMMAND) check_archives = partial(shared.check_archives, command=COMMAND) diff --git a/atticmatic/backends/shared.py b/atticmatic/backends/shared.py index 5544b30..f300d1e 100644 --- a/atticmatic/backends/shared.py +++ b/atticmatic/backends/shared.py @@ -69,6 +69,8 @@ def create_archive( exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else () compression = storage_config.get('compression', None) compression_flags = ('--compression', compression) if compression else () + umask = storage_config.get('umask', None) + umask_flags = ('--umask', str(umask)) if umask else () one_file_system_flags = ('--one-file-system',) if one_file_system else () verbosity_flags = { VERBOSITY_SOME: ('--stats',), @@ -83,7 +85,7 @@ def create_archive( timestamp=datetime.now().isoformat(), ), ) + sources + exclude_flags + compression_flags + one_file_system_flags + \ - verbosity_flags + umask_flags + verbosity_flags subprocess.check_call(full_command) diff --git a/atticmatic/tests/unit/backends/test_shared.py b/atticmatic/tests/unit/backends/test_shared.py index 660fc5b..8babc58 100644 --- a/atticmatic/tests/unit/backends/test_shared.py +++ b/atticmatic/tests/unit/backends/test_shared.py @@ -162,6 +162,21 @@ def test_create_archive_with_one_file_system_should_call_attic_with_one_file_sys ) +def test_create_archive_with_umask_should_call_attic_with_umask_parameters(): + insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740')) + insert_platform_mock() + insert_datetime_mock() + + module.create_archive( + excludes_filename='excludes', + verbosity=None, + storage_config={'umask': 740}, + source_directories='foo bar', + repository='repo', + command='attic', + ) + + BASE_PRUNE_FLAGS = ( ('--keep-daily', '1'), ('--keep-weekly', '2'), diff --git a/sample/config b/sample/config index 3d9432f..70527e4 100644 --- a/sample/config +++ b/sample/config @@ -17,6 +17,8 @@ repository: user@backupserver:sourcehostname.attic # archives. See https://borgbackup.github.io/borgbackup/usage.html#borg-create # for details. Defaults to no compression. #compression: lz4 +# For Borg only, you can specify the umask to be used for borg create. +#umask: 0740 [retention] # Retention policy for how many backups to keep in each category. See