From 7d18f5907912fe43bb9b34bd0fba0dc7ef119e10 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Sun, 9 Jul 2023 11:45:51 +0200 Subject: [PATCH 1/3] Add a config entry for BORG_CHECK_I_KNOW_WHAT_I_AM_DOING env var --- borgmatic/borg/environment.py | 15 +++++++++++++-- borgmatic/config/schema.yaml | 6 ++++++ tests/unit/borg/test_environment.py | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/borgmatic/borg/environment.py b/borgmatic/borg/environment.py index 1b14369a..d32d07d7 100644 --- a/borgmatic/borg/environment.py +++ b/borgmatic/borg/environment.py @@ -11,11 +11,15 @@ OPTION_TO_ENVIRONMENT_VARIABLE = { 'temporary_directory': 'TMPDIR', } -DEFAULT_BOOL_OPTION_TO_ENVIRONMENT_VARIABLE = { +DEFAULT_BOOL_OPTION_TO_DOWNCASE_ENVIRONMENT_VARIABLE = { 'relocated_repo_access_is_ok': 'BORG_RELOCATED_REPO_ACCESS_IS_OK', 'unknown_unencrypted_repo_access_is_ok': 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK', } +DEFAULT_BOOL_OPTION_TO_UPPERCASE_ENVIRONMENT_VARIABLE = { + 'check_i_know_what_i_am_doing': 'BORG_CHECK_I_KNOW_WHAT_I_AM_DOING', +} + def make_environment(storage_config): ''' @@ -33,8 +37,15 @@ def make_environment(storage_config): for ( option_name, environment_variable_name, - ) in DEFAULT_BOOL_OPTION_TO_ENVIRONMENT_VARIABLE.items(): + ) in DEFAULT_BOOL_OPTION_TO_DOWNCASE_ENVIRONMENT_VARIABLE.items(): value = storage_config.get(option_name, False) environment[environment_variable_name] = 'yes' if value else 'no' + for ( + option_name, + environment_variable_name, + ) in DEFAULT_BOOL_OPTION_TO_UPPERCASE_ENVIRONMENT_VARIABLE.items(): + value = storage_config.get(option_name, False) + environment[environment_variable_name] = 'YES' if value else 'NO' + return environment diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 3f1b3cb4..84b512ca 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -405,6 +405,12 @@ properties: Bypass Borg error about a previously unknown unencrypted repository. Defaults to false. example: true + check_i_know_what_i_am_doing: + type: boolean + description: | + Bypass Borg confirmation about check with repair option. + Defaults to false. + example: true extra_borg_options: type: object additionalProperties: false diff --git a/tests/unit/borg/test_environment.py b/tests/unit/borg/test_environment.py index 4cef39b9..203a6b05 100644 --- a/tests/unit/borg/test_environment.py +++ b/tests/unit/borg/test_environment.py @@ -25,6 +25,7 @@ def test_make_environment_without_configuration_should_only_set_default_environm assert environment == { 'BORG_RELOCATED_REPO_ACCESS_IS_OK': 'no', 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': 'no', + 'BORG_CHECK_I_KNOW_WHAT_I_AM_DOING': 'NO', } @@ -34,6 +35,12 @@ def test_make_environment_with_relocated_repo_access_should_override_default(): assert environment.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'yes' +def test_make_environment_check_i_know_what_i_am_doing_should_override_default(): + environment = module.make_environment({'check_i_know_what_i_am_doing': True}) + + assert environment.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING') == 'YES' + + def test_make_environment_with_integer_variable_value(): environment = module.make_environment({'borg_files_cache_ttl': 40}) assert environment.get('BORG_FILES_CACHE_TTL') == '40' From 196a226a7e20639e750147b547dbd0ddef4ed8f4 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 10 Jul 2023 09:44:00 -0700 Subject: [PATCH 2/3] Add "check_i_know_what_i_am_doing" option to NEWS (#724). --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index f1ecea0d..535e5afe 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ https://torsion.org/borgmatic/docs/how-to/run-arbitrary-borg-commands/ * #719: Fix an error when running "borg key export" through borgmatic. * #720: Fix an error when dumping a MySQL database and the "exclude_nodump" option is set. + * #724: Add "check_i_know_what_i_am_doing" option to bypass Borg confirmation prompt when running + "check --repair". * When merging two configuration files, error gracefully if the two files do not adhere to the same format. * BREAKING: Remove the deprecated (and silently ignored) "--successful" flag on the "list" action, From 5b991b88ddfaba63abe0d7ac93a6a0d8e6d4f650 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 11 Jul 2023 19:58:49 -0700 Subject: [PATCH 3/3] Rewrite documentation navigation URLs when being run locally. --- docs/_data/borgmatic.js | 5 +++++ docs/_includes/layouts/main.njk | 2 +- docs/docker-compose.yaml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 docs/_data/borgmatic.js diff --git a/docs/_data/borgmatic.js b/docs/_data/borgmatic.js new file mode 100644 index 00000000..5d76ca01 --- /dev/null +++ b/docs/_data/borgmatic.js @@ -0,0 +1,5 @@ +module.exports = function() { + return { + environment: process.env.NODE_ENV || "development" + }; +}; diff --git a/docs/_includes/layouts/main.njk b/docs/_includes/layouts/main.njk index a7e5b665..81300bae 100644 --- a/docs/_includes/layouts/main.njk +++ b/docs/_includes/layouts/main.njk @@ -11,7 +11,7 @@ headerClass: elv-header-default {% set navPages = collections.all | eleventyNavigation %} {% macro renderNavListItem(entry) -%} - {{ entry.title }} + {{ entry.title }} {%- if entry.children.length -%}
    {%- for child in entry.children %}{{ renderNavListItem(child) }}{% endfor -%} diff --git a/docs/docker-compose.yaml b/docs/docker-compose.yaml index dfadf4a4..9914ef29 100644 --- a/docs/docker-compose.yaml +++ b/docs/docker-compose.yaml @@ -9,7 +9,7 @@ services: dockerfile: docs/Dockerfile context: .. args: - ENVIRONMENT: dev + ENVIRONMENT: development message: image: alpine container_name: message