Created
May 27, 2012 15:08
-
-
Save daogurtsov/2814626 to your computer and use it in GitHub Desktop.
import list of databases to mysql
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/sh | |
#Import list of databases to MySQL | |
#Start vars declaration | |
importPath=dbes | |
dbList=domains.txt | |
importLog=import_log.txt | |
#End vars declaration | |
if [ -d "$importPath" -a -f "$dbList" ]; then | |
if [ -f "$importLog" ]; then | |
rm "$importLog" | |
fi | |
touch "$importLog" | |
while read db_file_name db_name db_user db_pass db_host | |
do | |
pathToDB="$importPath"/"$db_file_name" | |
if [ -f "$pathToDB" ]; then | |
mysql -h "$db_host" -u "$db_user" --password="$db_pass" "$db_name" < "$pathToDB" | |
date=`date` | |
echo "$pathToDB" | |
echo "$db_file_name $date" >> "$importLog" | |
else | |
echo "$pathToDB" | |
echo "$pathToDB -doesn't exist" >> "$importPath" | |
fi | |
done < "$dbList" | |
cat "$importLog" | |
echo "===============" | |
wc -l "$importLog" | |
else | |
echo "Check import path and dblist file" | |
fi | |
echo "==============" | |
echo "IMPORT FINISHED" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dblist.txt format example:
db_file_name db_name user password host
test2 test2 root win7 localhost
test3 test3 root win7 localhost
test4 test4 root win7 localhost
test5 test5 root win7 localhost