diff --git a/NEWS b/NEWS index a6504385..80d7f157 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.3.5.dev0 + * #153: Support for various Borg directory environment variables (BORG_CONFIG_DIR, BORG_CACHE_DIR, + etc.) via options in borgmatic's storage configuration. + 1.3.4 * Part of #125: Color borgmatic (but not Borg) output when using an interactive terminal. * #166: Run tests for all installed versions of Python. diff --git a/borgmatic/borg/environment.py b/borgmatic/borg/environment.py index 0f717e75..2dde10cd 100644 --- a/borgmatic/borg/environment.py +++ b/borgmatic/borg/environment.py @@ -1,15 +1,19 @@ import os +OPTION_TO_ENVIRONMENT_VARIABLE = { + 'borg_base_directory': 'BORG_BASE_DIR', + 'borg_config_directory': 'BORG_CONFIG_DIR', + 'borg_cache_directory': 'BORG_CACHE_DIR', + 'borg_security_directory': 'BORG_SECURITY_DIR', + 'borg_keys_directory': 'BORG_KEYS_DIR', + 'encryption_passcommand': 'BORG_PASSCOMMAND', + 'encryption_passphrase': 'BORG_PASSPHRASE', + 'ssh_command': 'BORG_RSH', +} + def initialize(storage_config): - passcommand = storage_config.get('encryption_passcommand') - if passcommand: - os.environ['BORG_PASSCOMMAND'] = passcommand - - passphrase = storage_config.get('encryption_passphrase') - if passphrase: - os.environ['BORG_PASSPHRASE'] = passphrase - - ssh_command = storage_config.get('ssh_command') - if ssh_command: - os.environ['BORG_RSH'] = ssh_command + for option_name, environment_variable_name in OPTION_TO_ENVIRONMENT_VARIABLE.items(): + value = storage_config.get(option_name) + if value: + os.environ[environment_variable_name] = value diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index ce34f2a7..198da492 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -168,6 +168,32 @@ map: Command to use instead of "ssh". This can be used to specify ssh options. Defaults to not set. example: ssh -i /path/to/private/key + borg_base_directory: + type: scalar + desc: | + Base path used for various Borg directories. Defaults to $HOME, ~$USER, or ~. + See https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables for details. + example: /path/to/base + borg_config_directory: + type: scalar + desc: | + Path for Borg configuration files. Defaults to $borg_base_directory/.config/borg + example: /path/to/base/config + borg_cache_directory: + type: scalar + desc: | + Path for Borg cache files. Defaults to $borg_base_directory/.cache/borg + example: /path/to/base/cache + borg_security_directory: + type: scalar + desc: | + Path for Borg security and encryption nonce files. Defaults to $borg_base_directory/.config/borg/security + example: /path/to/base/config/security + borg_keys_directory: + type: scalar + desc: | + Path for Borg encryption key files. Defaults to $borg_base_directory/.config/borg/keys + example: /path/to/base/config/keys umask: type: scalar desc: Umask to be used for borg create. Defaults to 0077. diff --git a/setup.py b/setup.py index ac359ba0..c3696230 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.3.4' +VERSION = '1.3.5.dev0' setup( diff --git a/tests/unit/borg/test_environment.py b/tests/unit/borg/test_environment.py index 67653b32..9fa25b19 100644 --- a/tests/unit/borg/test_environment.py +++ b/tests/unit/borg/test_environment.py @@ -42,8 +42,7 @@ def test_initialize_without_configuration_should_not_set_environment(): try: os.environ = {} module.initialize({}) - assert os.environ.get('BORG_PASSCOMMAND') is None - assert os.environ.get('BORG_PASSPHRASE') is None - assert os.environ.get('BORG_RSH') is None + + assert sum(1 for key in os.environ.keys() if key.startswith('BORG_')) == 0 finally: os.environ = orig_environ