網站程序文件增量更新腳本

說明:css

功能:原文件更新,新文件加入,此腳本暫時不支持新增目錄加入jquery

upload目錄和web目錄是同級的 他們下面的目錄級別也是同樣的,這點要注意web

[root@tzp ~]# ls upload/images/main/
logo.png  qrcode.pngtomcat

[root@tzp ~]# ls web/images/main/
footphone.png  loading1.gif  logo2.png  logo.png       qrcodedy.jpg  qrcodefw.jpg  qrcode.png   verify2.png  verifyicon.png
hxbanner.png   loading.gif   logo3.png  qrcodeapp.png  qrcodedy.png  qrcodefw.png  verify1.png  verify3.png  zhili.png

bash

#!/bin/bash

upname=upload
ywjname=web #項目目錄名
upload=/root/upload #更新項目文件目錄
ywj=/root/web #項目地址
backup=/root/backup #項目備份存放目錄
#sshpass -p "$password" ssh  -t hladmin@"$ipp"  "cd ~;/bin/sh "$project".sh shutdown"
#/data/tomcat-web/bin/shutdown.sh
#備份源文件
cp -r "$ywj" /root/backup/web_`date +%Y%m%d`
#過濾掉中文名稱
china=$(ls -l -R "$upload"|grep -vE 'drw|upload|用量|^$'|awk -F' ' '{print $9}'|sed 's/[a-zA-Z0-9[:punct:]]//g' | grep -v '^$')
gl=`echo $china|sed 's# #|#g'`

for filename in `ls -l -R "$upload"|grep -vE 'drw|upload|用量|^$'|awk -F' ' '{print $9}'|grep -vE "$gl"|sort|uniq -c|awk -F' ' '{print $2}'|grep -v $(ls -l $upload|grep -v drw|awk '{print $9}'|grep -v ^$)`;do
#uploadurl=
double=$(find $upload -name "$filename"|wc -l)
doubley=$(find $ywj -name "$filename"|wc -l)

  if [ "$double" -gt 1 ];then
  echo 2
    for dfile in `seq $double`;do
      uploadurl=$(find $upload -name "$filename"|sed -n "$dfile"p)
      echo $uploadurl
      echo '==========2============'
      ywjurl=`find $ywj -name "$filename"|grep "$ywjname"'/'$(echo "$uploadurl"|sed -r 's#(/[^/]*){2}/(.*)/[^/]*$#\2#')'/'"$filename"`
      echo '#update'
      \cp -r  $uploadurl $ywjurl
      echo ' '
    done
 
   elif [ "$doubley" -eq 0 ];then
     echo $filename
     uploadurl=$(find $upload -name "$filename")
     echo $uploadurl
     echo '===============1========='
     #echo 新文件
     \cp -r $uploadurl  "$ywj"'/'"$(find $upload -name "$filename"|cut -d'/' -f4-)"
 
   elif [ "$double" -eq 1 ];then
     echo 1
     uploadurl=$(find $upload -name "$filename")
     echo $uploadurl
     echo '===============1========='
     #echo 源文件
      ywjurl=`find $ywj -name "$filename"|grep "$ywjname"'/'$(echo "$uploadurl"|sed -r 's#(/[^/]*){2}/(.*)/[^/]*$#\2#')'/'"$filename"`
      echo '#update'
      \cp -r  $uploadurl $ywjurl
     echo ' '
  fi
done
#/data/tomcat-web/bin/startup.sh多線程

注:腳本要用在正式環境中要改幾個地方app

tomcat關閉和啓動行,更新行把echo去掉ssh

運行測試結果:測試

[root@tzp ~]# sh sinn.sh
1
/root/upload/images/newer/banner.png
===============1=========
#update
\cp -r  /root/upload/images/newer/banner.png /root/web/images/newer/banner.png
 
1
/root/upload/images/product/bar.png
===============1=========
#update
\cp -r  /root/upload/images/product/bar.png /root/web/images/product/bar.png
 
1
/root/upload/lib/My97DatePicker/calendar.js
===============1=========
#update
\cp -r  /root/upload/lib/My97DatePicker/calendar.js /root/web/lib/My97DatePicker/calendar.js
 
1
/root/upload/lib/My97DatePicker/lang/en.js
===============1=========
#update
\cp -r  /root/upload/lib/My97DatePicker/lang/en.js /root/web/lib/My97DatePicker/lang/en.js
 
1
/root/upload/images/newer/hz1.png
===============1=========
#update
\cp -r  /root/upload/images/newer/hz1.png /root/web/images/newer/hz1.png
 
1
/root/upload/lib/fullpage/jquery.fullPage.css
===============1=========
#update
\cp -r  /root/upload/lib/fullpage/jquery.fullPage.css /root/web/lib/fullpage/jquery.fullPage.css
 
1
/root/upload/lib/fullpage/jquery.fullPage.min.js
===============1=========
#update
\cp -r  /root/upload/lib/fullpage/jquery.fullPage.min.js /root/web/lib/fullpage/jquery.fullPage.min.js
 
1
/root/upload/lib/layer/mobile/need/layer.css
===============1=========
#update
\cp -r  /root/upload/lib/layer/mobile/need/layer.css /root/web/lib/layer/mobile/need/layer.css
 
2
/root/upload/lib/layer/layer.js
==========2============
#update
/root/web/lib/layer/layer.js
\cp -r  /root/upload/lib/layer/layer.js /root/web/lib/layer/layer.js
 
/root/upload/lib/layer/mobile/layer.js
==========2============
#update
/root/web/lib/layer/mobile/layer.js
\cp -r  /root/upload/lib/layer/mobile/layer.js /root/web/lib/layer/mobile/layer.js
 
1
/root/upload/images/main/logo.png
===============1=========
#update
\cp -r  /root/upload/images/main/logo.png /root/web/images/main/logo.png
 
1
/root/upload/images/product/product_detail_bg.png
===============1=========
#update
\cp -r  /root/upload/images/product/product_detail_bg.png /root/web/images/product/product_detail_bg.png
 
1
/root/upload/images/main/qrcode.png
===============1=========
#update
\cp -r  /root/upload/images/main/qrcode.png /root/web/images/main/qrcode.png
 
1
/root/upload/images/product/security_guarantee.png
===============1=========
#update
\cp -r  /root/upload/images/product/security_guarantee.png /root/web/images/product/security_guarantee.pngurl

總結:

基本上能完成了增量更新,腳本是單線程,有待改進成多線程的!提升 更新速度。另外腳本對於新加的文件或者目錄沒有作到更新進去,有待改善。666加油。

相關文章
相關標籤/搜索