主站目录脚本自动更新

今接到开发的一个要求,写个脚本,更新主站目录文件 ,要求,先把更新的文件和要更新的文件 分别备份
然后再进行更新覆盖.这样 话就不用每次更新都要人工去做繁琐的事。脚本考虑到了文件是不定的,随时会变更每一个文件。脚本运行前把更新文件目录压缩后上传到目录,运行脚本就行了。

例如开发要更新user目录下的这几个文件 :

user
├── user/access.log
└── user/public_html
├── user/public_html/css
│ ├── user/public_html/css/admin_main.css
│ └── user/public_html/css/user.css
├── user/public_html/img
│ └── user/public_html/img/spirit.png
└── user/public_html/WEB-INF
└── user/public_html/WEB-INF/jsp
└── user/public_html/WEB-INF/jsp/errorPage.jsp

#!/bin/bash


#backup changed deploy
upload=/home/loho88/upload/deploy
changed=/home/loho88/upload/changed

javaproj=/data/www/java-proj/
backup=/home/loho88/upload/backup

date1=`date +%F_%T`
cp $upload/*.zip $changed/loho_"$date1".zip
mv $upload/*.zip /tmp/lin
unzip /tmp/lin/*.zip -d $upload
wcc=`ls -l $upload|grep drw|awk '{print $9}'|wc -l`

for i in `seq $wcc`;do
ml=`ls -l $upload |grep "drw"|awk '{print $9}'|sed -n "$i"p`
mkdir $backup/deploy_"$ml"_"$date1"
cd $upload
tree -f $ml|grep "\." |awk '{print $NF}'>/tmp/aa
ls -R "$upload"/$ml/|grep "\.">/tmp/aaa
hs=`cat /tmp/aaa|wc -l`
for ii in `seq $hs`;do
wj=`sed -n "$ii"p /tmp/aaa`
wj2=`sed -n "$ii"p /tmp/aa`
cd $javaproj
cp -r -f --parents $wj2 $backup/deploy_"$ml"_"$date1"
cp -r -f "$upload"/$wj2 "$javaproj"$wj2

done
:>/tmp/aa
:>/tmp/aaa
rm -fr "$upload"/* && rm -fr /tmp/lin/*
done

0 个评论

要回复文章请先登录注册