Add backup.sh
This commit is contained in:
16
backup.sh
Normal file
16
backup.sh
Normal 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}"
|
||||
Reference in New Issue
Block a user