feat(restic): migrate to systemd template units

This commit is contained in:
2025-03-09 13:07:03 +01:00
parent ed95d4fd3d
commit 0aba4024de
14 changed files with 231 additions and 147 deletions

View File

@ -8,15 +8,19 @@ fi
echo "List existing snapshots or initialize repository"
restic snapshots || restic init
sleep 2;
sleep 1;
echo "Attempting to remove lock if present"
restic unlock
sleep 2
sleep 1;
echo "Start backup on ${@:1}"
restic --verbose --retry-lock=${RESTIC_RETRY_LOCK:-5m} backup "${@:1}"
sleep 2
sleep 1;
if [[ -n ${RESTIC_POIST_BACKUP_HOOK-} ]]; then
/bin/bash -c "$RESTIC_POST_BACKUP_HOOK"
fi
echo "Forget and prune old snapshots"
restic forget --prune --retry-lock=${RESTIC_RETRY_LOCK:-5m} \
@ -29,9 +33,11 @@ restic forget --prune --retry-lock=${RESTIC_RETRY_LOCK:-5m} \
sleep 2
echo "Generate snapshot metrics"
restic --json snapshots | /opt/restic-generate-snapshot-metrics.sh \
> /var/lib/node_exporter/restic-snapshots-${RESTIC_JOBNAME:-unknown}.prom-src
sleep 2
if [[ -n ${RESTIC_GENERATE_SNAPSHOT_METRICS_COMMAND-} ]]; then
restic --json snapshots | ${RESTIC_GENERATE_SNAPSHOT_METRICS_COMMAND} \
> /var/lib/node_exporter/restic-snapshots-${RESTIC_JOBNAME:-unknown}.prom-src
sleep 2;
fi
echo "Check repository"
restic check

View File

@ -6,7 +6,7 @@ echo $RESTIC_JSON | jq -r '.[]
| {
"hostname": .hostname,
"username": .username,
"short_id": .short_id,
"short_id": .short_id,
"time": ((((.time | split(".")[0]) + "Z") | fromdate) - (3600 * (.time | split("+")[1] | split(":")[0] | tonumber + 1))),
"paths": .paths[]
} | "restic_snapshots{hostname=\"\(.hostname)\",username=\"\(.username)\",short_id=\"\(.short_id)\",paths=\"\(.paths)\"} \(.time)"'