Last active
May 17, 2016 20:33
-
-
Save scoutman57/756e0453af3cba5b3a52efb5dc527ca5 to your computer and use it in GitHub Desktop.
Create a schema dump from .frm tables in databases
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 | |
# Author: Shannon Warren | |
# [email protected] | |
# github: w2pc | |
# This script requires dbsake to be installed | |
# http://dbsake.readthedocs.io/en/latest/ | |
echo "This script requires dbsake to be installed" | |
echo "http://dbsake.readthedocs.io/en/latest/" | |
echo "Downloading dbsake!" | |
curl -s http://get.dbsake.net > dbsake | |
chmod u+x dbsake | |
echo "Please enter the full path of the MySQL data directory." | |
read database_path | |
echo "Please enter the full path where you want the files to be saved. File names will be generated from the Database Name" | |
read saved_files | |
if [[ ! -e $saved_files ]]; then | |
mkdir $saved_files | |
elif [[ ! -d $saved_files ]]; then | |
echo "$database_path alread exists but is not a directory" 1>&2 | |
fi | |
find $database_path -name "*.frm"|while read fname; do | |
db_name=$(echo "$fname" | awk -F"/" '{print $(NF-1)}') | |
table_name=$(echo "$fname" | awk -F"/" '{print $NF}') | |
echo "$database_path/$db_name/$table_name" | |
sh dbsake frmdump "$database_path/$db_name/$table_name" | cat >> "$saved_files"/"$db_name"_schema.sql | |
done | |
rm dbsake | |
echo "dbsake removed!" | |
echo "All schema files have been created." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment