Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Windows教程綜合 >> 關於windows >> windows 下的定時備份實現教程

windows 下的定時備份實現教程

日期:2017/2/7 14:18:44      編輯:關於windows
 

backup.bat文件

rem 備份數據庫
echo start backup database at : %date% %time% >> backup.log (注:可以在DOS下用 echo %date% %time% 查看日期格式)
del E:\bak\xx%date:~0,4%%date:~5,2%%date:~8,2%.sql
mysqldump -uroot -proot -c --extended-insert --default-character-set=GB2312 -B xx> E:\bak\xx%date:~0,4%%date:~5,2%%date:~8,2%.sql
echo end backup database at : %date% %time% >> backup.log


rem 備份程序
echo start backup program at : %date% %time% >> backup.log
net stop tomcat >> backup.log
del E:\bak\xx_program%date:~0,4%%date:~5,2%%date:~8,2%.rar
C:\progra~1\winrar\winrar.exe a -r E:\bak\dxoa_program%date:~0,4%%date:~5,2%%date:~8,2%.rar D:\tomcat5\webapps\xx\ >> backup.log
copy jchatbox.ser D:\tomcat5\webapps\jchat\WEB-INF\conf\jchatbox.ser /y >> backup.log
net start tomcat >> backup.log
echo end backup program at : %date% %time% >> backup.log

 

得到前7天的日期

echo wscript.echo dateadd("d",-7,date) >%tmp%\tmp.vbs
for /f "tokens=1,2,3 delims=/- " %%i in ('cscript /nologo %tmp%\tmp.vbs') do set y=%%i
for /f "tokens=1,2,3 delims=/- " %%i in ('cscript /nologo %tmp%\tmp.vbs') do set m=%%j
for /f "tokens=1,2,3 delims=/- " %%i in ('cscript /nologo %tmp%\tmp.vbs') do set d=%%k
if %m% LSS 9 set m=0%m%
if %d% LSS 9 set d=0%d%
set deldate=%y%%m%%d%

rem 刪除7天前數據備份
echo start del E:\bak\xx%deldate%.sql at : %date% %time% >> backup.log
del E:\bak\xx%deldate%.sql >> backup.log
echo end del E:\bak\xx%deldate%.sql at : %date% %time% >> backup.log

rem 刪除7天前程序備份
echo start del E:\bak\xx_program%deldate%.rar at : %date% %time% >> backup.log
del E:\bak\xx_program%deldate%.rar >> backup.log
echo end del E:\bak\xx_program%deldate%.rar at : %date% %time% >> backup.log

Copyright © Windows教程網 All Rights Reserved