2020-05-01 10:56:07 +02:00
|
|
|
#!/usr/bin/env bash
|
2019-08-14 16:00:22 +02:00
|
|
|
# {{ ansible_managed }}
|
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-09-11 11:29:36 +02:00
|
|
|
set -euxo pipefail
|
2020-11-20 15:56:30 +01:00
|
|
|
|
2020-12-09 17:26:16 +01:00
|
|
|
{% for repo in restic_archiver__repos %}
|
2020-11-20 15:56:30 +01:00
|
|
|
|
2019-08-14 16:00:22 +02:00
|
|
|
{#
|
2020-12-09 17:26:16 +01:00
|
|
|
define macro:
|
|
|
|
how fast should we delete snapshots?
|
|
|
|
|
|
|
|
Variables are defined via defaults!
|
2019-09-11 11:29:36 +02:00
|
|
|
#}
|
2020-12-09 17:26:16 +01:00
|
|
|
{% macro retention_pattern(repo) -%}
|
|
|
|
{% if repo.keep_last is defined and repo.keep_last != None -%}
|
|
|
|
--keep-last {{ repo.keep_last }}
|
|
|
|
{%- else -%}
|
|
|
|
--keep-last {{ restic_archiver__keep }}
|
|
|
|
{%- endif %} \
|
|
|
|
{% if repo.keep_hourly is defined and repo.keep_hourly != None -%}
|
|
|
|
--keep-hourly {{ repo.keep_hourly }}
|
|
|
|
{%- else -%}
|
|
|
|
--keep-hourly {{ restic_archiver__keep_hourly }}
|
|
|
|
{%- endif %} \
|
|
|
|
{% if repo.keep_daily is defined and repo.keep_daily != None -%}
|
|
|
|
--keep-daily {{ repo.keep_daily }}
|
|
|
|
{%- else -%}
|
|
|
|
--keep-daily {{ restic_archiver__keep_daily }}
|
|
|
|
{%- endif %} \
|
|
|
|
{% if repo.keep_weekly is defined and repo.keep_weekly != None -%}
|
|
|
|
--keep-weekly {{ repo.keep_weekly }}
|
|
|
|
{%- else -%}
|
|
|
|
--keep-weekly {{ restic_archiver__keep_weekly }}
|
|
|
|
{%- endif %} \
|
|
|
|
{% if repo.keep_monthly is defined and repo.keep_monthly != None -%}
|
|
|
|
--keep-monthly {{ repo.keep_monthly }}
|
|
|
|
{%- else -%}
|
|
|
|
--keep-monthly {{ restic_archiver__keep_monthly }}
|
|
|
|
{%- endif %} \
|
|
|
|
{% if repo.keep_yearly is defined and repo.keep_yearly != None -%}
|
|
|
|
--keep-yearly {{ repo.keep_yearly }}
|
|
|
|
{%- else -%}
|
|
|
|
--keep-yearly {{ restic_archiver__keep_yearly }}
|
|
|
|
{%- endif -%}
|
|
|
|
{% if repo.keep_within is defined and repo.keep_within != None %} \
|
|
|
|
--keep-within {{ repo.keep_within }} {% endif -%}
|
2019-08-14 16:00:22 +02:00
|
|
|
{%- endmacro %}
|
2020-11-20 15:56:30 +01:00
|
|
|
|
|
|
|
|
2020-12-09 17:26:16 +01:00
|
|
|
# Settings for Server {{ repo['name'] | string }}
|
|
|
|
export RESTIC_REPOSITORY="{{ repo['location'] }}"
|
|
|
|
export RESTIC_PASSWORD='''{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}'''
|
|
|
|
BACKUP_NAME="{{ repo.name }}"
|
|
|
|
|
|
|
|
|
|
|
|
{{ restic_install_path }}/restic forget {{ retention_pattern(repo) }} {% if repo.prune is defined and repo.prune == true %}--prune{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
{% endfor %}
|