windows下Oracle增量备份脚本文件
windows下Oracle增量备份脚本文件
@set ORACLE_HOME=D:\oracle\product\10.2.0\db_1 @rem echo %ORACLE_HOME% @set ORACLE_SID=orcl @rem echo %ORACLE_SID% @set NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK @rem echo %NLS_LANG% @set PATH=%ORACLE_HOME%\bin @rem echo %PATH% @set RMAN=%ORACLE_HOME%\bin\rman.exe @rem *******************获取系统时间,截取yyyy-dd-mm ****************************** @rem*******************如果获取的时间不对,请修改系统时间格式 yyyy-mm-dd dddd***************************** @set MONTH=%date:~0,10% @set BACKUP_DIR=E:\BACKUP\%MONTH% @IF NOT EXIST %BACKUP_DIR% ( mkdir %BACKUP_DIR% ) @set RQ=%date:~0,10% @set RMAN_LOG_FILE=%BACKUP_DIR%\rman_%RQ%.log @rem echo %RMAN_LOG_FILE% @rem *******************连接rman 根据实际情况修改****************************** @set TARGET_CONNECT_STR=yk/yk@orcl @set DAY=%date:~12,13% @REM 0级备份就是进行全库备份,level 1就是备份level 0后改变的数据,level 2就是备份level 1或level 0后改变的数据 @REM 如果前一个备份是level 1那么就备份这之后修改的数据,如果前个备份是level 0那么就备份level 0后的数据 @echo ==== started on %DATE% ==== >>%RMAN_LOG_FILE% @set BACKUPTYPE=incremental level 2 database @set NAME=L2_%%d_%%T_%%s @if "%DAY%" EQU "一" ( set BACKUPTYPE=incremental level 2 database set NAME=F_%%d_%%T_%%s set ARCHIVE=L1_%%d_%%T ) @if "%DAY%" EQU "二" ( set BACKUPTYPE=incremental level 2 database set NAME=L1_%%d_%%T_%%s set ARCHIVE=L1_%%d_%%T ) @if "%DAY%" EQU "三" ( set BACKUPTYPE=incremental level 2 database set NAME=L1_%%d_%%T_%%s set ARCHIVE=L1_%%d_%%T ) @if "%DAY%" EQU "四" ( set BACKUPTYPE=incremental level 2 database set NAME=L1_%%d_%%T_%%s set ARCHIVE=L1_%%d_%%T ) @if "%DAY%" EQU "五" ( set BACKUPTYPE=incremental level 1 database set NAME=L1_%%d_%%T_%%s set ARCHIVE=L1_%%d_%%T ) @if "%DAY%" EQU "六" ( set BACKUPTYPE=incremental level 2 database set NAME=L1_%%d_%%T_%%s set ARCHIVE=L1_%%d_%%T ) @if "%DAY%" EQU "日" ( set BACKUPTYPE=incremental level 0 database set NAME=L1_%%d_%%T_%%s set ARCHIVE=L1_%%d_%%T ) @REM backup format 'e:\backup\dbL0_%d_%T.arc' archivelog all delete input; @rem echo backup %BACKUPTYPE% include current controlfile; @rem echo sql "ALTER SYSTEM ARCHIVE LOG CURRENT"; @( echo run { @rem 手动分配一个通道 目录: E:\BACKUP\yyyy-mm-dd echo allocate channel Channel1 type disk format '%BACKUP_DIR%\%NAME%'; @rem 备份数据库及控制文件 目录: E:\BACKUP\yyyy-mm-dd echo backup %BACKUPTYPE% include current controlfile; echo sql "ALTER SYSTEM ARCHIVE LOG CURRENT"; @rem 备份归档日志 目录: E:\BACKUP\yyyy-mm-dd echo backup format '%BACKUP_DIR%\%ARCHIVE%' archivelog all delete input; @rem 目录: E:\BACKUP\yyyy-mm-dd echo backup current controlfile format '%BACKUP_DIR%\ctl_%d_%T_%s'; @rem 释放通道 echo release channel Channel1; echo } ) | %RMAN% target %TARGET_CONNECT_STR% nocatalog msglog '%RMAN_LOG_FILE%' @set ERRLEVEL=%ERRORLEVEL% @if %ERRLEVEL% NEQ 0 @goto err @set LOGMSG="备份成功!!" @goto end :err @set LOGMSG="备份失败,请重试!!!" :end @echo # >> %RMAN_LOG_FILE% @echo ==== %LOGMSG% on %DATE% ==== >> %RMAN_LOG_FILE% @endlocal @REM End of Main Program -----------------------------------------------------