@echo off
REM ###########################################################
REM # Windows Server 2003下Oracle資料庫自動備份批處理指令碼
REM ###########################################################
REM 取當前系統時間,可能因作業系統不同而取值不一樣
set CURDATE=%date:~0,4%%date:~5,2%%date:~8,2%
set CURTIME=%time:~0,2%
REM 小時數如果小於10,則在前面補0
if "%CURTIME%"==" 0" set CURTIME=00
if "%CURTIME%"==" 1" set CURTIME=01
if "%CURTIME%"==" 2" set CURTIME=02
if "%CURTIME%"==" 3" set CURTIME=03
if "%CURTIME%"==" 4" set CURTIME=04
if "%CURTIME%"==" 5" set CURTIME=05
if "%CURTIME%"==" 6" set CURTIME=06
if "%CURTIME%"==" 7" set CURTIME=07
if "%CURTIME%"==" 8" set CURTIME=08
if "%CURTIME%"==" 9" set CURTIME=09
set CURTIME=%CURTIME%%time:~3,2%%time:~6,2%
REM 設定所有者、使用者名稱和密碼
set OWNER=OWNER
set USER=USER
set PASSWORD=PASSWORD
set PREFIX=OWNER
REM 建立備份用目錄,目錄結構為backup/YYYYMMDD/
if not exist "%CURDATE%" mkdir %CURDATE%
set CURDIR=%CURDATE%
set FILENAME=%CURDIR%/%PREFIX%_%CURDATE%_%CURTIME%.DMP
set EXPLOG=%CURDIR%/%PREFIX%_%CURDATE%_%CURTIME%_log.log
REM 調用ORACLE的exp命令匯出使用者資料
exp %USER%/%PASSWORD%@DEVDB file=%FILENAME% log=%EXPLOG% owner=%OWNER% grants=n
CD %CURDATE%
"C:/Program Files/WinRAR/WinRAR.exe" a -df %PREFIX%_%CURDATE%_%CURTIME%.rar * -r
exit