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

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

parent 2760f3b3
......@@ -21,8 +21,8 @@ function db_schema_sync()
config_file_name="$sync_config_folder/${database}_${uuid}_db_schema_sync_config.json"
db_backup_sub_folders=$db_backup_folder/${database}
echo "mkdir $db_backup_sub_folders"
mkdir $db_backup_sub_folders
echo "mkdir -p $db_backup_sub_folders"
mkdir -p $db_backup_sub_folders
echo "--- Step 1: generate_config_file: $config_file_name ---"
echo "source infos: $source_db_host $source_db_user"
......@@ -30,8 +30,8 @@ function db_schema_sync()
echo "database_name is : $sync_db_name"
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"
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 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'
......
......@@ -21,23 +21,25 @@ database_name=$sync_db_name
config_file_name=$8
db_backup_sub_folders=$9
use_cache=$10
port=""
sys_table_list=""
sync_config_folder=~/db_sync_configs
base_config_file=$sync_config_folder/base_config.json
cache_dir=/root/daily_db_backup
if [ $# -ne 9 ]; then
echo "db_gen_config.sh"
echo "Total Number of Parameters : $#"
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 "sync_db_name: $7"
echo "config_file_name: $8"
echo "db_backup_sub_folders: $9"
exit 1
fi
# if [ $# -ne 9 ]; then
# echo "db_gen_config.sh"
# echo "Total Number of Parameters : $#"
# 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 "sync_db_name: $7"
# echo "config_file_name: $8"
# echo "db_backup_sub_folders: $9"
# exit 1
# fi
echo "prepare to get port"
if [[ $database_name = 'xyqb' ]]; then
......@@ -159,11 +161,15 @@ sed -i "s/source_port/${port}/g" $config_file_name
for table_name in $sys_table_list
do
file_name=$db_backup_sub_folders/$table_name.sql
if [[ $table_name = 'repay' || $table_name = 'v_manifest' || $table_name = 'v_repay' ]]; then
echo "skip view table $table_name"
if [ $use_cache = "false"];then
if [[ $table_name = 'repay' || $table_name = 'v_manifest' || $table_name = 'v_repay' ]]; then
echo "skip view table $table_name"
else
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
fi
else
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
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
......@@ -10,12 +10,13 @@
source ~/.bash_profile
source ~/.profile
if [ $# -ne 9 ]; then
if [ $# -ne 10 ]; then
echo "---------------"
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 "sync_db_name: $7, re_replace_ip: $8"
echo "delete_business_data: $9"
echo "use_cache: $10"
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 "---------------"
......@@ -34,6 +35,7 @@ target_db_pwd=$6
sync_db_name=$7
re_replace_ip=$8
delete_business_data=$9
use_cache=$10
work_dir=/home/qa-deploy-utils/db-utils
sync_config_folder=~/db_sync_configs
......@@ -73,8 +75,9 @@ function db_schema_sync()
echo "target infos: $target_db_host $target_db_user"
echo "database_name is : $sync_db_name"
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: 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