Commit 430e5f5d authored by 智勇's avatar 智勇

up

parent 2946a3b8
{ {
"source":"source_db_user:Uiwb@o^fR&nHOa5t@(source_db_host:source_port)/sync_db_name", "source":"source_db_user:Uiwb@o^fR&nHOa5t@(source_db_host:source_port)/sync_db_name",
"dest":"target_db_user:target_db_pwd@(target_db_host:3306)/sync_db_name", "dest":"target_db_user:target_db_pwd@(target_db_host:target_db_port)/sync_db_name",
"alter_ignore":{}, "alter_ignore":{},
"tables":[], "tables":[],
"email":{ "email":{
......
...@@ -30,8 +30,8 @@ function db_schema_sync() ...@@ -30,8 +30,8 @@ function db_schema_sync()
# echo "target infos: $target_db_host $target_db_user" # echo "target infos: $target_db_host $target_db_user"
# echo "database_name is : $sync_db_name" # echo "database_name is : $sync_db_name"
echo "sh $work_dir/db_gen_config.sh $source_db_host $source_db_user $source_db_pwd 192.168.4.12 $target_db_user $target_db_pwd $database $config_file_name $db_backup_sub_folders false" echo "sh $work_dir/db_gen_config.sh $source_db_host $source_db_user $source_db_pwd 192.168.4.12 $target_db_user $target_db_pwd $database $config_file_name $db_backup_sub_folders false 3306"
sh $work_dir/db_gen_config.sh $source_db_host $source_db_user $source_db_pwd 192.168.4.12 $target_db_user $target_db_pwd $database $config_file_name $db_backup_sub_folders false sh $work_dir/db_gen_config.sh $source_db_host $source_db_user $source_db_pwd 192.168.4.12 $target_db_user $target_db_pwd $database $config_file_name $db_backup_sub_folders false 3306
} }
database_list=`grep database_list $work_dir/config/db_config | cut -d "=" -f 2` database_list=`grep database_list $work_dir/config/db_config | cut -d "=" -f 2`
......
...@@ -23,6 +23,7 @@ database_name=$sync_db_name ...@@ -23,6 +23,7 @@ database_name=$sync_db_name
config_file_name=$8 config_file_name=$8
db_backup_sub_folders=$9 db_backup_sub_folders=$9
use_cache=${10} use_cache=${10}
target_db_port=${11}
port="" port=""
sys_table_list="" sys_table_list=""
...@@ -176,6 +177,7 @@ sed -i "s/source_db_pwd/${source_db_pwd}/g" $config_file_name ...@@ -176,6 +177,7 @@ sed -i "s/source_db_pwd/${source_db_pwd}/g" $config_file_name
sed -i "s/target_db_host/${target_db_host}/g" $config_file_name sed -i "s/target_db_host/${target_db_host}/g" $config_file_name
sed -i "s/target_db_user/${target_db_user}/g" $config_file_name sed -i "s/target_db_user/${target_db_user}/g" $config_file_name
sed -i "s/target_db_pwd/${target_db_pwd}/g" $config_file_name sed -i "s/target_db_pwd/${target_db_pwd}/g" $config_file_name
sed -i "s/target_db_port/${target_db_port}/g" $config_file_name
sed -i "s/sync_db_name/${sync_db_name}/g" $config_file_name sed -i "s/sync_db_name/${sync_db_name}/g" $config_file_name
sed -i "s/source_port/${port}/g" $config_file_name sed -i "s/source_port/${port}/g" $config_file_name
......
...@@ -11,6 +11,7 @@ database_name=$1 ...@@ -11,6 +11,7 @@ database_name=$1
mysql_host=$2 mysql_host=$2
db_sub_backup_folder=$3 db_sub_backup_folder=$3
delete_business_data=$4 delete_business_data=$4
target_db_port=$5
echo "cd $db_sub_backup_folder" echo "cd $db_sub_backup_folder"
cd $db_sub_backup_folder cd $db_sub_backup_folder
...@@ -18,16 +19,16 @@ echo "delete_business_data:"$delete_business_data ...@@ -18,16 +19,16 @@ echo "delete_business_data:"$delete_business_data
if [ "$delete_business_data" = "true" ];then if [ "$delete_business_data" = "true" ];then
echo "DROP DATABASE ${database_name};" echo "DROP DATABASE ${database_name};"
echo "DROP DATABASE ${database_name};" | mysql -h $mysql_host -uqa -pqatest echo "DROP DATABASE ${database_name};" | mysql -h $mysql_host -P $target_db_port -uqa -pqatest
fi fi
echo "CREATE DATABASE IF NOT EXISTS \`${database_name}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;" echo "CREATE DATABASE IF NOT EXISTS \`${database_name}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
echo "CREATE DATABASE IF NOT EXISTS \`${database_name}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;" | mysql -h $mysql_host -uqa -pqatest echo "CREATE DATABASE IF NOT EXISTS \`${database_name}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;" | mysql -h $mysql_host -P $target_db_port -uqa -pqatest
for entry in ./*.sql for entry in ./*.sql
do do
echo "mysql -h $mysql_host -uqa -pqatest $database_name < $entry" echo "mysql -h $mysql_host -uqa -pqatest $database_name < $entry"
mysql -h $mysql_host -uqa -pqatest $database_name < $entry mysql -h $mysql_host -P $target_db_port -uqa -pqatest $database_name < $entry
if [ $? != 0 ];then if [ $? != 0 ];then
echo "--- mysql -h $mysql_host -uqa -pqatest $database_name < $entry import error ---" echo "--- mysql -h $mysql_host -P $target_db_port -uqa -pqatest $database_name < $entry import error ---"
fi fi
done done
...@@ -11,10 +11,11 @@ source ~/.bash_profile ...@@ -11,10 +11,11 @@ source ~/.bash_profile
source ~/.profile source ~/.profile
pwd_path="/home/qa-deploy-utils" pwd_path="/home/qa-deploy-utils"
if [ $# -ne 10 ]; then if [ $# -ne 11 ]; then
echo "---------------" echo "---------------"
echo "source_db_infos:source_db_host: $1, source_db_user: $2" echo "source_db_infos:source_db_host: $1, source_db_user: $2"
echo "target_db_infos:target_db_host: $4, target_db_user: $5" echo "target_db_infos:target_db_host: $4, target_db_user: $5"
echo "target_db_port: ${11}"
echo "sync_db_name: $7, re_replace_ip: $8" echo "sync_db_name: $7, re_replace_ip: $8"
echo "delete_business_data: $9" echo "delete_business_data: $9"
echo "use_cache: ${10}" echo "use_cache: ${10}"
...@@ -41,6 +42,7 @@ sync_db_name=$7 ...@@ -41,6 +42,7 @@ sync_db_name=$7
re_replace_ip=$8 re_replace_ip=$8
delete_business_data=$9 delete_business_data=$9
use_cache=${10} use_cache=${10}
target_db_port=${11}
trap "exec 1000>&-;exec 1000<&-;exit 0" 2 trap "exec 1000>&-;exec 1000<&-;exit 0" 2
tempfifo=$$.fifo tempfifo=$$.fifo
...@@ -74,7 +76,7 @@ function db_schema_sync() ...@@ -74,7 +76,7 @@ function db_schema_sync()
echo "delete_business_data : $delete_business_data" echo "delete_business_data : $delete_business_data"
echo "use_cache : $use_cache" echo "use_cache : $use_cache"
sh $work_dir/db_gen_config.sh $source_db_host $source_db_user $source_db_pwd $target_db_host $target_db_user $target_db_pwd $database $config_file_name $db_backup_sub_folders $use_cache sh $work_dir/db_gen_config.sh $source_db_host $source_db_user $source_db_pwd $target_db_host $target_db_user $target_db_pwd $database $config_file_name $db_backup_sub_folders $use_cache $target_db_port
cd $db_backup_sub_folders cd $db_backup_sub_folders
file_count=`ls -l | grep .sql$ | wc -l` file_count=`ls -l | grep .sql$ | wc -l`
...@@ -88,7 +90,7 @@ function db_schema_sync() ...@@ -88,7 +90,7 @@ function db_schema_sync()
fi fi
echo "--- Step 3: import basic data from backup file: $database $db_backup_sub_folders ---" echo "--- Step 3: import basic data from backup file: $database $db_backup_sub_folders ---"
sh $work_dir/db_import.sh $database $target_db_host $db_backup_sub_folders $delete_business_data sh $work_dir/db_import.sh $database $target_db_host $db_backup_sub_folders $delete_business_data $target_db_port
echo "--- Step 4: sync schema: $database $target_db_host ---" echo "--- Step 4: sync schema: $database $target_db_host ---"
#sync_cmd="mss -conf ${config_file_name} -sync" #sync_cmd="mss -conf ${config_file_name} -sync"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment