Guest User

Untitled

a guest
Nov 4th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #!/bin/bash
  2. ### change the values below where needed.....
  3. DBNAMES="buses"
  4. HOST="--host=localhost"
  5. USER="--user=buswatcher"
  6. PASSWORD="--password=njtransit"
  7. BACKUP_DIR="/home/anthony/outgoing_data"
  8.  
  9. #### you can change these values but they are optional....
  10. OPTIONS="--default-character-set=latin1 --complete-insert --no-create-info --compact -q"
  11. RESTORESCRIPT="$BACKUP_DIR/__restoreData.sql"
  12. DATE=`/bin/date '+%y%m%d_%H%M%S'`
  13.  
  14. #### make no changes after this....
  15. #### start script ####
  16. echo removing old temporary files if they exists...
  17. rm -f ${BACKUP_DIR}/*.sql > /dev/null 2>&1
  18. rm -f ${BACKUP_DIR}/*.tar > /dev/null 2>&1
  19. cd ${BACKUP_DIR}
  20.  
  21. for DB in $DBNAMES
  22. do
  23. echo "=========================================="
  24. echo ${DB}
  25. echo "=========================================="
  26. echo 'SET FOREIGN_KEY_CHECKS=0;' > $RESTORESCRIPT
  27.  
  28. mysqldump --no-data $HOST $USER $PASSWORD $DB > ${BACKUP_DIR}/__createTables.sql
  29. echo 'source __createTables.sql;' >> $RESTORESCRIPT
  30.  
  31. for TABLE in `mysql $HOST $USER $PASSWORD $DB -e 'show tables' | egrep -v 'Tables_in_' `; do
  32. TABLENAME=$(echo $TABLE|awk '{ printf "%s", $0 }')
  33. FILENAME="${TABLENAME}.sql"
  34. echo Dumping $TABLENAME
  35. echo 'source' $FILENAME';' >> $RESTORESCRIPT
  36. mysqldump $OPTIONS $HOST $USER $PASSWORD $DB $TABLENAME > ${BACKUP_DIR}/${FILENAME}
  37. done
  38.  
  39. echo 'SET FOREIGN_KEY_CHECKS=1;' >> $RESTORESCRIPT
  40.  
  41. echo making tar...
  42. tar -cf ${DB}_${DATE}.tar *.sql > /dev/null 2>&1
  43.  
  44. echo compressing...
  45. gzip -9 ${DB}_${DATE}.tar > /dev/null 2>&1
  46.  
  47. echo removing temporary files...
  48. rm -f ${BACKUP_DIR}/*.sql > /dev/null 2>&1
  49. rm -f ${BACKUP_DIR}/*.tar > /dev/null 2>&1
  50.  
  51. echo "done with " $DB
  52. done
  53.  
  54. echo "=========================================="
  55. echo " done with all database! "
  56. echo "=========================================="
Add Comment
Please, Sign In to add comment