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

Merge pull request #14 from arillso/12-exclude-options

Add the possibility to exclude certain files
This commit is contained in:
Matthias Leutenegger 2020-08-05 12:20:36 +02:00 committed by GitHub
commit 266b0c16ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 3 deletions

View file

@ -4,7 +4,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
and [human-readable changelog](https://keepachangelog.com/en/1.0.0/). and [human-readable changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased ## Unreleased
### Added: ### Added
* Config option to exclude files
* Contributing guide * Contributing guide
## [0.2.6] 2020-06-05 ## [0.2.6] 2020-06-05

View file

@ -136,6 +136,25 @@ Available variables:
| `schedule_hour` | no (`*`) | Hour when the job is run. ( 0-23, *, */2, etc ) | | `schedule_hour` | no (`*`) | Hour when the job is run. ( 0-23, *, */2, etc ) |
| `schedule_weekday` | no (`*`) | Weekday when the job is run. ( 0-6 for Sunday-Saturday, *, etc ) | | `schedule_weekday` | no (`*`) | Weekday when the job is run. ( 0-6 for Sunday-Saturday, *, etc ) |
| `schedule_month` | no (`*`) | Month when the job is run. ( 1-12, *, */2, etc ) | | `schedule_month` | no (`*`) | Month when the job is run. ( 1-12, *, */2, etc ) |
| `exclude` | no (`{}`) | Allows you to specify files to exclude. See [Exclude](#exclude) for reference. |
#### Exclude
the `exclude` key on a backup allows you to specify multiple files to exclude or
files to look for filenames to be excluded. You can specify the following keys:
```yaml
exclude:
exclude_cache: true
exclude:
- /path/to/file
iexclude:
- /path/to/file
exclude_file:
- /path/to/file
exclude_if_present:
- /path/to/file
```
Please refer to the use of the specific keys to the
[documentation](https://restic.readthedocs.io/en/latest/040_backup.html#excluding-files).
## Dependencies ## Dependencies
none none

View file

@ -62,6 +62,32 @@ set -euxo pipefail
{% if repo.keep_within is defined and repo.keep_within != None %}--keep-within {{ item.keep_within }}{% endif %} \ {% if repo.keep_within is defined and repo.keep_within != None %}--keep-within {{ item.keep_within }}{% endif %} \
{% if repo.keep_tag is defined and (repo.keep_tag|length>0) %}{{ keep_tags(repo.keep_tag) }}{% endif %} {% if repo.keep_tag is defined and (repo.keep_tag|length>0) %}{{ keep_tags(repo.keep_tag) }}{% endif %}
{%- endmacro %} {%- endmacro %}
{% macro exclude(exclude) %}
{% if exclude.exclude_cache is defined and exclude.exclude_cache == true %}
--exclude-cache \
{% endif %}
{% if exclude.exclude is defined %}
{% for path in exclude.exclude %}
--exclude {{ path }} \
{% endfor %}
{% endif %}
{% if exclude.iexclude is defined %}
{% for path in exclude.iexclude %}
--iexclude {{ path }} \
{% endfor %}
{% endif %}
{% if exclude.exclude_file is defined %}
{% for path in exclude.exclude_file %}
--exclude-file {{ path }} \
{% endfor %}
{% endif %}
{% if exclude.exclude_if_present is defined %}
{% for path in exclude.exclude_if_present %}
--exclude-if-present {{ path }} \
{% endfor %}
{% endif %}
{% endmacro %}
{# {#
Define backup commands Define backup commands
#} #}
@ -71,9 +97,17 @@ else
MODE_TAG="--tag cron" MODE_TAG="--tag cron"
fi fi
{% if item.stdin is defined and item.stdin == true %} {% if item.stdin is defined and item.stdin == true %}
{{ item.stdin_cmd }} | {{ restic_install_path }}/restic backup --stdin $MODE_TAG {{ tags(item.tags) }} {{ stdin_filename(item.stdin_filename) }} $@ {{ item.stdin_cmd }} | {{ restic_install_path }}/restic backup \
--stdin $MODE_TAG \
{{ tags(item.tags) }} \
{{ stdin_filename(item.stdin_filename) }} \
{% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \
$@
{% else %} {% else %}
{{ restic_install_path }}/restic backup $BACKUP_SOURCE $MODE_TAG {{ tags(item.tags) }} $@ {{ restic_install_path }}/restic backup $BACKUP_SOURCE $MODE_TAG \
{{ tags(item.tags) }} \
{% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \
$@
{% endif %} {% endif %}
{# {#
Define stdin forget commands Define stdin forget commands