Created
May 15, 2013 08:56
-
-
Save rc5hack/5582568 to your computer and use it in GitHub Desktop.
Restoring database(s) from dump, assume that *.sql contains "CREATE TABLE" statements, and *.txt contains table data. Folder name is name of database. Based on old Bookvoed's code. Syntax: cd /path/to/folders-with-dumps && ./restore_from_dump.sh database1 database2 ... databaseN
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
#!/usr/bin/env bash | |
if [ -z "$1" ] | |
then | |
echo "You should tell me where to work! I can't guess." | |
exit 1 | |
fi | |
dir=$(pwd) | |
for db in "$@" | |
do | |
for file in $(ls -- ${db}/*.sql) | |
do | |
echo "/usr/bin/env mysql -u root ${db} < ${file}" | |
/usr/bin/env mysql -u root ${db} < ${file} | |
echo "" | |
done | |
echo "find ${dir}/${db} -type f -iname '*.txt*' -print0 | xargs -0 /usr/bin/env mysqlimport -L -u root ${db}" | |
find ${dir}/${db} -type f -iname '*.txt*' -print0 | xargs -0 /usr/bin/env mysqlimport -L -u root ${db} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment