enable configuration of archive name format, prune and check prefixes as per borgmatic docs

This commit is contained in:
Konstantin Gizdov 2021-02-09 01:10:52 +02:00
parent 2b5a5aea46
commit c6bacae87e
3 changed files with 21 additions and 1 deletions

View File

@ -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.

View File

@ -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}-'

View File

@ -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.