Advertisement
Guest User

Untitled

a guest
May 1st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #####################################################################################################################
  2. ############# SCRIPT FOR DUMPING DATABASES FROM ROOT ##########################################################
  3. #####################################################################################################################
  4.  
  5. MYSQL_USER="root"
  6. MYSQL_PASS="yourpasswordhere"
  7.  
  8. echo "-- START --"
  9.  
  10. echo "SET autocommit=0;SET unique_checks=0;SET foreign_key_checks=0;" > tmp_sqlhead.sql
  11. echo "SET autocommit=1;SET unique_checks=1;SET foreign_key_checks=1;" > tmp_sqlend.sql
  12.  
  13. if [ -z "$1" ]
  14. then
  15. echo "-- Dumping all DB ..."
  16. for I in $(mysql -u $MYSQL_USER --password=$MYSQL_PASS -e 'show databases' -s --skip-column-names);
  17. do
  18. if [ "$I" = information_schema ] || [ "$I" = mysql ] || [ "$I" = phpmyadmin ] || [ "$I" = performance_schema ] # exclude this DB
  19. then
  20. echo "-- Skip $I ..."
  21. continue
  22. fi
  23. echo "-- Dumping $I ..."
  24. # Pipe compress and concat the head/end with the stoutput of mysqlump ( '-' cat argument)
  25. mysqldump -u $MYSQL_USER --password=$MYSQL_PASS $I | cat tmp_sqlhead.sql - tmp_sqlend.sql | gzip -fc > "$I.sql.gz"
  26. done
  27.  
  28. else
  29. I=$1;
  30. echo "-- Dumping $I ..."
  31. # Pipe compress and concat the head/end with the stoutput of mysqlump ( '-' cat argument)
  32. mysqldump -u $MYSQL_USER --password=$MYSQL_PASS $I | cat tmp_sqlhead.sql - tmp_sqlend.sql | gzip -fc > "$I.sql.gz"
  33. fi
  34.  
  35. # remove tmp files
  36. rm tmp_sqlhead.sql
  37. rm tmp_sqlend.sql
  38.  
  39. echo "-- FINISH --"
  40.  
  41.  
  42. ###########################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement