Tuesday, May 20, 2014

Remote Server Rsync Backup Replication Shell Script

  1. #!/bin/bash
  2. # Remote Server Rsync backup Replication Shell Script
  3. # -------------------------------------------------------------------------
  4. # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
  5. # This script is licensed under GNU GPL version 2.0 or above
  6. # -------------------------------------------------------------------------
  7. # This script is part of nixCraft shell script collection (NSSC)
  8. # Visit http://bash.cyberciti.biz/ for more information.
  9. # -------------------------------------------------------------------------
  10. # Local dir location
  11. LOCALBAKPOINT=/disk3
  12. LOCALBAKDIR=/remote/home/httpd/
  13. # remote ssh server
  14. # user
  15. SSHUER=brootbeer
  16.  
  17. # server IP / host
  18. SSHSERVER=10.10.11.12
  19.  
  20. #remote dir to backup
  21. SSHBACKUPROOT=/disk2.backup/hot/
  22.  
  23. rsync --exclude '*access.log*' --exclude '*error.log*' -avz -e 'ssh ' ${SSHUER}@${SSHSERVER}:${SSHBACKUPROOT} ${LOCALBAKPOINT}${LOCALBAKDIR}
  24.  
  25. # log if backup failed or not to /var/log/messages file
  26. [ $? -eq 0 ] && logger 'RSYNC BACKUP : Done' || logger 'RSYNC BACKUP : FAILED!'
  27.  
  28. # Replicate backup to /disk1 and /disk2
  29. # You can also use format user@host:/path
  30. # refer to rsync man page
  31. SRC=${LOCALBAKPOINT}${LOCALBAKDIR}
  32. DST="/disk1/remote /disk2/remote"
  33. for d in $DST
  34. do
  35. [ ! -d $d ] && mkdir -p $d || :
  36. rsync -avr $SRC $d
  37. done

0 comments: