forked from finallycoffee/base
		
	feat(restic): add scripts for directory backup and snapshot metrics generation
This commit is contained in:
		
							
								
								
									
										37
									
								
								roles/restic/files/restic-backup-directories.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								roles/restic/files/restic-backup-directories.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
set -euo pipefail
 | 
			
		||||
 | 
			
		||||
if [[ -n ${RESTIC_PRE_BACKUP_HOOK-} ]]; then
 | 
			
		||||
    /bin/bash -c "$RESTIC_PRE_BACKUP_HOOK"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo "List existing snapshots or initialize repository"
 | 
			
		||||
restic snapshots || restic init
 | 
			
		||||
sleep 2;
 | 
			
		||||
 | 
			
		||||
echo "Attempting to remove lock if present"
 | 
			
		||||
restic unlock
 | 
			
		||||
sleep 2
 | 
			
		||||
 | 
			
		||||
echo "Start backup on ${@:1}"
 | 
			
		||||
restic --verbose --retry-lock=${RESTIC_RETRY_LOCK:-5m} backup "${@:1}"
 | 
			
		||||
sleep 2
 | 
			
		||||
 | 
			
		||||
echo "Forget and prune old snapshots"
 | 
			
		||||
restic forget --prune --retry-lock=${RESTIC_RETRY_LOCK:-5m} \
 | 
			
		||||
    --keep-within=${RESTIC_FORGET_KEEP_WITHIN:-1d} \
 | 
			
		||||
    --keep-hourly=${RESTIC_FORGET_KEEP_HOURLY:-6} \
 | 
			
		||||
    --keep-daily=${RESTIC_FORGET_KEEP_DAILY:-2} \
 | 
			
		||||
    --keep-weekly=${RESTIC_FORGET_KEEP_WEEKLY:-7} \
 | 
			
		||||
    --keep-monthly=${RESTIC_FORGET_KEEP_MONTHLY:-4} \
 | 
			
		||||
    --verbose
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
echo "Check repository"
 | 
			
		||||
restic check
 | 
			
		||||
							
								
								
									
										12
									
								
								roles/restic/files/restic-generate-snapshot-metrics.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								roles/restic/files/restic-generate-snapshot-metrics.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
RESTIC_JSON=$(</dev/stdin)
 | 
			
		||||
 | 
			
		||||
echo $RESTIC_JSON | jq -r '.[]
 | 
			
		||||
    | {
 | 
			
		||||
        "hostname": .hostname,
 | 
			
		||||
        "username": .username,
 | 
			
		||||
	"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)"'
 | 
			
		||||
		Reference in New Issue
	
	Block a user