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
ansible_role_restic_archiver/templates/restic_forget_snapshots.j2

54 lines
1.8 KiB
Django/Jinja

#!/usr/bin/env bash
# {{ ansible_managed }}
# This file is to cleanup your backup archive and move some snapshots to a external storage.
pid="/var/run/restic_archiver.pid"
trap "rm -f $pid" SIGSEGV
trap "rm -f $pid" SIGINT
if [ -e $pid ]; then
{% if restic_archiver__mail_on_error | bool %}
mail -s "[ERROR] running restic backup" {{ restic_archiver__mailaddress }} <<< 'Another instance of our huge backup script is already running. We canceled running it twice at {{ ansible_hostname }}'
{% endif %}
echo "Another version of this script is already running. CANCELING"
exit # pid file exists, another instance is running, so now we politely exit
else
echo $$ > $pid # pid file doesn't exit, create one and go on
fi
{% if restic_archiver__cache_config | bool %}
{% include 'includes/restic_cache.sh.j2' %}
{% endif %}
{% if restic_archiver__mail_on_error | bool %}
{% include 'includes/set_send_mail_on_error_variable.sh.j2' %}
{% endif %}
{% if restic_archiver__mail_report | default(false) %}
{% include 'includes/mail_report_header.sh.j2' %}
{% endif %}
{% for repo in restic_archiver__repos %}
{% include 'includes/repo_todos.sh.j2' %}
{% endfor %}
sync
{% if restic_archiver__mail_report | default(false) %}
{% include 'includes/mail_report_trailer.sh.j2' %}
{% endif %}
{% if restic_archiver__mail_on_error | bool %}
if [ "$restic_archiver__send_mail_on_error" == true ]; then
mail -s "[ERROR] restic backup report" {{ restic_archiver__mailaddress }} <<< 'Something went wrong while running restic backup archiver at {{ ansible_hostname }}'
fi
{% endif %}
{% if restic_archiver__umount_after_usage %}
umount {{ restic_archiver__mount_disk }}
{% endif %}
rm -f $pid # remove pid file just before exiting
echo "restic archiver done"
exit