60 lines
3.4 KiB
Bash
60 lines
3.4 KiB
Bash
BACKUP_NAME="rsync-data-vol"
|
|
GOTIFY_TOKEN=`cat /var/run/secrets/gotify_token | head -n 1`
|
|
|
|
echo "Sending start message"
|
|
payload="{\"message\": \"$BACKUP_NAME Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"japan-rpi4: $BACKUP_NAME 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"
|
|
|
|
drivea=`lsblk -o NAME,SERIAL | grep -v luks | grep 9RGXW93C | awk {'print $1'}`
|
|
driveb=`lsblk -o NAME,SERIAL | grep -v luks | grep 9RGHYP8C | awk {'print $1'}`
|
|
drivec=`lsblk -o NAME,SERIAL | grep -v luks | grep 5QH05G3F | awk {'print $1'}`
|
|
|
|
mounta=`mount -l | grep $drivea`; mounteda=`echo $?`
|
|
mountb=`mount -l | grep $driveb`; mountedb=`echo $?`
|
|
mountc=`mount -l | grep $drivec`; mountedc=`echo $?`
|
|
|
|
echo "Drive status"
|
|
echo "Drive 2: $drivea / $mounta / $mounteda"
|
|
echo "Drive 1: $driveb / $mountb / $mountedb"
|
|
echo "Drive 3: $drivec / $mountc / $mountedc"
|
|
|
|
# If any drive isn't found, exit:
|
|
if [[ $mounteda != 0 ]] || [[ $mountedb != 0 ]] || [[ $mountedc != 0 ]] ; then
|
|
echo "One or more drives is not mounted. Exiting"
|
|
payload="{\"message\": \"$BACKUP_NAME Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"japan-rpi4: $BACKUP_NAME 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"
|
|
exit
|
|
fi
|
|
|
|
# If an old backup is still running, don't continue
|
|
count=$(ps aux | grep $BACKUP_NAME | grep -v grep | wc -l)
|
|
if [[ $count -ge 4 ]] ; then
|
|
echo -e "$BACKUP_NAME rsync still running. Exiting...."
|
|
|
|
echo "Output: "
|
|
ps aux | grep $BACKUP_NAME | grep -v grep
|
|
ps aux | grep $BACKUP_NAME | grep -v grep | wc -l
|
|
|
|
payload="{\"message\": \"$BACKUP_NAME stopped. $BACKUP_NAME is still running.\nDate: `date`\", \"priority\": 2,\"title\": \"japan-rpi4: $BACKUP_NAME 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"
|
|
exit
|
|
fi
|
|
|
|
# Check if the Synology is mounted
|
|
check=$(ssh root@nuc-docker01 df -h | grep synology.servers.hs.net | wc -l)
|
|
if [[ $check != 1 ]] ; then
|
|
echo "Synology is not mounted on nuc-docker01: check returned $check"
|
|
payload="{\"message\": \"Backup stopped. Synology isn't mounted\nDate: `date`\", \"priority\": 2,\"title\": \"japan-rpi4: $BACKUP_NAME 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"
|
|
exit
|
|
fi
|
|
|
|
echo -e "======= Time started : `date`"
|
|
echo -e "rsync -avr --delete --exclude=Downloads/ --exclude='Docker/sysctl.io' root@nuc-docker01:/Storage/Data/ /mnt/$drivea/Data/"
|
|
rsync -avr --delete --exclude=Downloads/ --exclude='Docker/sysctl.io' root@nuc-docker01:/Storage/Data/ /mnt/$drivea/Data/
|
|
|
|
echo -e "======= Time complete: `date`"
|
|
echo "Sending completion message"
|
|
payload="{\"message\": \"Data Vol Backup completed\nDate: `date`\n`df -h | grep sda`\n`df -h | grep sdb`\n`df -h | grep sdc`\", \"priority\": 2,\"title\": \"backups-rpi4: Data Vol 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"
|
|
|