1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic.git synced 2024-12-11 23:41:32 +01:00

quote BACKUP_SOURCES, add service_options

This commit is contained in:
Karl DeBisschop 2024-01-27 17:49:08 -05:00
parent fa0901b0b3
commit 928d73d268
3 changed files with 32 additions and 12 deletions

View file

@ -153,13 +153,14 @@ Available variables:
| ------------------ |:-----------------------------:| ------------ | | ------------------ |:-----------------------------:| ------------ |
| `name` | yes | The name of this backup. Used together with pruning and scheduling and needs to be unique. | | `name` | yes | The name of this backup. Used together with pruning and scheduling and needs to be unique. |
| `repo` | yes | The name of the repository to backup to. | | `repo` | yes | The name of the repository to backup to. |
| `src` | yes (unless `stdin` == `true`) | The source directory or file | | `src` | no (see Note) | The source directory or file |
| `stdin` | no | Is this backup created from a [stdin](https://restic.readthedocs.io/en/stable/040_backup.html#reading-data-from-stdin)? | | `stdin` | no (see Note) | Is this backup created from a [stdin](https://restic.readthedocs.io/en/stable/040_backup.html#reading-data-from-stdin)? |
| `stdin_cmd` | no (yes if `stdin` == `true`) | The command to produce the stdin. | | `stdin_cmd` | no (yes if `stdin` == `true`) | The command to produce the stdin. |
| `stdin_filename` | no | The filename used in the repository. | | `stdin_filename` | no | The filename used in the repository. |
| `pre_backup_cmd` | no | A command to run before backup, typically used to dump databases to disk | | `pre_backup_cmd` | no | A command to run before backup, typically used to dump databases to disk |
| `tags` | no | Array of default tags | | `tags` | no | Array of default tags |
| `options` | no | Array of additional options to restic backup | | `options` | no (see Note) | Array of additional options to restic backup |
| `forget_snapshots` | no | If set to false, do not forget snapshots with each run (
| `keep_last` | no | If set, only keeps the last n snapshots. | | `keep_last` | no | If set, only keeps the last n snapshots. |
| `keep_hourly` | no | If set, only keeps the last n hourly snapshots. | | `keep_hourly` | no | If set, only keeps the last n hourly snapshots. |
| `keep_daily` | no | If set, only keeps the last n daily snapshots. | | `keep_daily` | no | If set, only keeps the last n daily snapshots. |
@ -183,6 +184,8 @@ Available variables:
| `monitoring_call` | no | A command that will be called if the backup is *successful*. Useful for heartbeat monitoring systems that warn when no heartbeat is received. Use the full command, you need to run. Example: `curl https://monitoring.example.com/api/push/E9Wzm4lJ2O?status=up&msg=OK&ping=` | | `monitoring_call` | no | A command that will be called if the backup is *successful*. Useful for heartbeat monitoring systems that warn when no heartbeat is received. Use the full command, you need to run. Example: `curl https://monitoring.example.com/api/push/E9Wzm4lJ2O?status=up&msg=OK&ping=` |
| `niceness` | no | If set, runs any scheduled backup with given [niceness-value](https://en.wikipedia.org/wiki/Nice_(Unix)). On Linux -20 is highest priority, 0 default and 19 is lowest priority. 10 is a common low priority assigned to backup routines on production systems. | | `niceness` | no | If set, runs any scheduled backup with given [niceness-value](https://en.wikipedia.org/wiki/Nice_(Unix)). On Linux -20 is highest priority, 0 default and 19 is lowest priority. 10 is a common low priority assigned to backup routines on production systems. |
Note: One of src or stdin_cmd must be defined; or one of --files-from, --files-from-verbatim, or --files-from-raw must be provided in options.
Example: Example:
```yaml ```yaml
restic_backups: restic_backups:
@ -208,7 +211,14 @@ restic_backups:
scheduled: true scheduled: true
schedule_oncalendar: '*-*-* 02:00:00' schedule_oncalendar: '*-*-* 02:00:00'
pre_backup_cmd: cd /var/dumped_data && mariadb -N -e 'show databases' | while read dbname; do mariadb-dump --complete-insert --routines --triggers --single-transaction "$dbname" > "$dbname".sql; done pre_backup_cmd: cd /var/dumped_data && mariadb -N -e 'show databases' | while read dbname; do mariadb-dump --complete-insert --routines --triggers --single-transaction "$dbname" > "$dbname".sql; done
specified_files:
name: specified_files
repo: remote
options:
- --files-from
- /etc/restic-specified-files.txt
scheduled: true
schedule_oncalendar: '*-*-* 03:00:00'
``` ```
> You can also specify restic_backups as an array, which is a legacy feature and > You can also specify restic_backups as an array, which is a legacy feature and

View file

@ -7,6 +7,11 @@ After=fstrim.timer
[Service] [Service]
Type=oneshot Type=oneshot
{% if item.service_options is defined %}
{% for key, value in item.service_options.items() %}
{{key}}={{value}}
{% endfor %}
{% endif %}
{% if item.lvm is defined %} {% if item.lvm is defined %}
PrivateMounts=on PrivateMounts=on
{% endif %} {% endif %}

View file

@ -79,10 +79,10 @@ export B2_ACCOUNT_ID={{ restic_repos[item.repo].b2_account_id }}
export B2_ACCOUNT_KEY={{ restic_repos[item.repo].b2_account_key }} export B2_ACCOUNT_KEY={{ restic_repos[item.repo].b2_account_key }}
{% endif %} {% endif %}
{% if item.src is defined and item.src is string %} {% if item.src is defined and item.src is string %}
BACKUP_SOURCE={{ item.src }} BACKUP_SOURCE="{{ item.src }}"
{% endif %} {% endif %}
{% if item.src is defined and item.src.__class__.__name__ =='list' %} {% if item.src is defined and item.src.__class__.__name__ =='list' %}
BACKUP_SOURCE={{ item.src| join(' ') }} BACKUP_SOURCE="{{ item.src| join(' ') }}"
{% endif %} {% endif %}
{% if item.lvm is defined %} {% if item.lvm is defined %}
@ -203,9 +203,11 @@ set -uxo pipefail
{%- endmacro %} {%- endmacro %}
{% macro options(options) %} {% macro options(options) %}
{% for option in options %} {% if options is defined %}
{{ option }} \ {% for option in options %}
{% endfor %} {{ option }} \
{% endfor %}
{% endif %}
{% endmacro %} {% endmacro %}
{% macro exclude(exclude) %} {% macro exclude(exclude) %}
@ -290,7 +292,7 @@ case $? in
*) *)
echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ backup_result_log }} echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ backup_result_log }}
{% if item.mail_on_error is defined and item.mail_on_error == true %} {% if item.mail_on_error is defined and item.mail_on_error == true %}
mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S'). mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong in backups while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S').
{%- if item.src is defined -%} {%- if item.src is defined -%}
{{ ' ' }}We tried to backup '{{ item.src }}'. {{ ' ' }}We tried to backup '{{ item.src }}'.
{%- endif -%} {%- endif -%}
@ -306,6 +308,7 @@ esac
{# {#
Define stdin forget commands Define stdin forget commands
#} #}
{% if item.forget_snapshots is not defined or item.forget_snapshots %}
{{ restic_install_path }}/restic forget {{ paths(item) }} {{ retention_pattern(item) }} {% if item.prune is defined and item.prune == true %}--prune{% endif %} {{ forget_output_log }} {{ restic_install_path }}/restic forget {{ paths(item) }} {{ retention_pattern(item) }} {% if item.prune is defined and item.prune == true %}--prune{% endif %} {{ forget_output_log }}
if [[ $? -eq 0 ]] if [[ $? -eq 0 ]]
then then
@ -316,12 +319,14 @@ then
else else
echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ forget_result_log }} echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ forget_result_log }}
{% if item.mail_on_error is defined and item.mail_on_error == true %} {% if item.mail_on_error is defined and item.mail_on_error == true %}
mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S'). mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong in forgetting while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S').
{%- if item.src is defined -%} {%- if item.src is defined -%}
{{ ' ' }}We tried to backup '{{ item.src }}'. {{ ' ' }}We tried to forget '{{ item.src }}'.
{%- endif -%} {%- endif -%}
{{ ' ' }}Please repair the restic-{{ item.name | replace(' ', '') }} job." {{ ' ' }}Please repair the restic-{{ item.name | replace(' ', '') }} job."
{% endif %} {% endif %}
fi fi
{% endif %}
rm -f $pid # remove pid file just before exiting rm -f $pid # remove pid file just before exiting
exit exit