Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/bin/bash
  2. # A Simple Shell Script to Backup Red Hat / CentOS / Fedora / Debian / Ubuntu Apache Webserver and SQL Database
  3. # Path to backup directories
  4. USER="hery"
  5. HOME="/home"
  6.  
  7. # Store only day of month
  8. DOM=$(date +"%d")
  9.  
  10. # Temporary backup name
  11. # this will be created under /tmp
  12. BACKUPDIR="/backup"
  13.  
  14. # Backup file name hostname.time.tar.gz
  15. HOMEFILE="$USER-home-$DOM.tar.gz"
  16. MYSQLFILE="$USER-mysql-$DOM.tar.gz"
  17.  
  18. # Specify databases
  19. DBNAME1="hery_db"
  20.  
  21. # Set MySQL username and password
  22. MYSQLUSER="MYSQL-USER-NAME"
  23. MYSQLPASSWORD="MYSQL-PASSWORD"
  24.  
  25. # Remote SSH server setup - FOR A LATER DATE
  26. SSHSERVER="backup.example.com" # your remote ssh server
  27. SSHUSER="" # username
  28. SSHDUMPDIR="/backup/" # remote ssh server directory to store dumps
  29. SSHPORT=22
  30. # Paths for binary files
  31. TAR="/bin/tar"
  32. MYSQLDUMP="/usr/bin/mysqldump"
  33. GZIP="/bin/gzip"
  34. SCP="/usr/bin/scp"
  35. SSH="/usr/bin/ssh"
  36. LOGGER="/usr/bin/logger"
  37.  
  38.  
  39. #security reason
  40. BACKUPDIR=/tmp${BACKUPDIR}
  41. # make sure backup directory exists
  42. [ ! -d $BACKUPDIR ] && mkdir -p ${BACKUPDIR}
  43.  
  44. #clean backup dir
  45. rm -rf ${BACKUPDIR}/*
  46.  
  47. # Log backup start time in /var/log/messages
  48. $LOGGER "$0: *** Backup started @ $(date) ***"
  49.  
  50. # Backup websever dirs
  51. $TAR -zcvf ${BACKUPDIR}/${HOMEFILE} "${HOME}"
  52.  
  53. # Individual MySQL Backups
  54. $MYSQLDUMP -u ${MYSQLUSER} -h localhost -p${MYSQLPASSWORD} ${DBNAME1} | $GZIP -9 > ${BACKUPDIR}/${MYSQLFILE}
  55.  
  56.  
  57. # Dump all local files to failsafe remote UNIX ssh server / home server - FOR A LATER DATE
  58. $SSH -p ${SSHPORT} ${SSHUSER}@${SSHSERVER} mkdir -p ${SSHDUMPDIR}
  59. $SCP -r ${BACKUPDIR}/* ${SSHUSER}@${SSHSERVER}:${SSHDUMPDIR}
  60.  
  61.  
  62. # Log backup end time in /var/log/messages
  63. $LOGGER "$0: *** Backup Ended @ $(date) ***"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement