diff --git a/defaults/main.yml b/defaults/main.yml index 4cb447d..99357fa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -49,5 +49,8 @@ restic_archiver__package: restic_archiver__log_output: true restic_archiver__logrotate: true +restic_archiver__mailsummary: false +restic_archiver__mailaddress: false + # version check for this playbook (true is recomended) submodules_versioncheck: false diff --git a/tasks/cron.yml b/tasks/cron.yml index b036558..4fea18e 100644 --- a/tasks/cron.yml +++ b/tasks/cron.yml @@ -26,3 +26,4 @@ minute: "{{ restic_archiver__minute }}" user: "{{ restic_archiver__owner }}" when: not restic_archiver__log_output + diff --git a/tasks/mail.yml b/tasks/mail.yml new file mode 100644 index 0000000..6565854 --- /dev/null +++ b/tasks/mail.yml @@ -0,0 +1,10 @@ +--- +- name: deploy restic template + template: + src: templates/restic_mailsummary.j2 + dest: /opt/restic-mailsummary.sh + group: "{{ restic_archiver__owner }}" + owner: "{{ restic_archiver__group }}" + mode: 0700 + become: true + diff --git a/tasks/main.yml b/tasks/main.yml index a22e761..9f479d4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,3 +15,6 @@ when: restic_archiver__log_output | bool - include_tasks: cron.yml + +- include_tasks: mail.yml + when: restic_archiver__mailsummary | bool diff --git a/templates/restic_mailsummary.j2 b/templates/restic_mailsummary.j2 new file mode 100644 index 0000000..9aecc80 --- /dev/null +++ b/templates/restic_mailsummary.j2 @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# {{ ansible_managed }} +# This file is to cleanup your backup archive and move some snapshots to a external storage. +echo "Summary for Restic Backup" + +{% for repo in restic_archiver__repos %} + +# Settings for Server {{ repo['name'] | string }} +export RESTIC_REPOSITORY="{{ repo['location'] }}" +export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' +BACKUP_NAME="{{ repo.name }}" +echo "BACKUP: {{ repo.name }}" +restic check +restic stats + +{% if repo.archive|default(false) %} + +{% 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 %} + +# ARCHIVE Settings for Server "{{ repo['name'] | string }}" +echo "EXTERNAL_BACKUP: {{ repo.name }}" +export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" +export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' +BACKUP_NAME="{{ repo.name }}_archive" + +restic check +restic stats +{% endif %} + +{% endfor %} +sync +set +euxo pipefail +df -h +{% if restic_archiver__umount_after_usage %} +umount {{ restic_archiver__mount_disk }} +{% endif %} diff --git a/vars/main.yml b/vars/main.yml index 3f71bac..c359517 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,3 +1,3 @@ --- -playbook_version_number: 29 # should be over ninethousand +playbook_version_number: 30 # should be over ninethousand playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'