Created
December 13, 2020 06:02
-
-
Save akumbhani66/f8efb59da05a2eb90e5ef0adf6a277d0 to your computer and use it in GitHub Desktop.
Dump entire db to tsv/csv
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 | |
host=host | |
uname=uname | |
pass=pwd | |
port=port | |
db=db | |
DATE=`date +%Y%m%d` | |
rm -rf $DATE | |
echo 'show tables' | mysql -B -h${host} -u${uname} -p${pass} -P${port} ${db} > tables.txt | |
awk 'NR>1' tables.txt > tables_new.txt | |
while IFS= read -r line | |
do | |
mkdir -p $DATE/$line | |
echo "select * from $line" | mysql -B -h"${host}" -u"${uname}" -p"${pass}" -P"${port}" "${db}" > $DATE/$line/dump.tsv | |
done < tables_new.txt | |
touch $DATE/$DATE.fin | |
rm -rf tables_new.txt tables.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment