From ea143592b9402f1305a3af3e76f9e6d9b70277a4 Mon Sep 17 00:00:00 2001 From: Matthias Leutenegger Date: Fri, 5 Jun 2020 09:01:36 +0200 Subject: [PATCH 1/3] ADD: exclude option --- CHANGELOG.md | 2 ++ README.md | 19 +++++++++++++++++++ templates/restic_script_Linux.j2 | 31 ++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b951ef..50edc63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +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/). ## Unreleased +### Added +* Config option to exclude files ## [0.2.6] 2020-06-05 ### Changed diff --git a/README.md b/README.md index ae2a811..c6a40ff 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,25 @@ Available variables: | `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_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 none diff --git a/templates/restic_script_Linux.j2 b/templates/restic_script_Linux.j2 index 5f90e10..f086cc1 100644 --- a/templates/restic_script_Linux.j2 +++ b/templates/restic_script_Linux.j2 @@ -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_tag is defined and (repo.keep_tag|length>0) %}{{ keep_tags(repo.keep_tag) }}{% endif %} {%- 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 #} @@ -73,7 +99,10 @@ fi {% 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) }} $@ {% 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 %} {# Define stdin forget commands From 977ed115fb4cea008e8019685d55a6741fee7ae4 Mon Sep 17 00:00:00 2001 From: Matthias Leutenegger Date: Fri, 5 Jun 2020 09:04:03 +0200 Subject: [PATCH 2/3] FIX: link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6a40ff..433cfbf 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ exclude: - /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 ). +[documentation](https://restic.readthedocs.io/en/latest/040_backup.html#excluding-files). ## Dependencies none From 1ff31d56d72aaac1293625a4a9f378e52713ad02 Mon Sep 17 00:00:00 2001 From: Matthias Leutenegger Date: Fri, 5 Jun 2020 09:05:15 +0200 Subject: [PATCH 3/3] CHANGE: add exclude tags also to stdin command --- templates/restic_script_Linux.j2 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/templates/restic_script_Linux.j2 b/templates/restic_script_Linux.j2 index f086cc1..a20cf6e 100644 --- a/templates/restic_script_Linux.j2 +++ b/templates/restic_script_Linux.j2 @@ -97,7 +97,12 @@ else MODE_TAG="--tag cron" fi {% 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 %} {{ restic_install_path }}/restic backup $BACKUP_SOURCE $MODE_TAG \ {{ tags(item.tags) }} \