Skip to content

Instantly share code, notes, and snippets.

@rc5hack
Created May 15, 2013 08:56
Show Gist options
  • Save rc5hack/5582568 to your computer and use it in GitHub Desktop.
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
#!/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