mkdir -p
This commit is contained in:
parent
7916c165b4
commit
03899e7e0f
@ -15,9 +15,11 @@ preName="${fileName%.*}"
|
||||
PATH=PATH:/usr/bin:/usr/sbin
|
||||
|
||||
if [ ! -d $workPath ]; then
|
||||
mkdir $workPath -p
|
||||
echo workPath $workPath not exist!
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
function uploadLog()
|
||||
{
|
||||
ctype=$1
|
||||
|
101
dbUpgrade.sh
Executable file
101
dbUpgrade.sh
Executable file
@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
|
||||
#dbUpgrade.sh dbUpdate.sql "192.168.96.36" "root" "xtph9638642" "3306" "/tmp/autoDeploy" "ztupload/stage/sql"
|
||||
|
||||
sqlFile=$1
|
||||
dbHost=$2
|
||||
dbUser=$3
|
||||
dbPassword=$4
|
||||
dbPort=$5
|
||||
tempPath=$6
|
||||
ossPath=$7
|
||||
|
||||
projectName="sql"
|
||||
projectPath=${tempPath}/${projectName}
|
||||
|
||||
|
||||
function init(){
|
||||
cd $tempPath
|
||||
if [ ! -d $projectName ]; then
|
||||
mkdir $projectName -p
|
||||
fi
|
||||
}
|
||||
|
||||
function compareMd5(){
|
||||
cd $tempPath
|
||||
oriSum=$(md5sum $sqlFile)
|
||||
oriSum="${oriSum% *}"
|
||||
desSum=""
|
||||
echo "origin file $sqlFile md5sum: $oriSum"
|
||||
|
||||
cd $projectPath
|
||||
if [ ! -f "$sqlFile" ];then
|
||||
cp $tempPath/$sqlFile .
|
||||
return 1
|
||||
else
|
||||
desSum=$(md5sum $sqlFile)
|
||||
desSum="${desSum% *}"
|
||||
echo "current path: $(pwd)"
|
||||
echo "destination file ${sqlFile} md5sum: ${desSum}"
|
||||
fi
|
||||
if [ ${oriSum} = ${desSum} ];then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function replaceAndExec(){
|
||||
cd $projectPath
|
||||
rm $sqlFile
|
||||
rm sqlOut.log
|
||||
cp $tempPath/$sqlFile .
|
||||
/usr/bin/mysql -u${dbUser} -p${dbPassword} -P${dbPort} -e "$(cat ${sqlFile})" | tee sqlOut.log
|
||||
~/ossutil cp -f sqlOut.log oss://${ossPath}/${dbHost}/sqlOut.log
|
||||
}
|
||||
function uploadLog()
|
||||
{
|
||||
ctype=$1
|
||||
identify=$2
|
||||
count=$3
|
||||
echo "current user is ${USER}"
|
||||
journalctl -n $count -xe -${ctype} $identify > ${tempPath}/${identify}.log
|
||||
~/ossutil cp -f ${tempPath}/${identify}.log oss://${ossPath}/${dbHost}/${identify}.log
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "ok: log ${identify} uploaded to oss!"
|
||||
return 0
|
||||
else
|
||||
echo "error: upload log ${identify} to oss failed!"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
echo " "
|
||||
sleep 5
|
||||
echo "dbUpgrade start"
|
||||
init
|
||||
compareMd5
|
||||
result=$?
|
||||
if [ ${result} = 0 ];then
|
||||
echo "local temp file ${sqlFile} is same with ${projectPath},no need to replace"
|
||||
echo "ok: dbUpgrade done"
|
||||
echo " "
|
||||
exit 0
|
||||
else
|
||||
echo "local temp file $sqlFile is different from ${projectPath}, will replace and execusing..."
|
||||
fi
|
||||
replaceAndExec
|
||||
result=$?
|
||||
if [ $result = 0 ];then
|
||||
echo "ok: replace and execuse done"
|
||||
else
|
||||
echo "error: replace and execuse faild"
|
||||
exit 0
|
||||
fi
|
||||
sleep 3
|
||||
uploadLog t autoDeploy 100
|
||||
sleep 1
|
||||
}
|
||||
|
||||
main
|
@ -13,7 +13,8 @@ if [ -n $5 ]; then
|
||||
fi
|
||||
|
||||
if [ ! -d $workPath ]; then
|
||||
mkdir $workPath -p
|
||||
echo workPath $workPath not exist!
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATH=PATH:/usr/bin:/usr/sbin
|
||||
|
Loading…
x
Reference in New Issue
Block a user