ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ORACLE备份脚本

ORACLE备份脚本

原创 Linux操作系统 作者:sxzhanghl 时间:2009-05-06 17:50:29 0 删除 编辑

@set ORACLE_HOME=d:\oracle\ora92
@rem echo %ORACLE_HOME%
@set ORACLE_SID=dw
@rem echo %ORACLE_SID%
@set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
@rem echo %NLS_LANG%
@set PATH=%ORACLE_HOME%\bin
@rem echo %PATH%


@set RMAN=%ORACLE_HOME%\bin\rman.exe
@set MONTH=%date:~4,7%
@set BACKUP_DIR=D:\BACKUP\%MONTH%
@IF NOT EXIST %BACKUP_DIR% (
mkdir %BACKUP_DIR%
)


@set RQ=%date:~4,10%
@set RMAN_LOG_FILE=%BACKUP_DIR%\rman_%RQ%.log
@rem echo %RMAN_LOG_FILE%
@set
TARGET_CONNECT_STR=sys/sys@dw

@set DAY=%date:~12,2%


@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 "05" (
set BACKUPTYPE=incremental level 1 database
set NAME=L1_%%d_%%T_%%s
set ARCHIVE=L1_%%d_%%T
)

@if "%DAY%" EQU "10" (
set BACKUPTYPE=incremental level 1 database
set NAME=L1_%%d_%%T_%%s
set ARCHIVE=L1_%%d_%%T
)

@if "%DAY%" EQU "15" (
set BACKUPTYPE=incremental level 1 database
set NAME=L1_%%d_%%T_%%s
set ARCHIVE=L1_%%d_%%T
)

@if "%DAY%" EQU "20" (
set BACKUPTYPE=incremental level 1 database
set NAME=L1_%%d_%%T_%%s
set ARCHIVE=L1_%%d_%%T
)

@if "%DAY%" EQU "25" (
set BACKUPTYPE=incremental level 1 database
set NAME=L1_%%d_%%T_%%s
set ARCHIVE=L1_%%d_%%T
)

@if "%DAY%" EQU "01" (
set BACKUPTYPE=incremental level 0 database
set NAME=F_%%d_%%T_%%s
set ARCHIVE=L1_%%d_%%T
)

@REM backup format 'd:\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 {
echo allocate channel Channel1 type disk format '%BACKUP_DIR%\%NAME%';
echo backup %BACKUPTYPE% include current controlfile;
echo sql "ALTER SYSTEM ARCHIVE LOG CURRENT";
echo backup format '%BACKUP_DIR%\%ARCHIVE%' archivelog all delete input;
echo backup current controlfile format '%BACKUP_DIR%\ctl_%d_%T_%s';
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 -----------------------------------------------------

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/730796/viewspace-594353/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-03-19

  • 博文量
    31
  • 访问量
    58797