From c6bacae87e3e927258a40e5513ccfc26793b88e5 Mon Sep 17 00:00:00 2001 From: Konstantin Gizdov Date: Tue, 9 Feb 2021 01:10:52 +0200 Subject: [PATCH] enable configuration of archive name format, prune and check prefixes as per borgmatic docs --- README.md | 4 +++- defaults/main.yml | 4 ++++ templates/config.yaml.j2 | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4aa9cc5..d8ee436 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,9 @@ $ git clone https://github.com/borgbase/ansible-role-borgbackup.git roles/ansibl - `borgmatic_cron_checks_day`: Day when cron job for infrequent checks will run. Defaults to `{{ 28 | random }}` - `borgmatic_cron_checks_hour`: Hour when cron job for infrequent checks will run. Defaults to `{{ range(7, 24) | random }}` - `borgmatic_cron_checks_minute`: Minute when cron job for infrequent checks will run. Defaults to `{{ 59 | random }}` - +- `borg_archive_name_format`: The format for the archive name, e.g. `{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}`. Defaults to `{hostname}-{now}` +- `borg_prune_prefix`: The prefix used to select archives to prune. Defaults to `{hostname}-` +- `borg_check_prefix`: The prefix used to select archives to check for consistency. Defaults to `{hostname}-` ### Optional Arguments for [BorgBase.com](https://www.borgbase.com) repository auto creation This role can also set up a new repository on BorgBase, using the arguments below. Thanks to [Philipp Rintz](https://github.com/p-rintz) for contribution of this feature. diff --git a/defaults/main.yml b/defaults/main.yml index c3969b9..55ac7da 100755 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -43,3 +43,7 @@ borgmatic_cron_minute: "{{ 59 | random(seed=inventory_hostname) }}" borgmatic_cron_checks_day: "{{ range(1, 28) | random(seed=inventory_hostname) }}" borgmatic_cron_checks_hour: "{{ range(9, 24) | random(seed=inventory_hostname) }}" borgmatic_cron_checks_minute: "{{ 59 | random(seed=inventory_hostname) }}" +# the following are optional and defined by the user as needed +# borg_archive_name_format: '{hostname}-{now}' +# borg_prune_prefix: '{hostname}-' +# borg_check_prefix: '{hostname}-' diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index 60c44a7..ca3d3dc 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -96,6 +96,8 @@ storage: # prefix in the consistency section as well. {% if borg_archive_name_format is defined %} archive_name_format: '{{ borg_archive_name_format | replace("'", "") }}' +{% elif borg_prune_prefix is defined %} + archive_name_format: '{{ borg_prune_prefix | replace("'", "") }}-{now}' {% else %} archive_name_format: '{hostname}-{now:%Y-%m-%d-%H%M%S}' {% endif %} @@ -145,7 +147,12 @@ retention: # When pruning, only consider archive names starting with this prefix. # Borg placeholders can be used. See the output of "borg help placeholders" for # details. Default is "{hostname}-". +{% if borg_prune_prefix is defined %} + prefix: '{{ borg_prune_prefix | replace("'", "") }}' +{% else %} +{{ ('No custom archive name format provided.' if borg_archive_name_format is defined) | mandatory('Custom value for borg_archive_name_format was specified without providing the matching prune prefix. Please specify borg_prune_prefix as well.') }} prefix: '{hostname}-' +{% endif %} # Consistency checks to run after backups. See # https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check and @@ -170,7 +177,14 @@ consistency: # When performing the "archives" check, only consider archive names starting with # this prefix. Borg placeholders can be used. See the output of # "borg help placeholders" for details. Default is "{hostname}-". +{% if borg_check_prefix is defined %} + prefix: '{{ borg_check_prefix | replace("'", "") }}' +{% elif borg_prune_prefix is defined %} + prefix: '{{ borg_prune_prefix | replace("'", "") }}' +{% else %} +{{ ('No custom archive name format provided.' if borg_archive_name_format is defined) | mandatory('Custom value for borg_archive_name_format was specified without providing the matching consistency check prefix. Please specify borg_check_prefix as well.') }} prefix: '{hostname}-' +{% endif %} # Shell commands or scripts to execute before and after a backup or if an error has occurred. # IMPORTANT: All provided commands and scripts are executed with user permissions of borgmatic.