Created
July 5, 2018 16:51
-
-
Save jerryq27/73ee7391dfbab7aefb3b873cc8354b2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Original script: https://gist.github.com/togume/83b4bf40e1528742374bbce338270f34 | |
TABLES=$(mdb-tables -1 "$1") | |
IFS=$'\n' # Internal Field Separator: for loops use spaces to separate input by default, this changes that default value to new lines. | |
for t in $TABLES | |
do | |
# Surround the names in backticks so the spaces are ignored. | |
echo "DROP TABLE IF EXISTS \`$t\`;" | |
done | |
# Increase the size of text fields by removing (255). | |
mdb-schema $1 mysql | sed -e 's/text (.[0-9]*)/text/g' | |
for t in $TABLES | |
do | |
# Escape ' by doubling '' and ` by doubling ``, 3rd regex removes any backslashes within quotes. | |
mdb-export -D '%Y-%m-%d %H:%M:%S' -I mysql $1 $t | sed -e "s/'/''/g" -e 's/"\([0-9]*\)`\([0-9]*\)"/"\1``\2"/g; s/"\([A-Z]*\)\\"/"\1"/g' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment