从网上找了些资料,整理了下oracle的自动备份批处理,将以下的代码保存为.bat即可,再配合windows的计划任务可实现自动备份数据库并压缩功能,并指定删除7天前的备份文件(修改delDays参数)。在windows 2003/2008环境下,利用其forfiles工具进行辅助删除功能。?? 希望对大家有用!
@ echo ------ORACLE自动备份开始... Zhang Junming制作 @2012-----------REM ======================================================REM 备份服务器 SZYY系统的数据REM ======================================================@ echo offset BACKUP_DIR=e:\DATABACKUPset BACKUP_WAREHOUSE=e:\DATABACKUP\DATABACKUP_LOG_DMPset ORACLE_USERNAME=zjmset ORACLE_PASSWORD=zjm123set ORACLE_DB=orclset IP=192.168.5.100set RAR_CMD="C:\Program Files\WinRAR\WinRAR.exe"set delDays=7if not exist "DATABACKUP" md DATABACKUPif not exist "DATABACKUP\DATABACKUP_LOG_DMP\" md DATABACKUP\DATABACKUP_LOG_DMP\for /f "tokens=1,2" %%a in ('date/t') do set TODAY=%%aREM 如果文件名中需要小时及分钟,用下面第一行语句REM set BACK_NAME=%ORACLE_DB%_%ORACLE_USERNAME%_%TODAY%(%time:~0,2%时%time:~3,2%分%time:~6,2%秒)REM set BACK_NAME=%ORACLE_DB%_%ORACLE_USERNAME%_%TODAY%REM set BACK_NAME=%ORACLE_DB%_%TODAY%_%time:~0,2%时%time:~3,2%分%time:~6,2%秒set BACK_NAME=%ORACLE_DB%_%TODAY%set BACK_FULL_NAME=%BACKUP_DIR%\%BACK_NAME%REM 将操作记入批处理日志 %BACK_FULL_NAME%_bat.logecho ==================备份服务器 SZYY的数据================= >>%BACK_FULL_NAME%_bat.logecho 备份开始...... >>%BACK_FULL_NAME%_bat.log echo 开始的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.logREM 调用exp工具rem %ORACLE_USERNAME%/%ORACLE_PASSWORD%@%IP%/%ORACLE_DB% grants=Y exp %ORACLE_USERNAME%/%ORACLE_PASSWORD%@%IP%/%ORACLE_DB% grants=Y file="%BACK_FULL_NAME%.dmp"rem log="%BACK_FULL_NAME%_exp.log"if not exist %BACKUP_WAREHOUSE%\DMP md %BACKUP_WAREHOUSE%\DMPecho 压缩并删除原有dmp文件...... >>%BACK_FULL_NAME%_bat.logecho 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log%RAR_CMD% a -df "%BACK_FULL_NAME%_dmp.rar" "%BACK_FULL_NAME%.dmp"echo rar压缩==> %BACK_FULL_NAME%_dmp.rar>>%BACK_FULL_NAME%_bat.logREM "%BACK_FULL_NAME%exp.log"echo 压缩并删除原有dmp文件结束! >>%BACK_FULL_NAME%_bat.logecho 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.logecho 开始移动压缩后的备份文件...... >>%BACK_FULL_NAME%_bat.logecho 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.logmove %BACKUP_DIR%\*.rar %BACKUP_WAREHOUSE%\DMP\echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.logREM net send %userdomain% "数据库逻辑备份已于:%DATE% %time% 完成!"echo .echo 备份完成!!! >>%BACK_FULL_NAME%_bat.logecho 完成的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.logecho ===============备份服务器 SZYY的数据完成!!!============== >>%BACK_FULL_NAME%_bat.logif not exist %BACKUP_WAREHOUSE%\%BACK_NAME%_LOG md %BACKUP_WAREHOUSE%\LOGmove %BACKUP_DIR%\*.log %BACKUP_WAREHOUSE%\LOG\rem 删除七天前的rar备份文件forfiles /p %BACKUP_WAREHOUSE%\DMP /s /m *.rar /d -%delDays% /c "cmd /c del @file"echo .
?