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.
2021-03-01 11:13:14 +01:00
2022-01-10 14:11:27 +01:00
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
2021-10-04 18:12:38 +02:00
{% if restic_archiver__cache_config | bool %}
2023-10-22 20:33:44 +02:00
{% include 'includes/restic_cache.sh.j2' %}
2021-03-01 11:13:14 +01:00
{% endif %}
2021-04-29 11:20:40 +02:00
{% if restic_archiver__mail_on_error | bool %}
2023-10-22 20:33:44 +02:00
{% include 'includes/set_send_mail_on_error_variable.sh.j2' %}
2021-04-29 11:20:40 +02:00
{% endif %}
2021-02-17 17:21:20 +01:00
{% if restic_archiver__mail_report | default(false) %}
2023-10-22 20:33:44 +02:00
{% include 'includes/mail_report_header.sh.j2' %}
2021-02-17 17:21:20 +01:00
{% endif %}
2020-12-09 17:26:16 +01:00
{% for repo in restic_archiver__repos %}
2023-10-22 20:33:44 +02:00
{% include 'includes/repo_todos.sh.j2' %}
2020-12-09 17:26:16 +01:00
{% endfor %}
2020-12-10 19:44:40 +01:00
2020-12-14 12:02:36 +01:00
sync
2021-02-17 17:21:20 +01:00
2021-04-29 11:20:40 +02:00
{% if restic_archiver__mail_report | default(false) %}
2023-10-22 20:33:44 +02:00
{% include 'includes/mail_report_trailer.sh.j2' %}
2021-04-29 11:20:40 +02:00
{% endif %}
{% if restic_archiver__mail_on_error | bool %}
2021-10-05 13:36:12 +02:00
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
2021-04-29 11:20:40 +02:00
{% endif %}
2021-02-17 17:21:20 +01:00
2020-12-14 12:02:36 +01:00
{% if restic_archiver__umount_after_usage %}
2021-10-05 13:36:12 +02:00
umount {{ restic_archiver__mount_disk }}
2020-12-14 12:39:11 +01:00
{% endif %}
2022-01-10 14:11:27 +01:00
rm -f $pid # remove pid file just before exiting
2021-10-05 13:36:12 +02:00
echo "restic archiver done"
2022-01-10 14:11:27 +01:00
exit