on Windows 2008。

backup.bat
@echo off

@rem =========================================
@rem Author: flyfox 20121105
@rem 使用需知
@rem 1. 需安裝 IIS 7
@rem 2. 需安裝 7-zip
@rem 3. IIS 備份檔位於 D:\Backup\
@rem =========================================

@rem =========================================
@rem 設定各路徑變數
@rem =========================================
@set SDir=C:\Windows\System32\inetsrv\
@set DDir=D:\Backup\
@set zip="C:\Program Files\7-Zip\7z.exe"
@set pi=C:\WINDOWS\system32\ping.exe
@set batlog=D:\bat\log
@set appcmd=%SDir%appcmd.exe
@md %DDir%
@md %batlog%

@rem =========================================
@rem 設定備份檔名稱、log檔名稱
@rem =========================================
@set file=%computername%
@set zipfile=%computername%-iisbackup-%date:~0,4%%date:~5,2%%date:~8,2%.7z
@set log=D:\bat\log\log-%date:~0,4%%date:~5,2%%date:~8,2%-%time:~0,2%%time:~3,2%%time:~6,2%.txt
@set log=%log: =0%

@rem =========================================
@rem 備份 IIS 設定檔
@rem =========================================
@echo ================ start ================== > %log%
@echo Date: %date% Time: %time% >> %log%
@cd %SDir% >> %log%
@if exist %SDir%backup\%file% (rd /S /Q %SDir%backup\%file% && echo rd IIS old backup >> %log%)
@%appcmd% add backup %file% >> %log%
@echo IIS Backup Success. >> %log%

:compress
@rem =========================================
@rem 設定壓縮 IIS 備份檔
@rem =========================================
@if exist %DDir%%zipfile% (del /F /S /Q %DDir%%zipfile%)
@if exist %SDir%backup\%file% (%zip% a -mmt=4 -mx=9 %DDir%%zipfile% -mhe %SDir%backup\%file% && echo. >> %log%) else (goto nofile)
@echo Compress Success! >> %log%
@%pi% 127.1 -n 3 -w 1000 > nul
@start D:\bat\SendIISConfig.exe >> %log%
@goto close

:nofile
@rem =========================================
@rem 找不到 IIS 備份檔
@rem =========================================
@echo can not find IIS config file! >> %log%
@forfiles /P noxml /S /M *.* /D -30 /C "cmd /c del @path"
@exit
@echo on

:close
@exit
@echo on

flyfox 發表在 痞客邦 PIXNET 留言(0) 人氣()