2024-04-13 04:05:54 +02:00
BACKUP_NAME = "rsync-media"
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 "
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 "Drive status"
echo " Drive 1: $drive1 / $mount1 / $mounted1 "
echo " Drive 2: $drive2 / $mount2 / $mounted2 "
echo " Drive 3: $drive3 / $mount3 / $mounted3 "
# If any drive isn't found, exit:
if [ [ $mounted1 != 0 ] ] || [ [ $mounted2 != 0 ] ] || [ [ $mounted3 != 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
2024-05-08 01:02:08 +02:00
count = $( ps aux | grep $BACKUP_NAME | grep -v grep | wc -l)
if [ [ $count -ge 1 ] ] ; then
2024-04-13 04:05:54 +02:00
echo -e " $BACKUP_NAME rsync still running. Exiting.... "
2024-04-15 05:33:35 +02:00
payload = " {\"message\": \" $BACKUP_NAME stopped. $BACKUP_NAME is still running.\nDate: `date`\", \"priority\": 2,\"title\": \"japan-rpi4: $BACKUP_NAME Backup Stopped\"} "
2024-04-13 04:05:54 +02:00
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 192.168.1.100 | wc -l)
if [ [ $check != 1 ] ] ; then
echo " Synology is not mounted on nuc-docker01: check returned $check "
2024-04-13 16:33:14 +02:00
payload = " {\"message\": \"Backup stopped. Synology isn't mounted\nDate: `date`\", \"priority\": 2,\"title\": \"japan-rpi4: $BACKUP_NAME Backup Stopped\"} "
2024-04-13 04:05:54 +02:00
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=luks.img /Storage/Backups/Manual/Computers/ /mnt/ $drive1 /Backups/Manual/Computers/ "
rsync -avr --delete --exclude= luks.img root@nuc-docker01:/Storage/Backups/Manual/Computers/ /mnt/$drive1 /Backups/Manual/Computers/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Backups/Backblaze/ /mnt/ $drive1 /Backups/Backblaze/ "
rsync -avr --delete root@nuc-docker01:/Storage/Backups/Backblaze/ /mnt/$drive1 /Backups/Backblaze/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Backups/Logs/ /mnt/ $drive1 /Backups/Logs/ "
rsync -avr --delete root@nuc-docker01:/Storage/Backups/Logs/ /mnt/$drive1 /Backups/Logs/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Backups/Docker/ /mnt/ $drive1 /Backups/Docker/ "
rsync -avr --delete root@nuc-docker01:/Storage/Backups/Docker/ /mnt/$drive1 /Backups/Docker/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/Pictures/ /mnt/ $drive1 /Pictures/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/Pictures/ /mnt/$drive1 /Pictures/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/Books/ /mnt/ $drive1 /Books/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/Books/ /mnt/$drive1 /Books/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/Music/ /mnt/ $drive1 /Music/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/Music/ /mnt/$drive1 /Music/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete --exclude=Downloads/ /Storage/Data/ /mnt/ $drive1 /Data/ "
rsync -avr --delete --exclude= Downloads/ --exclude= Docker/sysctl* root@nuc-docker01:/Storage/Data/ /mnt/$drive1 /Data/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/Movies/ /mnt/ $drive2 /Movies/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/Movies/ /mnt/$drive2 /Movies/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[0-9]* /mnt/ $drive1 /TV_Shows/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[ 0-9] * /mnt/$drive1 /TV_Shows/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[A-K]* /mnt/ $drive1 /TV_Shows/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[ A-E] * /mnt/$drive1 /TV_Shows/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[L-R]* /mnt/ $drive2 /TV_Shows/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[ F-R] * /mnt/$drive2 /TV_Shows/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[S-Z]* /mnt/ $drive3 /TV_Shows/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/TV_Shows/[ S-Z] * /mnt/$drive3 /TV_Shows/
echo -e "======= Time: `date`"
echo -e " rsync -avr --delete root@nuc-docker01:/Storage/Media/YouTube /mnt/ $drive3 /YouTube/ "
rsync -avr --delete root@nuc-docker01:/Storage/Media/YouTube/ /mnt/$drive3 /YouTube/
echo -e "======= Time complete: `date`"
echo "Sending completion message"
payload = " {\"message\": \" $BACKUP_NAME Backup completed\nDate: `date`\n`df -h | grep sda`\n`df -h | grep sdb`\n`df -h | grep sdc`\", \"priority\": 2,\"title\": \"japan-rpi4: $BACKUP_NAME 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 "