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
#Jonathan Haack
#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.
#define services and logs
#create log file, ping server for 5 seconds, record data to log
touch $logfile
ping -w 5 > $logfile
#check log for from string, which is usually sufficient evidence of a network connection, owing to the response.
grep "from" $logfile
#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' /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)" < $logfile
rm $logfile
#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)" < $logfile
rm $logfile
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