Created
March 8, 2017 11:46
-
-
Save HakimCassimallyBBC/ee72169e3b0213413333067760fadee2 to your computer and use it in GitHub Desktop.
slightly modified mysql_splitdump.sh
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 | |
#### | |
# Split MySQL dump SQL file into one file per table | |
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump | |
# from https://gist.github.com/jasny/1608062 | |
#### | |
if [ $# -lt 1 ] ; then | |
echo "USAGE $0 DUMP_FILE" | |
exit | |
fi | |
csplit -s -ftable $1 "/-- Dumping data for table/" {*} | |
[ $? -eq 0 ] || exit | |
mv table00 head | |
FILE=`ls -1 table* | tail -n 1` | |
csplit -b '%d' -s -f$FILE $FILE "/40103 SET TIME_ZONE=@OLD_TIME_ZONE/" {*} | |
mv ${FILE}1 foot | |
for FILE in `ls -1 table*`; do | |
NAME=`head -n1 $FILE | cut -d$'\x60' -f2` | |
cat head $FILE foot > "$NAME.sql" | |
done | |
# rm head foot table* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment