initial commit of bin scripts into git

This commit is contained in:
2023-11-08 13:38:19 +11:00
commit 3735eea3c6
113 changed files with 11631 additions and 0 deletions

47
restic-success Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
AN_HOUR=3600
A_DAY=86400
log="/var/tmp/restic-check.log"
function CheckTag()
{
which="$1"
too_long="$2"
snapshot_data=`sudo -u restic RESTIC_PASSWORD=backups-are-important ~restic/bin/restic -r /backup/restic-repo snapshots --tag $which`
last_bkup_dt=`echo "$snapshot_data" | tail -n3 | head -n1 | awk ' { print $2,$3 } '`
last_bkup=`/usr/bin/date +%s --date="$last_bkup_dt"`
now=`date +%s`
how_long=`expr $now - $last_bkup`
echo "for tag: $which -> time now=$now, last_bkup=$last_bkup ($last_bkup_dt): how_long=$how_long (is this <= $too_long?)" >> $log
if [ $how_long -gt $too_long ]; then
echo "seems last backup ($last_bkup) was more than an hour ago? now=$now, how_long = $how_long" >> $log
exit 1
fi
num_snaps=`echo "$snapshot_data" | tail -n1 | cut -f1 -d' '`
if [ "$too_long" == "$AN_HOUR" ]; then
if [ $num_snaps -lt 24 ]; then
echo "Not enough backups for at least 24 hourly backups for tag: $which" >> $log
exit 1
fi
elif [ "$too_long" == "$A_DAY" ]; then
if [ $num_snaps -lt 7 ]; then
echo "Not enough backups for at least 7 daily backups for tag: $which" >> $log
exit 1
fi
fi
}
echo "`date`: Checking last backup time" > $log
for which in docker etc home storage myth; do
CheckTag "$which" "$AN_HOUR"
done
CheckTag "myth_tv" "$A_DAY"
echo "about to force check of metadata and random .1% of actual backups" >> $log
sudo -u restic RESTIC_PASSWORD=backups-are-important ~restic/bin/restic -r /backup/restic-repo check --read-data-subset='0.01%' >> $log
exit $?