Add backup.sh

This commit is contained in:
2023-04-06 14:05:02 +02:00
parent 3f8741e0c5
commit e9340219bc
3 changed files with 70 additions and 0 deletions

16
backup.sh Normal file
View File

@@ -0,0 +1,16 @@
#!/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}"