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"
2024-09-16 05:34:32 +02:00
payload = " {\"message\": \" $BACKUP_NAME Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: $BACKUP_NAME Backup Started\"} "
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 "
2024-06-05 05:46:44 +02:00
driveb = ` lsblk -o NAME,SERIAL | grep -v luks | grep 9RGHYP8C | awk { 'print $1' } `
drivea = ` lsblk -o NAME,SERIAL | grep -v luks | grep 9RGXW93C | awk { 'print $1' } `
drivec = ` lsblk -o NAME,SERIAL | grep -v luks | grep 5QH05G3F | awk { 'print $1' } `
2024-04-13 04:05:54 +02:00
2024-06-05 05:46:44 +02:00
mountb = ` mount -l | grep $driveb ` ; mountedb = ` echo $? `
mounta = ` mount -l | grep $drivea ` ; mounteda = ` echo $? `
mount3 = ` mount -l | grep $drivec ` ; mountedc = ` echo $? `
2024-04-13 04:05:54 +02:00
echo "Drive status"
2024-06-05 05:46:44 +02:00
echo " Drive 2: $drivea / $mounta / $mounteda "
echo " Drive 1: $driveb / $mountb / $mountedb "
echo " Drive 3: $drivec / $mount3 / $mountedc "
2024-04-13 04:05:54 +02:00
# If any drive isn't found, exit:
2024-06-05 05:46:44 +02:00
if [ [ $mounteda != 0 ] ] || [ [ $mountedb != 0 ] ] || [ [ $mountedc != 0 ] ] ; then
2024-04-13 04:05:54 +02:00
echo "One or more drives is not mounted. Exiting"
2024-09-16 05:34:32 +02:00
payload = " {\"message\": \" $BACKUP_NAME Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-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
# 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)
2024-05-21 10:28:39 +02:00
if [ [ $count -ge 4 ] ] ; then
2024-04-13 04:05:54 +02:00
echo -e " $BACKUP_NAME rsync still running. Exiting.... "
2024-05-14 04:20:59 +02:00
echo "Output: "
ps aux | grep $BACKUP_NAME | grep -v grep
ps aux | grep $BACKUP_NAME | grep -v grep | wc -l
2024-09-16 05:34:32 +02:00
payload = " {\"message\": \" $BACKUP_NAME stopped. $BACKUP_NAME is still running.\n $count \n.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-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
2024-11-20 23:57:32 +01:00
check = $( ssh root@nuc-server df -h | grep \/ volume1\/ Storage | wc -l)
2024-04-13 04:05:54 +02:00
if [ [ $check != 1 ] ] ; then
2024-11-20 23:57:32 +01:00
echo " Synology is not mounted on nuc-server: check returned $check "
2024-09-16 05:34:32 +02:00
payload = " {\"message\": \"Backup stopped. Synology isn't mounted\nDate: `date`\", \"priority\": 2,\"title\": \"backups-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`"
2024-06-05 05:46:44 +02:00
echo -e " rsync -avr --delete --exclude=luks.img /Storage/Backups/Manual/Computers/ /mnt/ $drivea /Backups/Manual/Computers/ "
2024-11-20 23:57:32 +01:00
rsync -avr --delete --exclude= luks.img root@nuc-server:/Storage/Backups/Manual/Computers/ /mnt/$drivea /Backups/Manual/Computers/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Backups/Backblaze/ /mnt/ $drivea /Backups/Backblaze/ "
rsync -avr --delete root@nuc-server:/Storage/Backups/Backblaze/ /mnt/$drivea /Backups/Backblaze/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Backups/Logs/ /mnt/ $drivea /Backups/Logs/ "
rsync -avr --delete root@nuc-server:/Storage/Backups/Logs/ /mnt/$drivea /Backups/Logs/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Backups/Docker/ /mnt/ $drivea /Backups/Docker/ "
rsync -avr --delete root@nuc-server:/Storage/Backups/Docker/ /mnt/$drivea /Backups/Docker/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/Pictures/ /mnt/ $driveb /Pictures/ "
rsync -avr --delete root@nuc-server:/Storage/Media/Pictures/ /mnt/$driveb /Pictures/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/Books/ /mnt/ $driveb /Books/ "
rsync -avr --delete root@nuc-server:/Storage/Media/Books/ /mnt/$driveb /Books/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/Music/ /mnt/ $drivea /Music/ "
rsync -avr --delete root@nuc-server:/Storage/Media/Music/ /mnt/$drivea /Music/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/Movies/ /mnt/ $driveb /Movies/ "
rsync -avr --delete root@nuc-server:/Storage/Media/Movies/ /mnt/$driveb /Movies/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[0-9]* /mnt/ $driveb /TV_Shows/ "
rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[ 0-9] * /mnt/$driveb /TV_Shows/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[A-K]* /mnt/ $driveb /TV_Shows/ "
rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[ A-E] * /mnt/$driveb /TV_Shows/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[L-R]* /mnt/ $drivea /TV_Shows/ "
rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[ F-R] * /mnt/$drivea /TV_Shows/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[S-Z]* /mnt/ $drivec /TV_Shows/ "
rsync -avr --delete root@nuc-server:/Storage/Media/TV_Shows/[ S-Z] * /mnt/$drivec /TV_Shows/
2024-04-13 04:05:54 +02:00
echo -e "======= Time: `date`"
2024-11-20 23:57:32 +01:00
echo -e " rsync -avr --delete root@nuc-server:/Storage/Media/YouTube /mnt/ $drivec /YouTube/ "
rsync -avr --delete root@nuc-server:/Storage/Media/YouTube/ /mnt/$drivec /YouTube/
2024-04-13 04:05:54 +02:00
echo -e "======= Time complete: `date`"
echo "Sending completion message"
2024-09-16 05:34:32 +02:00
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\": \"backups-rpi4: $BACKUP_NAME Backup Complete\"} "
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 "