1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic.git synced 2024-12-11 23:41:32 +01:00

fix: lvm: Handle cleanup after unreadable files

Before this commit, since restic backup exits with status 3 if it
cannot read one or more files, the LVM snapshot wasn't being cleaned
up.

Now, specially handle the 3 exit status; also, unequivocally perform
the LVM cleanup when finished.
This commit is contained in:
Martin Kennedy 2023-03-07 16:26:36 -05:00
parent de3d35d4ec
commit 6459eaa161

View file

@ -226,14 +226,18 @@ fi
{{ restic_install_path }}/restic backup {% if item.lvm is defined and item.src == '/' %}/rootfs{% endif %}$BACKUP_SOURCE $MODE_TAG \ {{ restic_install_path }}/restic backup {% if item.lvm is defined and item.src == '/' %}/rootfs{% endif %}$BACKUP_SOURCE $MODE_TAG \
{{ tags(item.tags) }} \ {{ tags(item.tags) }} \
{% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \ {% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \
$@ \ $@
{% if item.lvm is defined %}&& cleanup_vol $BACKUP_SOURCE{% endif %};
} \ } \
{% endif %} {{ backup_output_log }} {% endif %} {{ backup_output_log }}
if [[ $? -eq 0 ]]
then case $? in
0)
echo "$(date -u '+%Y-%m-%d %H:%M:%S') OK" {{ backup_result_log }} echo "$(date -u '+%Y-%m-%d %H:%M:%S') OK" {{ backup_result_log }}
else ;;
3)
echo "$(date -u '+%Y-%m-%d %H:%M:%S') WARNING" {{ backup_result_log }}
;;
*)
echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ backup_result_log }} echo "$(date -u '+%Y-%m-%d %H:%M:%S') ERROR" {{ backup_result_log }}
{% if item.mail_on_error is defined and item.mail_on_error == true %} {% if item.mail_on_error is defined and item.mail_on_error == true %}
mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S'). mail -s "restic backup failed on {{ ansible_hostname }}" {{ item.mail_address }} <<< "Something went wrong while running restic backup script running at {{ ansible_hostname }} at $(date -u '+%Y-%m-%d %H:%M:%S').
@ -241,12 +245,12 @@ else
{{ ' ' }}We tried to backup '{{ item.src }}'. {{ ' ' }}We tried to backup '{{ item.src }}'.
{%- endif -%} {%- endif -%}
{{ ' ' }}Please repair the restic-{{ item.name | replace(' ', '') }} job." {{ ' ' }}Please repair the restic-{{ item.name | replace(' ', '') }} job."
{% endif %}
esac
{% if item.lvm is defined %} {% if item.lvm is defined %}
cleanup_vol $BACKUP_SOURCE cleanup_vol $BACKUP_SOURCE
{% endif %} {% endif %}
{% endif %}
fi
{# {#