Commit 67753053 authored by Haack's Networking's avatar Haack's Networking
Browse files

updated name to match purpose and logs

parent d582a380
#!/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/rsync-on-or-offiste-temp.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
wait
then
#since the ping above was a success
echo "Fred's home server or primary desktop seems available, $(hostname) will try running a mirror on it." >> $logfile
sudo rsync -av --log-file=/home/user/rsync-on-or-offiste-temp.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 ^^
wait
mail -s "[rsync-off-or-onsite]-success-$(hostname)-$(date)" fred@hack.com < $logfile
wait
cat $logfile >> /home/user/rsync-on-or-offiste.log
wait
rm $logfile
chown -R user:user /home/remoteusers/remotedirectory/
chmod -R 750 /home/remoteusers/remotedirectory/
wait
exit
else
#since the ping above was a failure
echo "Fred's home server or primary desktop seems unavailable, $(hostname) will try again tomorrow at this same time."
mail -s "[offsite-backup]-failure-$(hostname)-$(date)" fred@hack.com < $logfile
wait
cat $logfile >> /home/user/rsync-on-or-offiste.log
wait
rm $logfile
wait
exit
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