SHARE
TWEET

rsync backup

a guest Jan 17th, 2012 22 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #what is the current day
  3. datum=`/bin/date +%d.%m.%Y-%H`
  4. #send email in case of error
  5. MAIL="administrator@domena.hr"
  6. #from field
  7. FROM="HTZS-B <backup@domena.hr>"
  8.  
  9. #backup baza
  10. mkdir /var/backups/www/srvhb/baze_${datum}
  11. /usr/bin/mysqldump -uroot -proot baza1 > /var/backups/www/srvhb/baze_${datum}/baza1_$CURRDATE.sql
  12. /usr/bin/mysqldump -uroot -proot baza2 > /var/backups/www/srvhb/baze_${datum}/baza2_$CURRDATE.sql
  13.  
  14.  
  15. #napravi arhivu www foldera
  16. tar -czf /var/backups/www/srvhb/www_${datum}.tgz /var/www/dir > /dev/null 2>&1
  17.  
  18. #rsync archive to remote host
  19. rsync -avz -e ssh /var/backups/www/srvhb/www_${datum}.tgz root@remote_server.com:/var/backups/www/srvhb
  20. #error while syncing check
  21. if [ $? != 0 ]; then
  22.     SUBJECT="BACKUP ERROR!"
  23.     MESSAGE="BACKUP ERROR: problem syncing www_$CURRDATE.tgz backup on SRVH-B!"
  24.  
  25.     TEMP=`mktemp`
  26.     echo "From: $FROM" > $TEMP
  27.     echo "To: $MAIL" >> $TEMP
  28.     echo "Subject: $SUBJECT" >> $TEMP
  29.     echo "" >> $TEMP
  30.     echo "$MESSAGE" >> $TEMP
  31.     /usr/sbin/sendmail -t < $TEMP
  32.     rm $TEMP
  33. fi
  34.  
  35. #delete
  36. rm -r /var/backups/www/srvhb/baze_${datum}
  37.  
  38. #optionally remove backup file
  39. #rm $BACKUPS/www_$CURRDATE.tgz
  40.  
  41. #or delete backups older than 10 days
  42.  
  43. find /var/backups/www/srvhb/* -mtime +10 -exec rm -f {} \;
  44. find /var/backups/www/srvha/* -mtime +10 -exec rm -f {} \;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top