mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2024-11-19 19:07:42 +01:00
Allow per-app configurations (#9)
This PR allows for multiple per application borgmatic configurations as per this article: https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/
This commit is contained in:
parent
0fd01bc13f
commit
0fcbef29a9
@ -10,7 +10,6 @@ An Ansible Role that sets up automated remote backups on the target machine. Use
|
|||||||
|
|
||||||
### Optional Arguments
|
### Optional Arguments
|
||||||
- `borg_encryption_passphrase`: Password to use for repokey or keyfile. Empty if repo is unencrypted.
|
- `borg_encryption_passphrase`: Password to use for repokey or keyfile. Empty if repo is unencrypted.
|
||||||
- `borgmatic_config_name`: Name to use for the borgmatic config file. Defaults to `config.yml`
|
|
||||||
- `borgmatic_large_repo`: Does repo-checking on a weekly basis instead of daily. Good for repos with 100GB+ size.
|
- `borgmatic_large_repo`: Does repo-checking on a weekly basis instead of daily. Good for repos with 100GB+ size.
|
||||||
- `borgmatic_failure_command`: Run this command when an error occurs. E.g. `curl -s -F "token=xxx" -F "user=xxx" -F "message=Error during backup" https://api.pushover.net/1/messages.json`
|
- `borgmatic_failure_command`: Run this command when an error occurs. E.g. `curl -s -F "token=xxx" -F "user=xxx" -F "message=Error during backup" https://api.pushover.net/1/messages.json`
|
||||||
- `borg_exclude_patterns`: Paths or patterns to exclude from backup. See [official documentation](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-patterns) for more.
|
- `borg_exclude_patterns`: Paths or patterns to exclude from backup. See [official documentation](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-patterns) for more.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
---
|
---
|
||||||
borg_encryption_passphrase: ''
|
borg_encryption_passphrase: ''
|
||||||
borg_exclude_patterns: []
|
borg_exclude_patterns: []
|
||||||
borgmatic_config_name: config.yaml
|
|
||||||
borgmatic_large_repo: false
|
borgmatic_large_repo: false
|
||||||
borgmatic_failure_command: echo "`date` - Error while creating a backup."
|
borgmatic_failure_command: echo "`date` - Error while creating a backup."
|
||||||
borg_one_file_system: true
|
borg_one_file_system: true
|
||||||
|
@ -52,9 +52,9 @@
|
|||||||
borg_repository: "{{ repo_creation['data']['repoPath'] }}"
|
borg_repository: "{{ repo_creation['data']['repoPath'] }}"
|
||||||
when: create_repo
|
when: create_repo
|
||||||
|
|
||||||
- name: Ensures /etc/borgmatic exists
|
- name: Ensures /etc/borgmatic.d exists
|
||||||
file:
|
file:
|
||||||
path: /etc/borgmatic
|
path: /etc/borgmatic.d
|
||||||
state: directory
|
state: directory
|
||||||
mode: 0700
|
mode: 0700
|
||||||
owner: root
|
owner: root
|
||||||
@ -62,8 +62,12 @@
|
|||||||
- name: Add Borgmatic Configuration
|
- name: Add Borgmatic Configuration
|
||||||
template:
|
template:
|
||||||
src: config.yaml.j2
|
src: config.yaml.j2
|
||||||
dest: "/etc/borgmatic/{{ borgmatic_config_name }}"
|
dest: "/etc/borgmatic.d/{{ item | regex_replace('\\/$', '') | basename }}.yaml"
|
||||||
mode: 0600
|
mode: 0600
|
||||||
|
with_items: "{{ borg_source_directories }}"
|
||||||
|
|
||||||
|
- debug: msg="/etc/borgmatic.d/{{ item | regex_replace('\\/$', '') | basename }}.yaml"
|
||||||
|
with_items: "{{ borg_source_directories }}"
|
||||||
|
|
||||||
- name: Add cron-job for borgmatic (large repo, create and check separate)
|
- name: Add cron-job for borgmatic (large repo, create and check separate)
|
||||||
block:
|
block:
|
||||||
@ -73,7 +77,7 @@
|
|||||||
minute: "{{ 59 |random }}"
|
minute: "{{ 59 |random }}"
|
||||||
user: "root"
|
user: "root"
|
||||||
cron_file: borgmatic
|
cron_file: borgmatic
|
||||||
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --create --prune"
|
job: "/usr/local/bin/borgmatic --create --prune"
|
||||||
- cron:
|
- cron:
|
||||||
name: "borgmatic-check"
|
name: "borgmatic-check"
|
||||||
day: "{{ 28 | random }}"
|
day: "{{ 28 | random }}"
|
||||||
@ -81,7 +85,7 @@
|
|||||||
minute: "{{ 59 | random }}"
|
minute: "{{ 59 | random }}"
|
||||||
user: "root"
|
user: "root"
|
||||||
cron_file: borgmatic
|
cron_file: borgmatic
|
||||||
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }} --check"
|
job: "/usr/local/bin/borgmatic --check"
|
||||||
when: borgmatic_large_repo
|
when: borgmatic_large_repo
|
||||||
|
|
||||||
- name: Add cron-job for borgmatic (normal-sized repo)
|
- name: Add cron-job for borgmatic (normal-sized repo)
|
||||||
@ -92,7 +96,7 @@
|
|||||||
minute: "{{ 59 | random }}"
|
minute: "{{ 59 | random }}"
|
||||||
user: "root"
|
user: "root"
|
||||||
cron_file: borgmatic
|
cron_file: borgmatic
|
||||||
job: "/usr/local/bin/borgmatic -c /etc/borgmatic/{{ borgmatic_config_name }}"
|
job: "/usr/local/bin/borgmatic"
|
||||||
- cron:
|
- cron:
|
||||||
name: "borgmatic-check"
|
name: "borgmatic-check"
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
# Full config: https://gist.github.com/coaxial/46e36d89d7b81887f7275d587fe04c44
|
# Full config: https://gist.github.com/coaxial/46e36d89d7b81887f7275d587fe04c44
|
||||||
|
{% set archive_prefix = item | regex_replace("\\/$", "") | basename %}
|
||||||
location:
|
location:
|
||||||
source_directories:
|
source_directories:
|
||||||
{% for dir in borg_source_directories %}
|
- {{ item }}
|
||||||
- {{ dir }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Stay in same file system (do not cross mount points).
|
# Stay in same file system (do not cross mount points).
|
||||||
one_file_system: {{ borg_one_file_system }}
|
one_file_system: {{ borg_one_file_system }}
|
||||||
@ -73,7 +72,7 @@ storage:
|
|||||||
# also specify a prefix in the retention section to avoid accidental pruning of
|
# 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
|
# archives with a different archive name format. And you should also specify a
|
||||||
# prefix in the consistency section as well.
|
# prefix in the consistency section as well.
|
||||||
archive_name_format: '{hostname}-{now}'
|
archive_name_format: '{{ archive_prefix }}-{now}'
|
||||||
|
|
||||||
# Retention policy for how many backups to keep in each category. See
|
# Retention policy for how many backups to keep in each category. See
|
||||||
# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-prune for details.
|
# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-prune for details.
|
||||||
@ -117,7 +116,7 @@ retention:
|
|||||||
# When pruning, only consider archive names starting with this prefix.
|
# When pruning, only consider archive names starting with this prefix.
|
||||||
# Borg placeholders can be used. See the output of "borg help placeholders" for
|
# Borg placeholders can be used. See the output of "borg help placeholders" for
|
||||||
# details. Default is "{hostname}-".
|
# details. Default is "{hostname}-".
|
||||||
prefix: '{hostname}-'
|
prefix: '{{ archive_prefix }}-'
|
||||||
|
|
||||||
# Consistency checks to run after backups. See
|
# Consistency checks to run after backups. See
|
||||||
# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check and
|
# https://borgbackup.readthedocs.org/en/stable/usage.html#borg-check and
|
||||||
@ -138,7 +137,7 @@ consistency:
|
|||||||
# When performing the "archives" check, only consider archive names starting with
|
# When performing the "archives" check, only consider archive names starting with
|
||||||
# this prefix. Borg placeholders can be used. See the output of
|
# this prefix. Borg placeholders can be used. See the output of
|
||||||
# "borg help placeholders" for details. Default is "{hostname}-".
|
# "borg help placeholders" for details. Default is "{hostname}-".
|
||||||
prefix: '{hostname}-'
|
prefix: '{{ archive_prefix }}-'
|
||||||
|
|
||||||
# Shell commands or scripts to execute before and after a backup or if an error has occurred.
|
# 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.
|
# IMPORTANT: All provided commands and scripts are executed with user permissions of borgmatic.
|
||||||
|
Loading…
Reference in New Issue
Block a user