diff options
| -rw-r--r-- | README.md | 13 | ||||
| -rw-r--r-- | defaults/main.yml | 8 | ||||
| -rw-r--r-- | meta/argument_specs.yml | 5 | ||||
| -rw-r--r-- | molecule/default/converge.yml | 6 | ||||
| -rw-r--r-- | molecule/default/tests/test_client_setup.py | 27 | ||||
| -rw-r--r-- | tasks/client_create_scripts_each.yml | 2 |
6 files changed, 60 insertions, 1 deletions
@@ -156,11 +156,24 @@ will be backed up by Borg. ```yaml borg_compression: zstd # -C argument +borg_create_additional_arguments: "" # Additional borg create options borg_passphrase: "" # Env variable borg_included_dirs: [] # Positional arguments borg_excluded_dirs: [] # --exclude arguments ``` +`borg_create_additional_arguments` lets you pass additional options to `borg +create`. These arguments are appended after all role-defined options, so +user-specified options can override defaults. For example: + +```yaml +# Add verbose output +borg_create_additional_arguments: "--stats --list --filter=AME" + +# Stay in one filesystem and exclude caches +borg_create_additional_arguments: "--one-file-system --exclude-caches" +``` + To decrypt your backups without the client, we store the decryption keys in a YAML file in your Ansible repository. You require the decryption keys as well as access to the repository files on the Borg server to access the backups. diff --git a/defaults/main.yml b/defaults/main.yml index 2d71d58..c508975 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -121,6 +121,14 @@ borg_backup_name_format: "{hostname}-{now:%Y-%m-%dT%H:%M:%S}" # https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-compression borg_compression: zstd +# Additional arguments passed to `borg create`. +# These are appended to the command line after all role-defined options, +# allowing user-specified options to override defaults. +# Examples: "--stats --list --filter=AME" or "--one-file-system --exclude-caches" +# Note: If you specify -C/--compression here, it will override borg_compression. +# See: https://borgbackup.readthedocs.io/en/stable/usage/create.html +borg_create_additional_arguments: "" + # This is a list of files and directories to be backed up in the systemd job. # In case you leave this empty, the role will not create an automatic backup job borg_included_dirs: [] diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml index a6e640c..518b881 100644 --- a/meta/argument_specs.yml +++ b/meta/argument_specs.yml @@ -81,6 +81,11 @@ argument_specs: required: false default: zstd + borg_create_additional_arguments: + type: str + required: false + default: "" + borg_included_dirs: type: list elements: str diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 21d4899..504758d 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -94,6 +94,8 @@ - 1 - TEMPFAIL borg_compression: lz4 + borg_create_additional_arguments: >- + -C zlib,6 borg_systemd_oncalendar: "*-*-* 03:00:00" borg_included_dirs: - /etc @@ -176,6 +178,8 @@ borg_mode_append_only: true borg_storage_quota: 10G borg_compression: zstd + borg_create_additional_arguments: >- + --stats --list --filter=AME borg_included_dirs: - /etc borg_excluded_dirs: [] @@ -190,6 +194,8 @@ borg_mode_append_only: false borg_storage_quota: 50G borg_compression: lz4 + borg_create_additional_arguments: >- + --one-file-system --exclude-caches borg_included_dirs: - /home borg_excluded_dirs: diff --git a/molecule/default/tests/test_client_setup.py b/molecule/default/tests/test_client_setup.py index f59c6db..78e751a 100644 --- a/molecule/default/tests/test_client_setup.py +++ b/molecule/default/tests/test_client_setup.py @@ -301,6 +301,33 @@ class TestBackupScript: else: pytest.fail(f"Unexpected hostname: {hostname}") + def test_backup_script_contains_additional_arguments(self, host): + hostname = host.backend.get_hostname() + + if hostname == "borg-client-multi-keys": + script1 = host.file("/usr/local/bin/run_borg_backup@configs-keys") + script2 = host.file("/usr/local/bin/run_borg_backup@home-data-keys") + assert "--stats" in script1.content_string + assert "--list" in script1.content_string + assert "--filter=AME" in script1.content_string + assert "--one-file-system" in script2.content_string + assert "--exclude-caches" in script2.content_string + elif hostname == "borg-client-2": + script = host.file("/usr/local/bin/run_borg_backup") + content = script.content_string + assert "-C zlib,6" in content + + def test_backup_script_compression_override(self, host): + hostname = host.backend.get_hostname() + if hostname != "borg-client-2": + return + + script = host.file("/usr/local/bin/run_borg_backup") + content = script.content_string + + assert "-C lz4" in content + assert "-C zlib,6" in content + def test_backup_script_contains_borg_rsh_when_per_repo(self, host): hostname = host.backend.get_hostname() per_repo = get_client_ssh_key_per_repo(host) diff --git a/tasks/client_create_scripts_each.yml b/tasks/client_create_scripts_each.yml index e185013..6056b81 100644 --- a/tasks/client_create_scripts_each.yml +++ b/tasks/client_create_scripts_each.yml @@ -27,7 +27,7 @@ {% if borg_ssh_key_per_repo %} export BORG_RSH="ssh -i {{ borg_ssh_key_path }}" {% endif %} - borg create -C {{ borg_compression }} \ + borg create -C {{ borg_compression }}{% if borg_create_additional_arguments %} {{ borg_create_additional_arguments }}{% endif %} \ {{ borg_server_user }}@{{ borg_server_host_url }}:{{ borg_server_user_home }}/{{ borg_repo_name }}::{{ borg_backup_name_format }} \ {{ borg_included_dirs | map('quote') | join(' ') }} \ {% for e in (borg_excluded_dirs | map('quote')) %} --exclude {{ e }} {% endfor %} |