From 5e6ba4a1dd421e669fc728407cab84042ef0e6fe Mon Sep 17 00:00:00 2001 From: Konstantin Gizdov Date: Wed, 9 Dec 2020 17:58:51 +0200 Subject: [PATCH 1/3] allow configuring of archive format --- templates/config.yaml.j2 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index 94de878..0013b82 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -94,7 +94,11 @@ storage: # also specify a prefix in the retention section to avoid accidental pruning of # archives with a different archive name format. And you should also specify a # prefix in the consistency section as well. +{% if borg_archive_name_format is defined %} + archive_name_format: '{{ borg_archive_name_format | replace("'", "") }}' +{% else %} archive_name_format: '{hostname}-{now}' +{% endif %} # Bypass Borg error about a repository that has been moved. relocated_repo_access_is_ok: {{ borgmatic_relocated_repo_access_is_ok }} From 962b5a9b4043d26bb779d7c6d9f33c1ce5d45686 Mon Sep 17 00:00:00 2001 From: Konstantin Gizdov Date: Tue, 9 Feb 2021 01:10:52 +0200 Subject: [PATCH 2/3] 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 4312d31..6a804df 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,9 @@ $ git clone https://github.com/borgbase/ansible-role-borgbackup.git roles/borgba - `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 949e9ce..454ac8c 100755 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -42,3 +42,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 0013b82..58ce160 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}' {% 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. From e5bbfb28bac096cb0ea09a65126712798eaaffd6 Mon Sep 17 00:00:00 2001 From: Konstantin Gizdov Date: Tue, 9 Feb 2021 01:19:17 +0200 Subject: [PATCH 3/3] fix inconsistent logic --- templates/config.yaml.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index 58ce160..02eacfd 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -150,7 +150,7 @@ retention: {% 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.') }} +{{ (' # No custom archive name format provided.' if borg_archive_name_format is not 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 %} @@ -182,7 +182,7 @@ consistency: {% 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.') }} +{{ (' # No custom archive name format provided.' if borg_archive_name_format is not 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 %}