From 2904225f80ba3856efae2834f1848b9b96c8f39a Mon Sep 17 00:00:00 2001 From: L3D Date: Fri, 19 Feb 2021 13:52:46 +0100 Subject: [PATCH] try to improve template... --- templates/restic_forget_snapshots.j2 | 43 ++++++++++++++++------------ vars/main.yml | 2 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/templates/restic_forget_snapshots.j2 b/templates/restic_forget_snapshots.j2 index 00fc1c7..fc06fec 100644 --- a/templates/restic_forget_snapshots.j2 +++ b/templates/restic_forget_snapshots.j2 @@ -65,14 +65,21 @@ EOT --prune {% endif %} {%- endmacro %} +{# + +START DUING STUFF INSIDE THE RESTIC REPO FOR LOOP + +#} + +{ # try + + {% if restic_archiver__mail_report | default(false) %} - # collect info about last snapshot for mail report - restic {{ restic_archiver__default_opt }} stats latest | grep Total - {% endif %} + {% if restic_archiver__mount_required %} if mountpoint -q {{ restic_archiver__mount_disk }} then @@ -81,13 +88,13 @@ else mount -a fi {% endif %} -set -euxo pipefail # Settings for Server {{ repo['name'] | string }} export RESTIC_REPOSITORY="{{ repo['location'] }}" export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null BACKUP_NAME="{{ repo.name }}" +echo "init $BACKUP_NAME" restic {{ restic_archiver__default_opt }} forget {{ retention_pattern(repo) }} {% if restic_archiver__mail_report | default(false) %} @@ -127,20 +134,16 @@ restic {{ restic_archiver__default_opt }} check # ARCHIVE Settings for Server "{{ repo['name'] | string }}" export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null -export RESTIC_REPOSITORY2="{{ repo['location'] }}" -export RESTIC_PASSWORD2='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null BACKUP_NAME="{{ repo.name }}_archive" - +echo "init $BACKUP_NAME" {% if restic_archiver__mount_required %} -set +euxo pipefail if mountpoint -q {{ restic_archiver__mount_disk }} then echo "{{ restic_archiver__mount_disk }} is mounted" else mount -a fi -set -euxo pipefail {% endif %} # init repo if it does not exist @@ -152,22 +155,20 @@ export RESTIC_REPOSITORY2="{{ repo['archive_location'] }}" export RESTIC_PASSWORD2='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null export RESTIC_REPOSITORY="{{ repo['location'] }}" export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null - -# transfer snapshots to archive -restic {{ restic_archiver__default_opt }} copy - -{% if repo.archive_cleanup %} - {% if restic_archiver__mount_required %} -set +euxo pipefail if mountpoint -q {{ restic_archiver__mount_disk }} then echo "{{ restic_archiver__mount_disk }} is mounted" else mount -a fi -set -euxo pipefail {% endif %} + +# transfer snapshots to archive +restic {{ restic_archiver__default_opt }} copy + +{% if repo.archive_cleanup %} + # ARCHIVE CLEANUP Settings for Server "{{ repo['name'] | string }}" export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null @@ -185,10 +186,16 @@ restic {{ restic_archiver__default_opt }} check --quiet >> /tmp/mailcontent restic {{ restic_archiver__default_opt }} check {% endif %} + +} || { # catch +echo -e "

ALARM, ALRM

\n

SOMETING IN $RESTIC_REPOSITORY went wrong

" >> /tmp/mailcontent +awk 'NR==3{print "

ALARM, ALRM

\n

SOMETING IN $RESTIC_REPOSITORY went wrong

"}1' /tmp/mailcontent >> /tmp/mailcontentx +mv /tmp/mailcontentx /tmp/mailcontent +} + {% endfor %} sync -set +euxo pipefail cat <> /tmp/mailcontent


diff --git a/vars/main.yml b/vars/main.yml index a4cd779..44ddfb1 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,3 +1,3 @@ --- -playbook_version_number: 40 # should be int +playbook_version_number: 41 # should be int playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'