分享一个版本升级脚本


脚本用途:

把已经打好包的代码,替换到生产环境上面。

对即将替换的文件进行备份。


调用方法:

(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




  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值