Commit 75d5d1d1 authored by Haack's Networking's avatar Haack's Networking
Browse files

new script to run rsync over ssh mirror with email alert + network check

parent 49ce0220
#!/bin/sh
#Jonathan Haack
#oemb1905@jonathanhaack.com
#rsync over ssh mirror script, with availability check, email alerts for success / failure.
#designed to be run on a cron job for a simple daily/weekly/monthly etc. remote mirror.
#structure can be adapted to run rsnapshot instead.
#gpl3
#define services and logs
rsnap="/usr/bin/rsnapshot"
logfile="/home/user/temp-alert.log"
#create log file, ping server for 5 seconds, record data to log
touch $logfile
ping -w 5 domain.com > $logfile
if
#check log for from string, which is usually sufficient evidence of a network connection, owing to the response.
grep "from" $logfile
then
#since the ping above was a success
echo "Fred's home server seems available, $(hostname) will try running a mirror on it." >> $logfile
sudo rsync -av --log-file=/home/alert.log --delete -e 'ssh -i /home/user/.ssh/id_rsa' root@domain.com:/home/remoteusers/remotedirectory/ /media/directory/targetdirectory/
#add as many locations as you need ^^
sudo chown -R user:user /media/directory/
sudo chmod -R 770 /media/directory/
mail -s "[offsite-backup]-success-$(hostname)-$(date)" fred@hack.com < $logfile
rm $logfile
else
#since the ping above was a failure
echo "Fred's home server seems unavailable, $(hostname) will try again tomorrow at this same time."
mail -s "[offsite-backup]-failure-$(hostname)-$(date)" fred@hack.com < $logfile
rm $logfile
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment