Created
September 18, 2014 18:50
-
-
Save gnidan/c923e56c33609a17a1a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echoerr() { echo "$@" 1>&2; } | |
upper() { echo "$@" | tr [a-z] [A-Z]; } | |
if [ $# -lt 5 ]; then | |
echoerr "Exports data from mysql database in tables matching a like pattern e.g. 'table_%'" | |
echoerr "Usage: $0 host dbname dbuser dbpass pattern" | |
exit 1 | |
fi | |
HOST=$1 | |
DBNAME=$2 | |
DBUSER=$3 | |
DBPASS=$4 | |
PATTERN=$5 | |
TABLES=( `mysql -h$HOST -u$DBUSER -p$DBPASS $DBNAME --silent -e "show tables like '$PATTERN'"` ) | |
for TABLE in "${TABLES[@]}"; do | |
TABLE_UPPER=$(upper "$TABLE") | |
echoerr "*** GRABBING TABLE: $TABLE_UPPER" | |
mysqldump -h$HOST -u$DBUSER -p$DBPASS $DBNAME $TABLE --quick --single-transaction | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment