2020-05-01 10:56:07 +02:00
|
|
|
#!/usr/bin/env bash
|
2019-08-14 16:00:22 +02:00
|
|
|
# {{ ansible_managed }}
|
|
|
|
# Backup script for {{ item.src|default('stdin') }}
|
2020-11-20 15:56:30 +01:00
|
|
|
# This file is to cleanup your backup archive and move some snapshots to a external storage.
|
|
|
|
|
2019-08-14 16:00:22 +02:00
|
|
|
|
|
|
|
export RESTIC_REPOSITORY={{ restic_repos[item.repo].location }}
|
2020-06-03 08:52:02 +02:00
|
|
|
export RESTIC_PASSWORD='{{ restic_repos[item.repo].password | regex_replace('\'', '\'\\\'\'') }}'
|
2019-08-14 16:00:22 +02:00
|
|
|
BACKUP_NAME={{ item.name }}
|
2020-11-20 15:56:30 +01:00
|
|
|
|
|
|
|
{% if item.src is defined -%}
|
|
|
|
# BACKUP_SOURCE={{ item.src }}
|
|
|
|
{%- endif %}
|
|
|
|
|
2019-09-11 11:29:36 +02:00
|
|
|
set -euxo pipefail
|
2020-11-20 15:56:30 +01:00
|
|
|
|
|
|
|
|
2019-08-14 16:00:22 +02:00
|
|
|
{#
|
|
|
|
Define Tags
|
|
|
|
#}
|
|
|
|
{% macro tags(tags) -%}
|
2019-09-11 11:29:36 +02:00
|
|
|
{% if tags is defined and (tags|length>0) %}{% for tag in tags %} --tag {{ tag }}{% endfor %}{% endif %}
|
|
|
|
{%- endmacro %}
|
|
|
|
{#
|
|
|
|
Define Keeped Tags
|
|
|
|
#}
|
|
|
|
{% macro keep_tags(tags) -%}
|
|
|
|
{% if tags is defined and (tags|length>0) %}{% for tag in tags %} --keep-tag {{ tag }}{% endfor %}{% endif %}
|
2019-08-14 16:00:22 +02:00
|
|
|
{%- endmacro %}
|
2020-11-20 15:56:30 +01:00
|
|
|
|
|
|
|
|
2019-08-14 16:00:22 +02:00
|
|
|
{#
|
|
|
|
Define Hostname
|
|
|
|
#}
|
|
|
|
{% macro hostname(h) -%}
|
|
|
|
{% if h is defined %} --hostname {{ h }}{% endif %}
|
|
|
|
{%- endmacro %}
|
|
|
|
{#
|
|
|
|
Define stdin filename
|
|
|
|
#}
|
|
|
|
{% macro stdin_filename(n) -%}
|
|
|
|
{% if n is defined %} --stdin-filename {{ n }}{% endif %}
|
|
|
|
{%- endmacro %}
|
|
|
|
{#
|
|
|
|
Define path
|
|
|
|
#}
|
|
|
|
{% macro path(repo) -%}
|
2019-09-11 15:58:57 +02:00
|
|
|
{% if repo.src is defined and repo.src != None and (repo.src|length>0) %}{{ repo.src }}{% else %}{{ repo.stdin_filename }}{% endif %}
|
2019-08-14 16:00:22 +02:00
|
|
|
{%- endmacro %}
|
|
|
|
{#
|
|
|
|
Define retention pattern
|
|
|
|
#}
|
|
|
|
{% macro retention_pattern(repo) -%}
|
2019-09-11 11:29:36 +02:00
|
|
|
{% if repo.keep_last is defined and repo.keep_last != None %}--keep-last {{ item.keep_last }}{% endif %} \
|
|
|
|
{% if repo.keep_hourly is defined and repo.keep_hourly != None %}--keep-hourly {{ item.keep_hourly }}{% endif %} \
|
|
|
|
{% if repo.keep_daily is defined and repo.keep_daily != None %}--keep-daily {{ item.keep_daily }}{% endif %} \
|
|
|
|
{% if repo.keep_weekly is defined and repo.keep_weekly != None %}--keep-weekly {{ item.keep_weekly }}{% endif %} \
|
|
|
|
{% if repo.keep_monthly is defined and repo.keep_monthly != None %}--keep-monthly {{ item.keep_monthly }}{% endif %} \
|
|
|
|
{% if repo.keep_yearly is defined and repo.keep_yearly != None %}--keep-yearly {{ item.keep_yearly }}{% 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 %}
|
2019-08-14 16:00:22 +02:00
|
|
|
{%- endmacro %}
|
2020-06-05 09:01:36 +02:00
|
|
|
|
|
|
|
{% 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 %}
|
2019-08-14 16:00:22 +02:00
|
|
|
{#
|
|
|
|
Define backup commands
|
|
|
|
#}
|
2020-11-20 15:56:30 +01:00
|
|
|
{{ restic_install_path }}/restic forget {{ retention_pattern(item) }} {% if item.prune is defined and item.prune == true %}--prune{% endif %}
|