File: //opt/alibabacloud/hbrclient/setup
#!/bin/bash
while getopts "m:t:k:u:n:h:p:x:l:ds" arg
do
case $arg in
m)
clientMode="--mode $OPTARG"
;;
t)
clientType="$OPTARG"
;;
k)
token="--userToken $OPTARG"
;;
u)
userDefinedKey="--userDefinedKey $OPTARG"
;;
n)
networkType="--networkType $OPTARG"
;;
h)
host="--host $OPTARG"
;;
p)
port="--port $OPTARG"
;;
x)
proxy="--proxy $OPTARG"
;;
l)
listeningPort="--listeningPort $OPTARG"
;;
d)
opt="-ignore-cert"
;;
s)
sourceType="sap"
;;
?)
echo "unkonw argument"
exit 1
;;
esac
done
echo "Installing Hybridbackup client ..."
pushd `dirname $0` > /dev/null
mkdir -p conf
mkdir -p logs
mkdir -p download
mkdir -p versions
# Config backint for SAP HANA backup
if [ "$sourceType"x = "sap"x ]
then
echo "Setting up backint client ..."
chmod 755 client/backint
install_path=`pwd`
cd /usr/sap/*/SYS/global/hdb/opt/
if [ -L ids ]
then
echo "remove old link ids ..."
rm -f ids
fi
if [ -L hdbbackint ]
then
echo "remove old link hdbbackint ..."
rm -f hdbbackint
fi
ln -s ${install_path}/client/ids ids
ln -s ${install_path}/client/backint hdbbackint
cd ${install_path}
fi
# Config hbrclient & ids
if [ ! -d "client" ]; then
echo "[ERROR] Cannot find client directory. Failed to install HBR client."
exit 1
fi
pushd client > /dev/null
if [ ! -f "hbrclient" ]; then
echo "[ERROR] Cannot find file hbrclient. Failed to install HBR client."
exit 1
fi
chmod 755 hbrclient
if [ ! -f "ids" ]; then
echo "[ERROR] Cannot find file ids. Failed to install HBR client."
exit 1
fi
chmod 755 ids
# Cleanup existing hbrclient service
echo "Cleanup hbrclient service."
./hbrclient service uninstall
# Install hbrclient service
echo "Register hbrclient service"
./hbrclient service install
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to install hbrclient service. Failed to install HBR client."
exit 1
fi
# Initialize hbrclient service config file
if [ "$clientMode"x = "--mode ApsaraStack"x ]; then
if [ "$clientType"x = "local"x ]; then
echo "Initialize HBR local client to ApsaraStack."
./hbrclient init local --mode ApsaraStack ${token} ${host} ${port} ${proxy} ${listeningPort} --useSSL
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to initialize hbrclient service config. Failed to install HBR client."
exit 1
fi
else
echo "Initialize HBR ecs client to ApsaraStack."
./hbrclient init ecs --mode ApsaraStack ${host} ${port} ${listeningPort} --useSSL
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to initialize hbrclient service config. Failed to install HBR client."
exit 1
fi
fi
else
if [ "$clientType"x = "local"x ]; then
echo "Initialize HBR local client to public cloud."
./hbrclient init local ${token} ${networkType} ${proxy} ${userDefinedKey} ${listeningPort}
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to initialize hbrclient service config. Failed to install HBR client."
exit 1
fi
else
echo "Initialize HBR ecs client to public cloud."
./hbrclient init ecs ${token} ${listeningPort}
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to initialize hbrclient service config. Failed to install HBR client."
exit 1
fi
fi
fi
# Start hbrclient service
echo "Start hbrclient service"
./hbrclient service start
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to start hbrclient service. Failed to install HBR client."
exit 1
fi
popd > /dev/null
# Config updater
if [ ! -d "update" ]; then
echo "[ERROR] Cannot find update directory. Failed to install HBR client."
exit 1
fi
pushd update > /dev/null
if [ ! -f "updater" ]; then
echo "[ERROR] Cannot find file updater. Failed to install HBR client."
exit 1
fi
chmod 755 updater
# Cleanup existing hbrclientupdater service
echo "Cleanup hbrclientupdater service."
./updater -service uninstall
# Install & start hbrclientupdater service
echo "Register hbrclientupdater service."
./updater -service install
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to install hbrclientupdater service. Failed to install HBR client."
exit 1
fi
echo "Start hbrclientupdater service."
./updater -service start
if [ $? -ne 0 ]; then
echo "[ERROR] Failed to start hbrclientupdater service. Failed to install HBR client."
exit 1
fi
popd > /dev/null
popd > /dev/null
echo "Install complete."