Advertisement
Guest User

Untitled

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