Update backup scripts
This commit is contained in:
parent
55cfaff942
commit
b8517efaaf
2 changed files with 76 additions and 6 deletions
|
@ -86,10 +86,10 @@ echo -e "======= Time: `date`"
|
|||
echo -e "rsync -avr --delete /Storage/Video/Music/ /mnt/$drive1/Music/"
|
||||
rsync -avr --delete root@nuc-docker01:/Storage/Video/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 --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`"
|
||||
|
@ -130,9 +130,78 @@ payload="{\"message\": \"Backup completed\nDate: `date`\n`df -h | grep sda`\n`df
|
|||
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 ]] && [[ munted2 != 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"
|
||||
|
||||
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 Storage | wc -l)
|
||||
if [[ $check != 3 ]] ; then
|
||||
payload="{\"message\": \"Data Vol Backup stopped. nuc-docker01 does not have 3 mounts in Storage\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/ /Storage/Data/ /mnt/$drive1/Data/"
|
||||
rsync -avr --delete --exclude=Downloads/ 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"
|
||||
|
||||
'';
|
||||
'';
|
||||
in
|
||||
{
|
||||
environment.systemPackages = [ rsync-backups ];
|
||||
environment.systemPackages = [
|
||||
rsync-backups
|
||||
rsync-data-vol
|
||||
];
|
||||
|
||||
# Set up the secret for the password:
|
||||
sops.secrets."gotify_token" = {
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
systemCronJobs = [
|
||||
# Backups from nuc-docker01 - See "backup-script.nix"
|
||||
# https://git.sysctl.io/albert/random-scripts/src/branch/master/rsync-pi/rsync-all.sh
|
||||
''0 9 * * 3 root rsync-backups >> /root/logs/rsync-backup-`date "+\%Y-\%m-\%d"`''
|
||||
''0 9 * * * root rsync-backups >> /root/logs/rsync-backup-`date "+\%Y-\%m-\%d"`''
|
||||
''0 19 * * 3 root rsync-data-vol >> /root/logs/rsync-data-vol-`date "+\%Y-\%m-\%d"`''
|
||||
];
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue