#9: New configuration option for the encryption passphrase. #10: Support for Borg's new archive compression feature.

This commit is contained in:
Dan Helfman 2015-09-02 22:48:07 -07:00
commit 3a9e32a411
3 changed files with 98 additions and 10 deletions

View file

@ -7,6 +7,8 @@ from atticmatic.backends import shared
COMMAND = 'attic'
CONFIG_FORMAT = shared.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)

View file

@ -8,7 +8,14 @@ from atticmatic.backends import shared
COMMAND = 'borg'
CONFIG_FORMAT = (
shared.CONFIG_FORMAT[0], # location
shared.CONFIG_FORMAT[1], # retention
Section_format(
'storage',
(
option('encryption_passphrase', required=False),
option('compression', required=False),
),
),
shared.CONFIG_FORMAT[2], # retention
Section_format(
'consistency',
(
@ -19,6 +26,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)

View file

@ -21,6 +21,12 @@ CONFIG_FORMAT = (
option('repository'),
),
),
Section_format(
'storage',
(
option('encryption_passphrase', required=False),
),
),
Section_format(
'retention',
(
@ -41,13 +47,26 @@ CONFIG_FORMAT = (
)
)
def create_archive(excludes_filename, verbosity, source_directories, repository, command):
def initialize(storage_config, command):
passphrase = storage_config.get('encryption_passphrase')
if passphrase:
os.environ['{}_PASSPHRASE'.format(command.upper())] = passphrase
def create_archive(
excludes_filename, verbosity, storage_config, source_directories, repository, command,
):
'''
Given an excludes filename (or None), a vebosity flag, a space-separated list of source
directories, a local or remote repository path, and a command to run, create an attic archive.
Given an excludes filename (or None), a vebosity flag, a storage config dict, a space-separated
list of source directories, a local or remote repository path, and a command to run, create an
attic archive.
'''
sources = tuple(source_directories.split(' '))
exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else ()
compression = storage_config.get('compression', None)
compression_flags = ('--compression', compression) if compression else ()
verbosity_flags = {
VERBOSITY_SOME: ('--stats',),
VERBOSITY_LOTS: ('--verbose', '--stats'),
@ -60,7 +79,7 @@ def create_archive(excludes_filename, verbosity, source_directories, repository,
hostname=platform.node(),
timestamp=datetime.now().isoformat(),
),
) + sources + exclude_flags + verbosity_flags
) + sources + exclude_flags + compression_flags + verbosity_flags
subprocess.check_call(full_command)