1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic_archiver.git synced 2024-08-16 10:09:49 +02:00

improve mail reporting

This commit is contained in:
L3D 2021-01-11 19:01:04 +01:00
parent 66d6fee588
commit 70902baeb6
No known key found for this signature in database
GPG key ID: 5215C3441797AB2B
5 changed files with 52 additions and 15 deletions

View file

@ -50,7 +50,7 @@ restic_archiver__log_output: true
restic_archiver__logrotate: true restic_archiver__logrotate: true
restic_archiver__mailsummary: false restic_archiver__mailsummary: false
restic_archiver__mailaddress: false restic_archiver__mailaddress: 'root@localhost'
# restic default options # restic default options
restic_archiver__default_opt: '' restic_archiver__default_opt: ''

View file

@ -27,3 +27,14 @@
user: "{{ restic_archiver__owner }}" user: "{{ restic_archiver__owner }}"
when: not restic_archiver__log_output when: not restic_archiver__log_output
- name: setup cronjob for restic without logging
become: true
cron:
name: "archive restic backup with ansible_role_restic_archiver"
job: /opt/restic-mailsummary.sh
cron_file: /etc/crontab
hour: "7"
minute: "30"
user: "{{ restic_archiver__owner }}"
when: restic_archiver__mailsummary

View file

@ -1,4 +1,12 @@
--- ---
- name: install requirements
become: true
package:
name:
- jq
- bsd-mailx
state: present
- name: deploy restic template - name: deploy restic template
template: template:
src: templates/restic_mailsummary.j2 src: templates/restic_mailsummary.j2

View file

@ -1,7 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# {{ ansible_managed }} # {{ ansible_managed }}
# This file is to cleanup your backup archive and move some snapshots to a external storage. # This file is designed to create a overview
echo "Summary for Restic Backup" # overof the restic backup and
# send it by mail - if wanted
echo "SUMMARY for Restic BACKUP" > /tmp/mailcontent
{% for repo in restic_archiver__repos %} {% for repo in restic_archiver__repos %}
@ -9,38 +12,53 @@ echo "Summary for Restic Backup"
export RESTIC_REPOSITORY="{{ repo['location'] }}" 2>/dev/null export RESTIC_REPOSITORY="{{ repo['location'] }}" 2>/dev/null
export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
BACKUP_NAME="{{ repo.name }}" 2>/dev/null BACKUP_NAME="{{ repo.name }}" 2>/dev/null
echo "BACKUP: {{ repo.name }}" {#
restic check 2>/dev/null
restic stats 2>/dev/null STARTING MAIL OUTPUT
#}
cat <<EOT >> /tmp/mailcontent
{{ repo.name }}"
$(restic check --quiet 2>/dev/null)
$(restic --quiet stats --json | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('Repo size: ', str(int(jsondata['total_size'] / 1024 / 1024 / 1024 * 1000 )/1000 ), 'GB with ', str(jsondata['total_file_count']), ' Files.')")
Latest Snapshots:
restic --quiet snapshots --last --json | jq -c '.[]' | while read i; do echo -e "$i" | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print(' Hostname: ', jsondata['hostname'], ' \tbackup time: ', jsondata['time'], ' \tPath: ', str(jsondata['paths'][0]))" ; done
EOT
{% if repo.archive|default(false) %} {% if repo.archive|default(false) %}
{% if restic_archiver__mount_required %} {% if restic_archiver__mount_required %}
set +euxo pipefail 2>/dev/null
if mountpoint -q {{ restic_archiver__mount_disk }} if mountpoint -q {{ restic_archiver__mount_disk }}
then then
echo "{{ restic_archiver__mount_disk }} is mounted" echo "{{ restic_archiver__mount_disk }} is mounted"
else else
mount -a 2>/dev/null mount -a 2>/dev/null
fi fi
set -euxo pipefail 2>/dev/null
{% endif %} {% endif %}
# ARCHIVE Settings for Server "{{ repo['name'] | string }}" # ARCHIVE Settings for Server "{{ repo['name'] | string }}"
echo "EXTERNAL_BACKUP: {{ repo.name }}" echo "EXTERNAL_BACKUP: {{ repo.name }}" 2>/dev/null
export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" 2>/dev/null export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" 2>/dev/null
export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
BACKUP_NAME="{{ repo.name }}_archive" 2>/dev/null BACKUP_NAME="{{ repo.name }}_archive" 2>/dev/null
restic check 2>/dev/null echo " Backup at external Disk:" >> /tmp/mailcontent
restic statps restic check --quiet >> /tmp/mailcontent
restic --quiet stats --json | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print(' External Backup Repo size: ', str(int(jsondata['total_size'] / 1024 / 1024 / 1024 * 1000 )/1000 ), 'GB with ', str(jsondata['total_file_count']), ' Files.')" >> /tmp/mailcontent
{% endif %} {% endif %}
{% endfor %} {% endfor %}
sync sync
set +euxo pipefail echo -e "\n\n\n\n\n\n\n -------------------------------------" >> /tmp/mailcontent
echo "\n\n\n\n" df -h >> /tmp/mailcontent
df -h mail -s "restic backup report" {{ restic_archiver__mailaddress }} < /tmp/mailcontent
{% if restic_archiver__umount_after_usage %} {% if restic_archiver__umount_after_usage %}
umount {{ restic_archiver__mount_disk }} umount {{ restic_archiver__mount_disk }}
{% endif %} {% endif %}

View file

@ -1,3 +1,3 @@
--- ---
playbook_version_number: 33 # should be over ninethousand playbook_version_number: 35 # should be over ninethousand
playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version' playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'