Last active
December 9, 2022 20:14
-
-
Save veerendra2/462264542e3de75b4ffbed7bba8a41b3 to your computer and use it in GitHub Desktop.
A script to run restic backup in cronjob and writes metrics to file for node exporter's textfile collector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Veerendra K | |
# Description: Runs restic backup and writes metrics to file for node exporter's textfile collector | |
# Dependencies: restic, jq | |
# | |
# ** INFO *** | |
# https://www.robustperception.io/using-the-textfile-collector-from-a-shell-script/ | |
# https://github.com/prometheus/node_exporter | |
# Set --collector.textfile.directory in node_exporter | |
RESTIC_REPO="" | |
RESTIC_BACKUP_DIR="" | |
RESTIC_PASSWORD_FILE="" | |
TEXTFILE_COLLECTOR_DIR="." | |
START="$(date +%s)" | |
restic -r $RESTIC_REPO \ | |
--json \ | |
-p $RESTIC_PASSWORD_FILE \ | |
backup $RESTIC_BACKUP_DIR | tail -1 > /tmp/restic_stats.json | |
END="$(date +%s)" | |
cat << EOF > "$TEXTFILE_COLLECTOR_DIR/backup_restic.prom.$$" | |
backup_duration_seconds $(($END - $START)) | |
backup_last_run_epoch_seconds $END | |
backup_restic_summary_files_new `jq .files_new /tmp/restic_stats.json` | |
backup_restic_summary_files_changed `jq .files_changed /tmp/restic_stats.json` | |
backup_restic_summary_files_unmodified `jq .files_unmodified /tmp/restic_stats.json` | |
backup_restic_summary_dirs_new `jq .dirs_new /tmp/restic_stats.json` | |
backup_restic_summary_dirs_changed `jq .dirs_changed /tmp/restic_stats.json` | |
backup_restic_summary_dirs_unmodified `jq .dirs_unmodified /tmp/restic_stats.json` | |
backup_restic_summary_data_blobs `jq .data_blobs /tmp/restic_stats.json` | |
backup_restic_summary_tree_blobs `jq .tree_blobs /tmp/restic_stats.json` | |
backup_restic_summary_data_added `jq .data_added /tmp/restic_stats.json` | |
backup_restic_summary_total_files_processed `jq .total_files_processed /tmp/restic_stats.json` | |
backup_restic_summary_total_bytes_processed `jq .total_bytes_processed /tmp/restic_stats.json` | |
backup_restic_summary_total_duration `jq .total_duration /tmp/restic_stats.json` | |
backup_restic_summary_snapshot_id `jq .snapshot_id /tmp/restic_stats.json` | |
EOF | |
mv "$TEXTFILE_COLLECTOR_DIR/backup_restic.prom.$$" "$TEXTFILE_COLLECTOR_DIR/backup_restic.prom" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Metrics