Commit 6c1df5a5 authored by 智勇's avatar 智勇

--no-create-info --complete-insert

调整顺序
parent f3112501
...@@ -192,14 +192,14 @@ else ...@@ -192,14 +192,14 @@ else
do do
file_name=$db_backup_sub_folders/$table_name.sql file_name=$db_backup_sub_folders/$table_name.sql
echo "mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --tables $table_name --where \"1=1 order by id desc limit 1000\"> $file_name" echo "mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --tables $table_name --where \"1=1 order by id desc limit 1000\"> $file_name"
mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --skip-lock-tables --tables $table_name --where "1=1 order by id desc limit 10000" --skip-add-locks > $file_name mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --skip-lock-tables --tables $table_name --where "1=1 order by id desc limit 10000" --skip-add-locks --no-create-info --complete-insert > $file_name
done done
else else
for table_name in $sys_table_list for table_name in $sys_table_list
do do
file_name=$db_backup_sub_folders/$table_name.sql file_name=$db_backup_sub_folders/$table_name.sql
echo "mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --tables $table_name > $file_name" echo "mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --tables $table_name > $file_name"
mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --skip-lock-tables --tables $table_name --skip-add-locks > $file_name mysqldump -u${source_db_user} -p${source_db_pwd} -h${source_db_host} -P${port} $database_name --skip-lock-tables --tables $table_name --skip-add-locks --no-create-info --complete-insert > $file_name
done done
fi fi
fi fi
...@@ -15,19 +15,6 @@ target_db_port=$5 ...@@ -15,19 +15,6 @@ 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
echo "delete_business_data:"$delete_business_data
if [ "$delete_business_data" = "true" ];then
# echo "DROP DATABASE ${database_name};"
# echo "DROP DATABASE ${database_name};" | mysql -h $mysql_host -P $target_db_port -uqa -pqatest
echo "mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e \"DROP DATABASE ${database_name};\""
mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e "DROP DATABASE ${database_name};"
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;" | mysql -h $mysql_host -P $target_db_port -uqa -pqatest
echo "mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e \"CREATE DATABASE IF NOT EXISTS \`${database_name}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;\""
mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e "CREATE DATABASE IF NOT EXISTS \`${database_name}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
if [ $? != 0 ];then echo "mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e \"CREATE DATABASE ${database_name}\" error";exit -1; fi
for entry in ./*.sql for entry in ./*.sql
do do
...@@ -35,5 +22,6 @@ do ...@@ -35,5 +22,6 @@ do
mysql -h $mysql_host -P $target_db_port -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 -P $target_db_port -uqa -pqatest $database_name < $entry import error ---" echo "--- mysql -h $mysql_host -P $target_db_port -uqa -pqatest $database_name < $entry import error ---"
exit -1
fi fi
done done
...@@ -64,7 +64,17 @@ function db_schema_sync() ...@@ -64,7 +64,17 @@ function db_schema_sync()
uuid=$(uuidgen) uuid=$(uuidgen)
config_file_name="$sync_config_folder/${database}_${uuid}_db_schema_sync_config.json" config_file_name="$sync_config_folder/${database}_${uuid}_db_schema_sync_config.json"
db_backup_sub_folders=$db_backup_folder/${uuid} db_backup_sub_folders=$db_backup_folder/${uuid}
if [ "$delete_business_data" = "true" ];then
# echo "DROP DATABASE ${database_name};" | mysql -h $mysql_host -P $target_db_port -uqa -pqatest
echo "mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e \"DROP DATABASE ${database};\""
mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e "DROP DATABASE ${database};"
fi
# 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
echo "mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e \"CREATE DATABASE IF NOT EXISTS \`${database}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;\""
mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e "CREATE DATABASE IF NOT EXISTS \`${database}\` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
if [ $? != 0 ];then echo "mysql -h $mysql_host -P $target_db_port -uqa -pqatest -e \"CREATE DATABASE IF NOT EXISTS ${database}\" error";exit -1; fi
echo "mkdir $db_backup_sub_folders" echo "mkdir $db_backup_sub_folders"
mkdir -p $db_backup_sub_folders mkdir -p $db_backup_sub_folders
mkdir -p $sync_config_folder mkdir -p $sync_config_folder
...@@ -89,15 +99,16 @@ function db_schema_sync() ...@@ -89,15 +99,16 @@ function db_schema_sync()
echo "--- Skip step 2: replace domain name in tables: $database $db_backup_sub_folders ---" echo "--- Skip step 2: replace domain name in tables: $database $db_backup_sub_folders ---"
fi fi
echo "--- Step 3: import basic data from backup file: $database $db_backup_sub_folders ---" echo "--- Step 3: sync schema: $database $target_db_host ---"
sh $work_dir/db_import.sh $database $target_db_host $db_backup_sub_folders $delete_business_data $target_db_port
if [ $? != 0 ];then echo "db_import.sh $database error";exit -1; fi
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"
echo "mss -conf ${config_file_name} -sync > /dev/null" echo "mss -conf ${config_file_name} -sync > /dev/null"
mss -conf ${config_file_name} -sync > /dev/null mss -conf ${config_file_name} -sync > /dev/null
echo "mysql-schema-sync result:$?" echo "mysql-schema-sync result:$?"
echo "--- Step 4: 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 $target_db_port
# if [ $? != 0 ];then echo "db_import.sh $database error";exit -1; fi
} }
function run_sql_file() function run_sql_file()
......
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