windows 全量+增量备份脚本bat

发布时间:2020-08-10 11:21:21 作者:abin1703
来源:ITPUB博客 阅读:279

@set ORACLE_HOME=D:\app\Administrator\product\11.2.0\dbhome_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*****************************

@rem MONTH=%date:~0,10%

@set MONTH=%date:~0,4%%date:~5,2%%date:~8,2%

@set BACKUP_DIR=C:\%MONTH%

@IF NOT EXIST %BACKUP_DIR% (

mkdir %BACKUP_DIR%

)

@set RQ=%date:~0,4%%date:~5,2%%date:~8,2%

@set RMAN_LOG_FILE=%BACKUP_DIR%\rman_%RQ%.log

@rem echo %RMAN_LOG_FILE%

@rem *******************连接rman 根据实际情况修改******************************

@rem TARGET_CONNECT_STR=/

@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_%%U

@if "%DAY%" EQU "一" (

set BACKUPTYPE=incremental level 2 database

set NAME=inc2_%%d_%%T_%%s_%%U

set ARCHIVE=arch3_%%d_%%T_%%U

)

@if "%DAY%" EQU "二" (

set BACKUPTYPE=incremental level 2 database

set NAME=inc2_%%d_%%T_%%s_%%U

set ARCHIVE=arch3_%%d_%%T_%%U

)

@if "%DAY%" EQU "三" (

set BACKUPTYPE=incremental level 1 database

set NAME=inc1_%%d_%%T_%%s_%%U

set ARCHIVE=arch2_%%d_%%T_%%U

)

@if "%DAY%" EQU "四" (

set BACKUPTYPE=incremental level 2 database

set NAME=inc2_%%d_%%T_%%s_%%U

set ARCHIVE=arch3_%%d_%%T_%%U

)

@if "%DAY%" EQU "五" (

set BACKUPTYPE=incremental level 2 database

set NAME=inc2_%%d_%%T_%%s_%%U

set ARCHIVE=arch3_%%d_%%T_%%U

)

@if "%DAY%" EQU "六" (

set BACKUPTYPE=incremental level 2 database

set NAME=inc2_%%d_%%T_%%s_%%U

set ARCHIVE=arch3_%%d_%%T_%%U

)

@if "%DAY%" EQU "日" (

set BACKUPTYPE=incremental level 0 database

set NAME=full0_%%d_%%T_%%s_%%U

set ARCHIVE=arch0_%%d_%%T_%%U

)

@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 {

echo allocate channel Channel1 type disk format '%BACKUP_DIR%\%NAME%';

echo allocate channel Channel2 type disk format '%BACKUP_DIR%\%NAME%';

echo allocate channel Channel3 type disk format '%BACKUP_DIR%\%NAME%';

echo allocate channel Channel4 type disk format '%BACKUP_DIR%\%NAME%';

echo backup section size 4G filesperset 1 %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_%%U';

echo }

) | %RMAN% target / 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 -----------------------------------------------------

推荐阅读:
  1. Windows下bat脚本
  2. windows的3个小脚本

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

bat windows 全量

上一篇:Maven项目继承实现过程的案例分析

下一篇:功能测试与性能测试有什么区别

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》