From 5723c72eb13b4121dddd26d0006a64e6c34eb27b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 30 Jul 2022 16:21:53 +0200 Subject: [PATCH] Add environment variable RESTIC_COMPRESSION --- changelog/unreleased/issue-21 | 1 + cmd/restic/global.go | 6 ++++++ doc/040_backup.rst | 1 + doc/047_tuning_backup_parameters.rst | 3 ++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/changelog/unreleased/issue-21 b/changelog/unreleased/issue-21 index 795c5331e..afb0edb96 100644 --- a/changelog/unreleased/issue-21 +++ b/changelog/unreleased/issue-21 @@ -8,6 +8,7 @@ You can configure if data is compressed with the option `--compression`. It can be set to `auto` (the default, which will compress very fast), `max` (which will trade backup speed and CPU usage for better compression), or `off` (which disables compression). Each setting is only applied for the single run of restic. +The option can also be set via the environment variable `RESTIC_COMPRESSION`. The new format version has not received much testing yet. Do not rely on it as your only backup copy! Please run `check` in regular intervals to detect any diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 91e6a7509..876e6e614 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -125,6 +125,12 @@ func init() { // Use our "generate" command instead of the cobra provided "completion" command cmdRoot.CompletionOptions.DisableDefaultCmd = true + comp := os.Getenv("RESTIC_COMPRESSION") + if comp != "" { + // ignore error as there's no good way to handle it + _ = globalOptions.Compression.Set(comp) + } + restoreTerminal() } diff --git a/doc/040_backup.rst b/doc/040_backup.rst index fa535f403..1a126f841 100644 --- a/doc/040_backup.rst +++ b/doc/040_backup.rst @@ -552,6 +552,7 @@ environment variables. The following lists these environment variables: RESTIC_PASSWORD_COMMAND Command printing the password for the repository to stdout RESTIC_KEY_HINT ID of key to try decrypting first, before other keys RESTIC_CACHE_DIR Location of the cache directory + RESTIC_COMPRESSION Compression mode (only available for repository format version 2) RESTIC_PROGRESS_FPS Frames per second by which the progress bar is updated TMPDIR Location for temporary files diff --git a/doc/047_tuning_backup_parameters.rst b/doc/047_tuning_backup_parameters.rst index 5fe435d9a..78001bee6 100644 --- a/doc/047_tuning_backup_parameters.rst +++ b/doc/047_tuning_backup_parameters.rst @@ -46,4 +46,5 @@ For a repository using at least repository format version 2, you can configure h is compressed with the option ``--compression``. It can be set to ```auto``` (the default, which will compress very fast), ``max`` (which will trade backup speed and CPU usage for slightly better compression), or ``off`` (which disables compression). Each setting is -only applied for the single run of restic. +only applied for the single run of restic. The option can also be set via the environment +variable ``RESTIC_COMPRESSION``.