daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest May 23rd, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. V_DIR_SQL="/home/sysadmin/data"
  4. V_DIR_BACKUP="/home/sysadmin/backup"
  5.  
  6. V_HOST="localhost"
  7. V_DATABASE="database"
  8. V_USER="root"
  9. V_PASSWORD="root"
  10.  
  11. I_HOST="homologacao"
  12. I_USER="sysadmin"
  13.  
  14. echo ".............................."
  15. echo $(date)
  16. echo " - "
  17.  
  18. echo "Starting dump .......... ready"
  19. START=$(date +%s)
  20.  
  21. echo " 1/5"
  22. echo -n "Dumping functions"
  23. mysqldump --login-path=user --skip-opt --no-create-info --add-drop-table --no-data --routines ${V_SOURCE} > ${V_DIR_SQL}/FUNCTION.sql
  24. echo " ...... ready"
  25.  
  26. echo " 2/5 "
  27. echo -n "Dumping views"
  28. mysql --login-path=user INFORMATION_SCHEMA --skip-column-names --batch -e "SELECT table_name FROM tables WHERE table_type = 'VIEW' AND table_schema = '$V_SOURCE'" | xargs mysqldump -u ${V_USER} -p${V_PASSWORD} ${V_SOURCE} > ${V_DIR_SQL}/VIEW.sql
  29. echo " .......... ready"
  30.  
  31. echo " 3/5 "
  32. echo -n "Dumping tables"
  33. mysql --login-path=user INFORMATION_SCHEMA --skip-column-names --batch -e "SELECT table_name FROM tables WHERE table_type = 'BASE TABLE' AND table_schema = '$V_SOURCE'" | xargs mysqldump -u ${V_USER} -p${V_PASSWORD} ${V_SOURCE} > ${V_DIR_SQL}/TABLE.sql
  34. echo " ......... ready"
  35.  
  36. echo " 4/5"
  37. echo -n "Ziping backup"
  38. rm ${V_DIR_BACKUP}/backup.zip
  39. zip -qrj ${V_DIR_BACKUP}/backup.zip ${V_DIR_SQL}
  40. echo " .......... ready"
  41.  
  42. echo " 5/5"
  43. echo -n "Sending file"
  44. scp ${V_DIR_BACKUP}/backup.zip ${I_USER}@${I_HOST}:backup/ >> ${DIR}backup.log
  45. echo " ........... ready"
  46.  
  47. END=$(date +%s)
  48. TIME=$(( $END - $START ))
  49.  
  50. echo ".............................."
  51. echo "Backup finished ($TIME seconds)"
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