#!/bin/sh
#备份项目
today=$(date +%Y%m%d)
rootfile="/data/tomcat8080/test/ROOT"
rootwarfile="/data/tomcat8080/test/ROOT.war"
backfile="/data/tomcat8080/testbak/"
myfile="/data/tomcat8080/temp_back/ROOT.war"
mytest='/data/tomcat8080/test/'
bakrootwar="/data/tomcat8080/testbak/ROOT.war-${today}"
bakroot="/data/tomcat8080/testbak/ROOT-${today}"
if [ -f "${rootwarfile}" -a -d "${rootfile}" ];then
cp -r ${rootfile} ${backfile}/ROOT-${today}
cp -r ${rootwarfile} ${backfile}/ROOT.war-${today}
echo "${mytest}ROOT back success"
echo "${mytest}ROOT.war back success"
echo "${today}-${backfile}-${rootwarfile} back success" >> ${backfile}/log
else echo "${mytest}ROOT not is existed"
echo "${mytest}ROOT.war not is existed"
sleep 1s
fi#删除项目文件
if [ -f "${bakrootwar}" -a -d "${bakroot}" ];then
rm -rf ${rootfile} ${rootwarfile}
echo "${rootfile} rm success"
echo "${rootfile} rm success" >> ${backfile}/log
echo "${rootwarfile} rm success" >> ${backfile}/logelse
echo "${rootwarfile} not is backup"
sleep 1s
fi
#将临时目录下的项目文件复制到根目录
if [ -f "${rootwarfile}" ];then
echo "${rootwarfile} already existed"
echo "${today}-${backfile}-${rootwarfile} already existed" >> ${backfile}/log
elif [ -f "${myfile}" ];then
cp -r /data/tomcat8080/temp_back/ROOT.war /data/tomcat8080/test/
echo "${myfile} copy success"
echo "${today}-${backfile}-${myfile} copy success" >> ${backfile}/log else echo "${myfile} not found"
echo "${today}-${backfile}-${myfile} not found" >> ${backfile}/log
fi
编辑回复