From 48c88347a9b7182295be1c56f819679d3058196b Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 8 May 2021 16:12:05 +0100 Subject: [PATCH] Add some healthchecks integration to backup --- ansible/host_vars/restic.yml | 8 ++++++++ ansible/roles/restic/tasks/files/backrest.sh | 3 +++ ansible/roles/restic/vars/main.yml | 1 + 3 files changed, 12 insertions(+) diff --git a/ansible/host_vars/restic.yml b/ansible/host_vars/restic.yml index 8df576d..76ef5db 100644 --- a/ansible/host_vars/restic.yml +++ b/ansible/host_vars/restic.yml @@ -1,2 +1,10 @@ restic_backup_locations: - /mnt/tank +healthchecks_id: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 61343535336633643231356138356631663130313234343538366634393661666232303965643365 + 3735323363366366303366336163623334316638653164610a633735316466336637346666666536 + 64323361653034303033383333333037346637343865636634386533653337363936386130396265 + 3134623162393034370a383737386434653036373639636631363233623232383936313264656539 + 62376636326332386330663432306135313938623134383239373435666666356538363639323333 + 3264386632376261666566373032363261643961376635336131 diff --git a/ansible/roles/restic/tasks/files/backrest.sh b/ansible/roles/restic/tasks/files/backrest.sh index 74e0f0a..176579b 100644 --- a/ansible/roles/restic/tasks/files/backrest.sh +++ b/ansible/roles/restic/tasks/files/backrest.sh @@ -14,8 +14,11 @@ mkdir -p "$RESTIC_LOG_DIR" # Run backup, and capture logs to file cron_backup() { + curl -fsS -m 10 --retry 5 -o /dev/null {{ healthchecks_host }}/{{ healthchecks_id }}/start restic --verbose backup {{ restic_backup_locations|join(' ') }} | tee -a $RESTIC_LOG_FILE exit_code=${PIPESTATUS[0]} + curl -fsS -m 10 --retry 5 -o /dev/null {{ healthchecks_host }}/{{ healthchecks_id }}/$exit_code --data-binary "@$RESTIC_LOG_FILE" + rm $RESTIC_LOG_FILE echo "Exit code: $exit_code" } diff --git a/ansible/roles/restic/vars/main.yml b/ansible/roles/restic/vars/main.yml index 0f4b882..28cc7e0 100644 --- a/ansible/roles/restic/vars/main.yml +++ b/ansible/roles/restic/vars/main.yml @@ -24,3 +24,4 @@ restic_key: !vault | 61303164333662353732656265386430383566343462633435626334373331316663363563616662 66643135336539333738623231346331623464636637373639666435663961383936 restic_b2_bucket: 0rng-restic +healthchecks_host: https://hc-ping.com