17 lines
877 B
Bash
17 lines
877 B
Bash
#!/bin/sh -e
|
|
|
|
INSTANCE="$(echo ${INSTANCE:-${TAG}} | envsubst)"
|
|
export RESTIC_REPOSITORY="$(echo ${RESTIC_REPOSITORY} | envsubst)"
|
|
|
|
restic cat config >/dev/null || restic init
|
|
restic backup --verbose --tag ${TAG} ${BACKUP_PATH}
|
|
restic forget --prune --tag ${TAG} -g paths,tags --keep-hourly 12 --keep-daily 7 --keep-monthly 3
|
|
|
|
# Metrics
|
|
restic stats --json latest > /tmp/stats.json
|
|
restic snapshots --json latest > /tmp/snapshots.json
|
|
|
|
cat /tmp/stats.json | jq -r '"restic_stats_total_size_bytes \(.total_size)\nrestic_stats_total_file_count \(.total_file_count)"' > /tmp/output
|
|
cat /tmp/snapshots.json | jq -r 'max_by(.time) | .time | sub(".[0-9]+Z$"; "Z") | fromdate | "restic_stats_last_snapshot_timestamp \(.)"' >> /tmp/output
|
|
cat /tmp/output | curl --data-binary @- "http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job/backup/instance/${INSTANCE}"
|