#!/bin/bash {{ ansible_managed | comment }} set -eu TEXTFILE_COLLECTOR_DIR=/var/lib/prometheus/node-exporter PROM_FILE=$TEXTFILE_COLLECTOR_DIR/backup.prom TMP_FILE=$PROM_FILE.$$ NOW=$(date +%s) BORG_INFO=$(borgmatic --no-color info --last 1 --json) get_field() { local query="$1" printf '%s' "$BORG_INFO" | jq -r ".[].$query" } borg_last_modified=$(get_field 'repository.last_modified' | xargs -I{} date -d "{}" +"%s") echo $borg_last_modified borg_backup_age=$(echo "$NOW" "$borg_last_modified" | awk '{print(($1 - $2) / (24 * 60 * 60))}') get_status_data() { cat <"$TMP_FILE" mv "$TMP_FILE" "$PROM_FILE"