Created
June 9, 2011 15:08
-
-
Save ajbonner/1016920 to your computer and use it in GitHub Desktop.
Mysqldump data from database tables matching a pattern
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 | |
if [ $# -lt 5 ]; then | |
echo "Exports data from mysql database in tables matching a like pattern e.g. 'table_%'" | |
echo "Usage: $0 dbname dbuser dbpass pattern outputfile" | |
exit 1 | |
fi | |
DBNAME=$1 | |
DBUSER=$2 | |
DBPASS=$3 | |
PATTERN=$4 | |
OUTPUTFILE=$5 | |
TABLES=( `mysql -u$DBUSER -p$DBPASS $DBNAME --silent -e "show tables like '$PATTERN'"` ) | |
for TABLE in "${TABLES[@]}"; do | |
mysqldump -u$DBUSER -p$DBPASS $DBNAME $TABLE >> $OUTPUTFILE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment