#!/usr/bin/env bash set -e set -a . "{{ service_path }}/service.env" set +a duration_start=$(date +%s) _duration_get () { duration_end=$(date +%s) duration=$((duration_end - duration_start)) } hc_url="https://hc-ping.com/$HC_UID" uptime_kuma_url="https://status.serguzim.me/api/push/$UPTIME_KUMA_TOKEN" _hc_ping () { curl -fsSL --retry 3 "$hc_url$1" >/dev/null } _uptime_kuma_ping () { duration=_duration_get curl -fsSL --retry 3 \ --url-query "status=$1" \ --url-query "msg=$2" \ --url-query "ping=${duration}000" \ "$uptime_kuma_url" >/dev/null } _fail () { _hc_ping "/fail" _uptime_kuma_ping "down" "$1" exit 1 } _success () { _hc_ping _uptime_kuma_ping "up" "backup successful" } _hc_ping "/start" BACKUP_LOCATION="$(mktemp -d)" export BACKUP_LOCATION cd "$BACKUP_LOCATION" || exit shopt -s nullglob for file in "{{ service_path }}/backup.d/"* do echo "" echo "running $file" time "$file" || _fail "fail while running $file" done || true cd "{{ service_path }}" docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _fail "fail during restic backup" _success rm -rf "$BACKUP_LOCATION" echo "forgetting old backups for $(hostname)" docker compose run --rm app forget --host "$(hostname)" --prune \ --keep-daily 14 \ --keep-weekly 28 \ --keep-monthly 12 \ --keep-yearly 2