Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable configuration of archive name format, prune and consistency check prefixes #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:%Y-%m-%d-%H%M%S}`
- `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.
Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:%Y-%m-%d-%H%M%S}'
# borg_prune_prefix: '{hostname}-'
# borg_check_prefix: '{hostname}-'
18 changes: 18 additions & 0 deletions templates/config.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ 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("'", "") }}'
{% elif borg_prune_prefix is defined %}
archive_name_format: '{{ borg_prune_prefix | replace("'", "") }}-{now:%Y-%m-%d-%H%M%S}'
{% else %}
archive_name_format: '{hostname}-{now:%Y-%m-%d-%H%M%S}'
{% endif %}

# Bypass Borg error about a repository that has been moved.
relocated_repo_access_is_ok: {{ borgmatic_relocated_repo_access_is_ok }}
Expand Down Expand Up @@ -141,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 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 %}

# Consistency checks to run after backups. See
# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check and
Expand All @@ -166,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 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 %}

# 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.
Expand Down