Commit 88d5d789 authored by 智勇's avatar 智勇

增加是否使用本地备份数据参数use_cache

parent 2760f3b3
...@@ -21,8 +21,8 @@ function db_schema_sync() ...@@ -21,8 +21,8 @@ function db_schema_sync()
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/${database} db_backup_sub_folders=$db_backup_folder/${database}
echo "mkdir $db_backup_sub_folders" echo "mkdir -p $db_backup_sub_folders"
mkdir $db_backup_sub_folders mkdir -p $db_backup_sub_folders
echo "--- Step 1: generate_config_file: $config_file_name ---" echo "--- Step 1: generate_config_file: $config_file_name ---"
echo "source infos: $source_db_host $source_db_user" echo "source infos: $source_db_host $source_db_user"
...@@ -30,8 +30,8 @@ function db_schema_sync() ...@@ -30,8 +30,8 @@ function db_schema_sync()
echo "database_name is : $sync_db_name" echo "database_name is : $sync_db_name"
echo "delete_business_data : $delete_business_data" echo "delete_business_data : $delete_business_data"
echo "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" echo "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 false"
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 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 false
} }
database_list='cash_loan_flow contract dujiangyan financial_system financial_system_api fund_manage gyxd mall merchant notify offline payment_center qinqiong quartz redpacket risk_control silk_road spider_center user_credit xyqb xyqb_app xyqb_btzt xyqb_user' database_list='cash_loan_flow contract dujiangyan financial_system financial_system_api fund_manage gyxd mall merchant notify offline payment_center qinqiong quartz redpacket risk_control silk_road spider_center user_credit xyqb xyqb_app xyqb_btzt xyqb_user'
......
...@@ -21,23 +21,25 @@ database_name=$sync_db_name ...@@ -21,23 +21,25 @@ 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
port="" port=""
sys_table_list="" sys_table_list=""
sync_config_folder=~/db_sync_configs sync_config_folder=~/db_sync_configs
base_config_file=$sync_config_folder/base_config.json base_config_file=$sync_config_folder/base_config.json
cache_dir=/root/daily_db_backup
if [ $# -ne 9 ]; then # if [ $# -ne 9 ]; then
echo "db_gen_config.sh" # echo "db_gen_config.sh"
echo "Total Number of Parameters : $#" # echo "Total Number of Parameters : $#"
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 "sync_db_name: $7" # echo "sync_db_name: $7"
echo "config_file_name: $8" # echo "config_file_name: $8"
echo "db_backup_sub_folders: $9" # echo "db_backup_sub_folders: $9"
exit 1 # exit 1
fi # fi
echo "prepare to get port" echo "prepare to get port"
if [[ $database_name = 'xyqb' ]]; then if [[ $database_name = 'xyqb' ]]; then
...@@ -159,11 +161,15 @@ sed -i "s/source_port/${port}/g" $config_file_name ...@@ -159,11 +161,15 @@ sed -i "s/source_port/${port}/g" $config_file_name
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
if [ $use_cache = "false"];then
if [[ $table_name = 'repay' || $table_name = 'v_manifest' || $table_name = 'v_repay' ]]; then if [[ $table_name = 'repay' || $table_name = 'v_manifest' || $table_name = 'v_repay' ]]; then
echo "skip view table $table_name" echo "skip view table $table_name"
else else
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 > $file_name
fi fi
else
echo "\cp -f $cache_dir/$database_name/table_name.sql $file_name"
\cp -f $cache_dir/$database_name/table_name.sql $file_name
fi
done done
...@@ -10,12 +10,13 @@ ...@@ -10,12 +10,13 @@
source ~/.bash_profile source ~/.bash_profile
source ~/.profile source ~/.profile
if [ $# -ne 9 ]; then if [ $# -ne 10 ]; 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 "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 "--- 参数不正确 ---" echo "--- 参数不正确 ---"
echo "Usage:sh db_schema_sync.sh source_db_host source_db_user source_db_pwd target_db_host target_db_user target_db_pwd sync_db_name" echo "Usage:sh db_schema_sync.sh source_db_host source_db_user source_db_pwd target_db_host target_db_user target_db_pwd sync_db_name"
echo "---------------" echo "---------------"
...@@ -34,6 +35,7 @@ target_db_pwd=$6 ...@@ -34,6 +35,7 @@ target_db_pwd=$6
sync_db_name=$7 sync_db_name=$7
re_replace_ip=$8 re_replace_ip=$8
delete_business_data=$9 delete_business_data=$9
use_cache=$10
work_dir=/home/qa-deploy-utils/db-utils work_dir=/home/qa-deploy-utils/db-utils
sync_config_folder=~/db_sync_configs sync_config_folder=~/db_sync_configs
...@@ -73,8 +75,9 @@ function db_schema_sync() ...@@ -73,8 +75,9 @@ 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 "delete_business_data : $delete_business_data" echo "delete_business_data : $delete_business_data"
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 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
echo "--- Step 2: replace domain name in tables: $database $mysql_host $db_backup_sub_folders ---" echo "--- Step 2: replace domain name in tables: $database $mysql_host $db_backup_sub_folders ---"
echo "--- Step 2: is re_replace_ip: $re_replace_ip ---" echo "--- Step 2: is re_replace_ip: $re_replace_ip ---"
......
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