# -------------------------------------------------------------------------------
# Filename:    db_replace_ip.sh
# Revision:    1.1
# Date:        2017/02
# Author:      dekun.dai
# Description: 该脚本根据备份sql称特定环境使用的sql
# Usage：used by ../deploy/db_replace_ip.sh
# -------------------------------------------------------------------------------
database_name=$1
server_host=$2
db_sub_backup_folder=$3
re_replace_ip=$4
public_ip="www.q-gp.com"
ip_last=$5
pwd_path="/home/qa-deploy-utils/qa_shell_script"
config_server="$pwd_path/config_server"

echo $server_host
cd $db_sub_backup_folder

file_count=`ls -l |grep "^-"|wc -l`

function trancsHostName()
{
	if [ "$4" = true ]; then
		sed -i "s/$2/$3-$7.q-gp.com/g" $5
	else
		sed -i "s/$2/$6:$1/g" $5
	fi
}

echo "./* file count is $file_count"
if [ "$file_count" -gt 0 ]; then
	for entry in ./*
	do
		sed -i "s/https/http/g" $entry
		echo "is replace ip for db_back_file $entry"
		var=`cat $config_server/get_project_host.sh`
		for v in ${var[@]}
		do
			i=${v//|/ }
			trancsHostName i $re_replace_ip $entry ${server_host} ${ip_last}
		done
	done
fi
