From 887c118cb393736fddc63d1c922b7fbdad42362b Mon Sep 17 00:00:00 2001 From: albert Date: Thu, 4 Apr 2024 12:47:30 +0900 Subject: [PATCH] Update scripts --- nixos/hosts/backups-rpi4/backup-script.nix | 260 +------------------ nixos/hosts/backups-rpi4/scripts/data-vol.sh | 63 +++++ nixos/hosts/backups-rpi4/scripts/media.sh | 128 +++++++++ nixos/hosts/backups-rpi4/scripts/sysctl.sh | 56 ++++ 4 files changed, 251 insertions(+), 256 deletions(-) create mode 100644 nixos/hosts/backups-rpi4/scripts/data-vol.sh create mode 100644 nixos/hosts/backups-rpi4/scripts/media.sh create mode 100644 nixos/hosts/backups-rpi4/scripts/sysctl.sh diff --git a/nixos/hosts/backups-rpi4/backup-script.nix b/nixos/hosts/backups-rpi4/backup-script.nix index 5cc73171..814c3ebd 100644 --- a/nixos/hosts/backups-rpi4/backup-script.nix +++ b/nixos/hosts/backups-rpi4/backup-script.nix @@ -1,261 +1,9 @@ { config, lib, pkgs, ... }: let - rsync-backups = pkgs.writeScriptBin "rsync-backups" '' -#!${pkgs.stdenv.shell} -# Send the gotify notification: - -GOTIFY_TOKEN=`cat /var/run/secrets/gotify_token | head -n 1` -payload="{\"message\": \"Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: 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\": \"Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: 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 "Checking if the NAS is mounted on nuc-docker01:" -check=$(ssh root@nuc-docker01 df -h | grep 192.168.1.100 | wc -l) -if [[ $check != 1 ]] ; then - payload="{\"message\": \"Backup stopped. Synology isn't mounted\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: 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`" - -if [[ `ps aux | grep rsync | grep -v grep | grep -v rsync-backups` ]] ; then - echo -e "================================================================================" - echo -e "rsync still running. Exiting...." - echo -e "======= Time complete: `date`" - exit -fi - -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -# echo -e "======= Time: `date`" -# echo -e "rsync -avr --delete --exclude=Downloads/ /Storage/Data/ /mnt/$drive1/Data/" -# rsync -avr --delete --exclude=Downloads/ root@nuc-docker01:/Storage/Data/ /mnt/$drive1/Data/ - -echo -e "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -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 "================================================================================" -echo -e "======= Time: `date`" -echo -e "======= Time complete: `date`" - -echo "Sending completion message" -payload="{\"message\": \"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 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" - -''; - - rsync-data-vol = pkgs.writeScriptBin "rsync-data-vol" '' -#!${pkgs.stdenv.shell} -# Send the gotify notification: - -GOTIFY_TOKEN=`cat /var/run/secrets/gotify_token | head -n 1` -payload="{\"message\": \"Data Vol Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Data Vol 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\": \"Data Vol Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Data Vol 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 "Drive 1: $drive1" -echo "Drive 2: $drive2" -echo "Drive 3: $drive3" - -echo "Checking if the NAS is mounted on nuc-docker01:" -check=$(ssh root@nuc-docker01 df -h | grep 192.168.1.100 | wc -l) -if [[ $check != 1 ]] ; then - payload="{\"message\": \"Data Vol Backup stopped. Synology isn't mounted\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Data Vol 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`" - -if [[ `ps aux | grep rsync | grep -v grep | grep -v rsync-data-vol` ]] ; 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/ --exclude='Data/Docker/sysctl.io/' root@nuc-docker01:/Storage/Data/ /mnt/$drive1/Data/" -rsync -avr --delete --exclude=Downloads/ --exclude='Data/Docker/sysctl.io/' root@nuc-docker01:/Storage/Data/ /mnt/$drive1/Data/ - -echo -e "======= Time: `date`" -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" - -''; - -rsync-sysctl = pkgs.writeScriptBin "rsync-sysctl" '' -#!${pkgs.stdenv.shell} -# 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` -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" - -''; -in -{ + rsync-backups = pkgs.writeScriptBin "rsync-backups" builtins.readFile ./scripts/media.sh; + rsync-data-vol = pkgs.writeScriptBin "rsync-data-vol" builtins.readFile ./scripts/data-vol.sh; + rsync-sysctl = pkgs.writeScriptBin "rsync-sysctl" builtins.readFile ./scripts/sysctl.sh; +in { environment.systemPackages = [ rsync-backups rsync-data-vol diff --git a/nixos/hosts/backups-rpi4/scripts/data-vol.sh b/nixos/hosts/backups-rpi4/scripts/data-vol.sh new file mode 100644 index 00000000..26fede68 --- /dev/null +++ b/nixos/hosts/backups-rpi4/scripts/data-vol.sh @@ -0,0 +1,63 @@ +#!/bin/env bash +# Send the gotify notification: + +GOTIFY_TOKEN=`cat /var/run/secrets/gotify_token | head -n 1` +payload="{\"message\": \"Data Vol Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Data Vol 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\": \"Data Vol Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Data Vol 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 "Drive 1: $drive1" +echo "Drive 2: $drive2" +echo "Drive 3: $drive3" + +echo "Checking if the NAS is mounted on nuc-docker01:" +check=$(ssh root@nuc-docker01 df -h | grep 192.168.1.100 | wc -l) +if [[ $check != 1 ]] ; then + payload="{\"message\": \"Data Vol Backup stopped. Synology isn't mounted\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: Data Vol 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`" + +if [[ `ps aux | grep rsync | grep -v grep | grep -v rsync-data-vol` ]] ; 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/ --exclude='Data/Docker/sysctl.io/' root@nuc-docker01:/Storage/Data/ /mnt/$drive1/Data/" +rsync -avr --delete --exclude=Downloads/ --exclude='Data/Docker/sysctl.io/' root@nuc-docker01:/Storage/Data/ /mnt/$drive1/Data/ + +echo -e "======= Time: `date`" +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" + diff --git a/nixos/hosts/backups-rpi4/scripts/media.sh b/nixos/hosts/backups-rpi4/scripts/media.sh new file mode 100644 index 00000000..a1a2eff3 --- /dev/null +++ b/nixos/hosts/backups-rpi4/scripts/media.sh @@ -0,0 +1,128 @@ +#! /bin/env bash +# Send the gotify notification: + +GOTIFY_TOKEN=`cat /var/run/secrets/gotify_token | head -n 1` +payload="{\"message\": \"Backup has started\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: 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\": \"Backup stopped. One or more local drives are not mounted.\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: 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 "Checking if the NAS is mounted on nuc-docker01:" +check=$(ssh root@nuc-docker01 df -h | grep 192.168.1.100 | wc -l) +if [[ $check != 1 ]] ; then + payload="{\"message\": \"Backup stopped. Synology isn't mounted\nDate: `date`\", \"priority\": 2,\"title\": \"backups-rpi4: 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`" + +if [[ `ps aux | grep rsync | grep -v grep | grep -v rsync-backups` ]] ; then + echo -e "================================================================================" + echo -e "rsync still running. Exiting...." + echo -e "======= Time complete: `date`" + exit +fi + +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +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 "================================================================================" +echo -e "======= Time: `date`" +echo -e "======= Time complete: `date`" + +echo "Sending completion message" +payload="{\"message\": \"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 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" + +' diff --git a/nixos/hosts/backups-rpi4/scripts/sysctl.sh b/nixos/hosts/backups-rpi4/scripts/sysctl.sh new file mode 100644 index 00000000..bd8a60aa --- /dev/null +++ b/nixos/hosts/backups-rpi4/scripts/sysctl.sh @@ -0,0 +1,56 @@ +#! /bin/env bash +# 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" + +