Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # for x in `echo "show databases;" | mysql -u root -ppassword| egrep -v "Database|information_schema|mysql"`; do mysqldump -u root -ppassword --extended=FALSE --compact --single-transaction --quick --skip-extended-insert $x | egrep -h "[[:graph:]]+@[[:graph:]]+" >> $x; done
  4.  
  5. MYSQL_USER=root
  6. MYSQL_PASS=password
  7. MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
  8. SQLSTMT="SELECT CONCAT(table_schema,'.',table_name)"
  9. SQLSTMT="${SQLSTMT} FROM information_schema.tables WHERE table_schema NOT IN "
  10. SQLSTMT="${SQLSTMT} ('information_schema','performance_schema','mysql')"
  11. mysql ${MYSQL_CONN} -ANe"${SQLSTMT}" > /tmp/DBTB.txt
  12. COMMIT_COUNT=0
  13. COMMIT_LIMIT=10
  14. for DBTB in `cat /tmp/DBTB.txt`
  15. do
  16. DB=`echo "${DBTB}" | sed 's/\./ /g' | awk '{print $1}'`
  17. TB=`echo "${DBTB}" | sed 's/\./ /g' | awk '{print $2}'`
  18. DUMPFILE=${DB}-${TB}.csv.gz
  19. mysql ${MYSQL_CONN} -ANe"SELECT * from ${TB}" ${DB} | egrep -h "[[:graph:]]+@[[:graph:]]+" | gzip > ${DUMPFILE}
  20. (( COMMIT_COUNT++ ))
  21. if [ ${COMMIT_COUNT} -eq ${COMMIT_LIMIT} ]
  22. then
  23. COMMIT_COUNT=0
  24. wait
  25. fi
  26. done
  27. if [ ${COMMIT_COUNT} -gt 0 ]
  28. then
  29. wait
  30. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement