脚本用途:
把已经打好包的代码,替换到生产环境上面。
对即将替换的文件进行备份。
调用方法:
(1)把编译好的代码打包成*.tar
(2)在程序的家目录下,建一个 versions/日期 的目录
(3)上传tar包到该文件夹
(4)配置好脚本的参数
(5)执行脚本:
$ ./VersionUpdate.sh 0619
mark:
脚本写得未尽完善,还有待改进的地方。
【以下是脚本】
##================================
#!/usr/bin/sh
workDIR=`pwd`
logDIR=${workDIR}/log
shellName=`basename $0 .sh`
runTime=`date +%y%m%d_%H%M`
logFile=${logDIR}/${shellName}_${runTime}
[ ! -d ${logDIR} ] && mkdir -p ${logDIR}
[ ! -d ${backupDIR} ] && mkdir -p ${backupDIR}
dstPath=/home/moumouxitong/apache-tomcat-8.0.24/webapps/
LOG()
{
echo "[`date '+%Y-%m-%d %H:%M:%S'`] $*"
}
case ${1} in
[0-9]* ) version=$1
versionPath=/home/moumouxitong/versions/${version}
[ ! -d ${versionPath} ] && echo "Can not find version path"
;;
* ) echo Input Error && exit 99
;;
esac
main()
{
LOG "Begin to untar Package."
find ${versionPath} -type f -name "*.tar" -exec tar -xf {} -C ${versionPath} \;
LOG "Begin to get the file list."
cd ${versionPath}
find . -type f ! -name "*.tar" > ${workDIR}/${shellName}.lst
ls -l ${workDIR}/${shellName}.lst
LOG "Current path is:"
cd ${dstPath}
pwd
LOG "Begin to backup files"
while read line
do
cp ${line} ${line}_`date +%H%M%S`.bak
done < ${workDIR}/${shellName}.lst
LOG "Finish backup files"
LOG "Begin to copy files"
cp -r ${versionPath}/XXXXX ${dstPath}
}
main >> ${logFile}.log 2>&1