nix/nixos/hosts/backups-rpi4/scripts/sysctl.sh

56 lines
2.6 KiB
Bash
Raw Normal View History

2024-04-04 05:47:30 +02:00
# Send the gotify notification:
GOTIFY_TOKEN=`cat /var/run/secrets/gotify_token | head -n 1`
payload="{\"message\": \"sysctl.io Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: sysctl.io Backup Started\"}"
curl -X "POST" "https://gotify.sysctl.io/message" -H "accept: application/json" -H "Content-Type: application/json" -H "X-Gotify-Key: $GOTIFY_TOKEN" -d "$payload"
drive1=`lsblk -o NAME,SERIAL | grep -v luks | grep 9RGHYP8C | awk {'print $1'}`
drive2=`lsblk -o NAME,SERIAL | grep -v luks | grep 9RGXW93C | awk {'print $1'}`
drive3=`lsblk -o NAME,SERIAL | grep -v luks | grep 5QH05G3F | awk {'print $1'}`
mount1=`mount -l | grep $drive1`
mounted1=`echo $?`
mount2=`mount -l | grep $drive2`
mounted2=`echo $?`
mount3=`mount -l | grep $drive3`
mounted3=`echo $?`
echo "status"
echo "$drive1 / $mount1 / $mounted1"
echo "$drive2 / $mount2 / $mounted2"
echo "$drive3 / $mount3 / $mounted3"
# If any drive isn't found, exit:
if [[ $mounted1 != 0 ]] || [[ mounted2 != 0 ]] || [[ $mounted3 != 0 ]] ; then
payload="{\"message\": \"sysctl.io Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: sysctl.io Backup Stopped\"}"
curl -X "POST" "https://gotify.sysctl.io/message" -H "accept: application/json" -H "Content-Type: application/json" -H "X-Gotify-Key: $GOTIFY_TOKEN" -d "$payload"
fi
echo "Drive 1: $drive1"
echo "Drive 2: $drive2"
echo "Drive 3: $drive3"
echo -e "======= Time started : `date`"
if [[ `ps aux | grep rsync | grep -v grep | grep -v rsync-sysctl` ]] ; then
echo -e "================================================================================"
echo -e "rsync still running. Exiting...."
echo -e "======= Time complete: `date`"
exit
fi
echo -e "================================================================================"
echo -e "======= Time: `date`"
echo -e "rsync -avr --delete --exclude=Downloads/ root@framework-server:/Storage/Data/Docker/sysctl.io/ /mnt/$drive1/Data/Docker/sysctl.io/"
rsync -avr --delete --exclude=Downloads/ root@framework-server:/Storage/Data/Docker/sysctl.io/ /mnt/$drive1/Data/Docker/sysctl.io/
echo -e "======= Time: `date`"
echo -e "======= Time complete: `date`"
echo "Sending completion message"
payload="{\"message\": \"sysctl.io Backup completed\nDate: `date`\n`df -h | grep sda`\n`df -h | grep sdb`\n`df -h | grep sdc`\", \"priority\": 2,\"title\": \"backups-rpi4: sysctl.io Backup Complete\"}"
curl -X "POST" "https://gotify.sysctl.io/message" -H "accept: application/json" -H "Content-Type: application/json" -H "X-Gotify-Key: $GOTIFY_TOKEN" -d "$payload"