Commit 51427be6 authored by daidekun's avatar daidekun

加入对ip的正则判断,如果是完整ip,则不按最后一位取。

parent adea5937
...@@ -27,8 +27,8 @@ source_db_host=$1 ...@@ -27,8 +27,8 @@ source_db_host=$1
source_db_user=$2 source_db_user=$2
source_db_pwd='Uiwb@o^fR&nHOa5t' source_db_pwd='Uiwb@o^fR&nHOa5t'
ip_last=$4 ip_value=$4
target_db_host="192.168.4.$ip_last"
target_db_user=$5 target_db_user=$5
target_db_pwd=$6 target_db_pwd=$6
...@@ -41,6 +41,25 @@ work_dir=/home/qa-deploy-utils/db-utils ...@@ -41,6 +41,25 @@ work_dir=/home/qa-deploy-utils/db-utils
sync_config_folder=~/db_sync_configs sync_config_folder=~/db_sync_configs
db_backup_folder=~/db_backups db_backup_folder=~/db_backups
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
if valid_ip $ip_value; then target_db_host="$ip_value"; else target_db_host="192.168.4.$ip_value"; fi
function db_schema_sync() function db_schema_sync()
{ {
database=$1 database=$1
...@@ -61,7 +80,7 @@ function db_schema_sync() ...@@ -61,7 +80,7 @@ function db_schema_sync()
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.1: is re_replace_ip: $re_replace_ip" echo "Step 2.1: is re_replace_ip: $re_replace_ip"
sh $work_dir/db_replace_ip.sh $database $target_db_host $db_backup_sub_folders $re_replace_ip $ip_last sh $work_dir/db_replace_ip.sh $database $target_db_host $db_backup_sub_folders $re_replace_ip $ip_value
echo "Step 3: import basic data from backup file: $database $mysql_host $db_backup_sub_folders" echo "Step 3: import basic data from backup file: $database $mysql_host $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
......
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