浏览代码

Support borg create --umask. (Merge PR from ypid.)

Dan Helfman 9 年之前
父节点
当前提交
dd2be365b1
共有 5 个文件被更改,包括 23 次插入1 次删除
  1. 1 0
      NEWS
  2. 2 0
      atticmatic/backends/borg.py
  3. 3 1
      atticmatic/backends/shared.py
  4. 15 0
      atticmatic/tests/unit/backends/test_shared.py
  5. 2 0
      sample/config

+ 1 - 0
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
 

+ 2 - 0
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)

+ 3 - 1
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)
 

+ 15 - 0
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'),

+ 2 - 0
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