1. 程式人生 > >windows tomcat專案更新及資料庫備份指令碼

windows tomcat專案更新及資料庫備份指令碼

本人使用的是批處理,即用cmd執行的,如果用powershell執行可能會有問題

我的是安裝版的tomcat,tomcat已安裝成服務

自動更新專案並部署,刪除本月之前的備份資料

rem *******************************Code Start*****************************
@echo off

set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"
cp "D:\Apache Software Foundation\Tomcat 7.0\webapps\cloudolp.dc.war" D:\backup\cloudolp.dc\%Ymd%.war
cd "D:\project\Cloudolp.dc"
git pull
grails war
net stop Tomcat7

rmdir /s/q "D:\Apache Software Foundation\Tomcat 7.0\webapps\cloudolp.dc"

net start Tomcat7
set "firstDate=%date:~,4%/%date:~5,2%/01"
forfiles /P D:\backup\cloudolp.dc /D  -%firstDate% /C "cmd /c del /f @path"
@echo on 
rem *******************************Code End*****************************

備份資料庫,刪除本月之前的備份資料
rem *******************************Code Start*****************************
@echo off

set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"
mysqldump --opt -u root --default-character-set=utf8 --password=xxoo datacenter > D:\backup\datacenter\%Ymd%.sql
set "firstDate=%date:~,4%/%date:~5,2%/01"
forfiles /P D:\backup\datacenter /D  -%firstDate% /C "cmd /c del /f @path"
@echo on
rem *******************************Code End*****************************