项目中shell备份目录、复制目录及删除目录

回复 收藏

#!/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

2018-08-06 17:56 举报
已邀请:
0

小路55

赞同来自:

学习了

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: