shell(14)安装客户端提取表结构脚本(支持多数据库)
针对之前支持单数据库的脚本优化下,能够支持多种数据库。
配置文件
修改DB_TYPE_ONE=mysql等于其他数据库,就可以支持了。
#dbType
DB_TYPE_ONE=mysql
DB_TYPE_ALL=mysql,postgresql,vertica,oracle,dm
#database json
MYSQL_JSON=36417-MYSQL-aoe_java-5-202111021304.json
ORACLE_JSON=593508-ORACLE-ORCL-4-202111021150.json
POSTGRES_JSON=955489-POSTGRESQL-aoe_java-3-202111021149.json
VERTICA_JSON=803147-VERTICA-verticadb-9-202111021459.json
DM_JSON=516328-DM-DAMENG-4-202111101530.json
#mysql database url and aoeurl
MYSQL_URL=jdbc:mysql://10.1.1.143:3306/aoe_java?useSSL=false&useUnicode=yes&characterEncoding=UTF-8
MYSQL_USER=root
MYSQL_SECRET=123456
MYSQL_AOE=jdbc:mysql:aoe://10.1.1.143:3306/aoe_java?useSSL=false&useUnicode=yes&characterEncoding=UTF-8
#tableName
MYSQL_TABLE=aoedata
#oracle database url and aoeurl
ORACLE_URL=jdbc:oracle:thin:@10.1.1.232:1521/ORCL
ORACLE_USER=HMF
ORACLE_SECRET=lianshi
#AOE
ORACLE_AOE=jdbc:aoe:oracle:thin:@10.1.1.232:1521/ORCL
ORACLE_TABLE=AOEDATA
#pgSQL database url and aoeurl
POSTGRES_URL=jdbc:postgresql://10.1.1.112:5432/aoe_java?currentSchema=public
POSTGRES_USER=postgres
POSTGRES_SECRET=postgres
#AOE
POSTGRES_AOE=jdbc:postgresql:aoe://10.1.1.112:5432/aoe_java?currentSchema=public
POSTGRES_TABLE=aoedata
#vertica database url and aoeurl
VERTICA_URL=jdbc:vertica://10.1.1.215:5433/verticadb?searchPath=cg
VERTICA_USER=dbadmin
VERTICA_SECRET=lianShi2021
#AOE
VERTICA_AOE=jdbc:vertica:aoe://10.1.1.215:5433/verticadb?searchPath=cg
VERTICA_TABLE=aoedata
#dm database url and aoeurl
DM_URL=jdbc:dm://10.1.1.112:5236/DAMENG
DM_USER=hmf
DM_SECRET=lianshi2021
#AOE (oracle和dm表名在数据库里会自动变成大写)
DM_AOE=jdbc:dm:aoe://10.1.1.112:5236/DAMENG
DM_TABLE=AOEDATA
Shell脚本:
#!/bin/bash
echo "----------------Java调用shell脚本解压/安装客户端,开始-------------------"
pwdDir=`pwd`
cd $pwdDir
echo "当前工程目录:"$pwdDir
#删除原有客户端里的文件和SDK目录
client_installDir=`find /opt -name "AOEClient_auto"`
if [ -d $client_installDir ];then
rm -rf $client_installDir
echo $client_installDir"AOEClient安装目录存在,进行删除"
fi
#删除casb,这里如果有客户端最好在客户端删除
casbDir=`find /opt -name "casb"`
if [ -d $casbDir ];then
rm -rf $casbDir
echo $casbDir"SDK安装目录:/opt/casb存在,进行删除"
fi
#删除原有解压安装包
#当前存在客户端解压的安装包目录
cd $pwdDir
echo "进入当前工程目录"$pwdDir
clientDir_old=`ls -l |grep ^d |grep "AOEClient" |awk '{print $9}'`
if [ -d $clientDir_old ];then
rm -rf $clientDir_old
echo $clientDir_old"已解压的安装包目录在当前目录存在,进行删除"
fi
clientZip=`ls AOEClient*.zip`
if [ -f "$clientZip" ]; then
#AOEClient解压缩
echo "-----------------------------------------------------------"
echo "-----------------AOEClient解压缩---------------------------"
unzip $clientZip
echo "-----------------------------------------------------------"
#创建配置文件
echo "root" > config
echo "root" >> config
echo "64" >> config
#进入安装包目录,执行安装
clientDir=`ls -l |grep ^d |grep "AOEClient" |awk '{print $9}'`
cd $clientDir
echo "进入客户端解压后的目录:"$pwdDir
chmod +x install.sh
echo "----------------shell脚本安装AOEClient-------------------"
sh install.sh /opt/AOEClient_auto <../config
echo "-----------------------------------------------------------"
fi
#查找是否存在客户端安装的目录
clientDir_new=`find /opt -name "AOEClient_auto"`
if [ -d $clientDir_new ];then
echo "客户端安装目录:"$clientDir_new
fi
#加载环境变量
source /etc/profile
echo $LD_LIBRARY_PATH
#查找数据库文件并读取数据
db_properties=`find $pwdDir/target/classes -name "db-java.properties"`
if [ -f "$db_properties" ];then
#获取数据库类型
dbtype=$(cat "$db_properties" | grep "DB_TYPE_ONE" | awk -F '=' '{print $2}')
if [[ $dbtype == "oracle" ]]; then
user=$(cat "$db_properties" | grep "ORACLE_USER" | awk -F '=' '{print $2}')
password=$(cat "$db_properties" | grep "ORACLE_SECRET" | awk -F '=' '{print $2}')
url=$(cat "$db_properties" | grep "ORACLE_URL" | awk -F '=' '{print $2}')
elif [[ $dbtype == "postgresql" ]]; then
user=$(cat "$db_properties" | grep "POSTGRES_USER" | awk -F '=' '{print $2}')
password=$(cat "$db_properties" | grep "POSTGRES_SECRET" | awk -F '=' '{print $2}')
url=$(cat "$db_properties" | grep "POSTGRES_URL" | awk -F '=' '{print $2}')
elif [[ $dbtype == "vertica" ]]; then
user=$(cat "$db_properties" | grep "VERTICA_USER" | awk -F '=' '{print $2}')
password=$(cat "$db_properties" | grep "VERTICA_SECRET" | awk -F '=' '{print $2}')
url=$(cat "$db_properties" | grep "VERTICA_URL" | awk -F '=' '{print $2}')
else
user=$(cat "$db_properties" | grep "MYSQL_USER" | awk -F '=' '{print $2}')
password=$(cat "$db_properties" | grep "MYSQL_SECRET" | awk -F '=' '{print $2}')
url=$(cat "$db_properties" | grep "MYSQL_URL" | awk -F '=' '{print $2}')
fi
dbhost=$(echo "$url" | awk -F '//' '{print $2}' | awk -F ':' '{print $1}' |tr -d '\n')
port=$(echo "$url" | awk -F '//' '{print $2}' | awk -F ':' '{print $2}' | awk -F '/' '{print $1}' |tr -d '\n')
database=$(echo "$url" | awk -F '//' '{print $2}' | awk -F ':' '{print $2}' | awk -F '/' '{print $2}' | awk -F '?' '{print $1}'|tr -d '\n')
echo $dbtype $dbhost $port $database $user $password
#AOEClient提取表结构
clientdir_new=`find /opt -name "AOEClient_auto"`
if [ -d $clientdir_new ];then
echo "-----------------------------------------------------------"
echo "-----------------客户端AOEClient提取表结构------------------"
cd $clientdir_new/extractor
extractorjar=`ls extractor*.jar`
if [ -f $extractorjar ]; then
echo "开始执行提取表结构:java -jar $extractorjar --op=extract --db-type=$dbtype --host=$dbhost --port=$port --user=$user --password=$password --database=$database"
java -jar $extractorjar --op=extract --db-type=$dbtype --host=$dbhost --port=$port --user=$user --password=$password --database=$database
else
echo "无法找到extractor.jar包,无法提取表结构"
fi
else
echo "未找到AOEClient安装目录"
fi
fi
echo "----------------Java调用shell脚本解压/安装客户端,结束--------------------------"
执行结果:
支持单数据库参考:<(shell(8): Shell脚本自动化重装客户端(二)>
https://blog.csdn.net/fen_fen/article/details/117154867
这个是要修改url也可以支持其他数据库。