2023-11-27 10:51:07 +11:00
|
|
|
#!/bin/bash
|
|
|
|
# Feed backup status info to a telegram bot
|
|
|
|
|
|
|
|
ONLYFAILED=0 # 0=send full report. 1=report only on failed backups
|
|
|
|
BARE=/root/scripts/bare/bare.sh
|
|
|
|
SENDER=/root/scripts/telegram-send/telegram-send.sh
|
|
|
|
|
2024-07-04 12:10:22 +10:00
|
|
|
function usage() {
|
|
|
|
echo "usage: $0 [OPTIONS]"
|
|
|
|
echo "Feeds backup status to telegram. "
|
|
|
|
echo
|
|
|
|
echo "OPTIONS"
|
|
|
|
echo " -f Only report on failed backups."
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
ARGS="hf"
|
|
|
|
|
|
|
|
while getopts "$ARGS" i; do
|
|
|
|
case "$i" in
|
|
|
|
f)
|
|
|
|
ONLYFAILED=1
|
|
|
|
;;
|
|
|
|
h)
|
|
|
|
usage;
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "ERROR: invalid argument: $i";
|
|
|
|
usage;
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
|
|
|
|
pids=$(pgrep -f bare.sh)
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
$SENDER "gridbug backup check failed - bare.sh process still running. PIDs: $pids"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-11-27 10:51:07 +11:00
|
|
|
|
|
|
|
text=$($BARE -T -a check)
|
|
|
|
[[ $ONLYFAILED -eq 1 ]] && text=$(egrep -v '^.*OK.*:' <<<"$text")
|
|
|
|
if [[ -n $text ]]; then
|
|
|
|
$SENDER "$text"
|
|
|
|
fi
|