Rman Backup script on Windows

Hello,

Here’s a script I created recently to backup a database under Windows with RMAN.

Hope you enjoy it.

Pierre

The script takes 4 parameters:

  • Target Database Sid
  • Rman Database Sid
  • Rman Database Password
  • Level of Rman backup

—–  Begin Script —–

SET ORACLE_HOME=E:\ORACLEORA10G
SET ORACLE_SID=%1%
SET RMAN_DB=%2%
SET CATALOG_PASS=%3%
SET LEVELBCK=%4%
SET CATALOG_PASS=rman/%CATALOG_PASS%@%RMAN_DB%
SET RMAN_DEST=K:\SAUVEGARDESRMAN%ORACLE_SID%
SET LOG_DEST=K:\SAUVEGARDESLOGS
SET NLS_LANG=AMERICAN_AMERICA.UTF8
SET TMPDIR=E:\ORACLETEMPSCRIPTS

@echo on

cd %TMPDIR%

REM This bit generates the RMAN script to backup database,
REM archivelogs and control file and then crosscheck output.
echo run { > rman_%ORACLE_SID%.rcv
echo allocate channel d1 type disk; >> rman_%ORACLE_SID%.rcv
echo allocate channel d2 type disk; >> rman_%ORACLE_SID%.rcv
echo allocate channel d3 type disk; >> rman_%ORACLE_SID%.rcv
echo backup incremental level %LEVELBCK% format
‘%RMAN_DEST%DBF_%ORACLE_SID%_t%%t_s%%s_p%%p.db’
database;>>rman_%ORACLE_SID%.rcv
echo sql ‘alter system archive log current’; >>rman_%ORACLE_SID%.rcv
echo backup archivelog all format
‘%RMAN_DEST%ARC_%ORACLE_SID%_t%%t_s%%s_p%%p.arc’;>>rman_%ORACLE_SID%.rcv
echo backup current controlfile format
‘%RMAN_DEST%CTL_%ORACLE_SID%_t%%t_s%%s_p%%p.ctl’;>>rman_%ORACLE_SID%.rcv
echo release channel d1; >> rman_%ORACLE_SID%.rcv
echo release channel d2; >> rman_%ORACLE_SID%.rcv
echo release channel d3; >> rman_%ORACLE_SID%.rcv
echo } >> rman_%ORACLE_SID%.rcv
echo allocate channel for maintenance type disk; >> rman_%ORACLE_SID%.rcv
echo sql ‘alter system archive log current’; >> rman_%ORACLE_SID%.rcv
echo crosscheck backup; >> rman_%ORACLE_SID%.rcv
echo crosscheck backup of archivelog all; >> rman_%ORACLE_SID%.rcv
echo crosscheck backup of controlfile; >> rman_%ORACLE_SID%.rcv
echo release channel; >> rman_%ORACLE_SID%.rcv
echo exit >> rman_%ORACLE_SID%.rcv

REM This starts RMAN, executes the script created earlier, then exits and
tidies up.
cd %RMAN_DEST%
if %LEVELBCK%==1 goto INCR
if %LEVELBCK%==0 goto FULL

:FULL
del %RMAN_DEST%*.* /q
rman target / catalog=%CATALOG_PASS% cmdfile=%TMPDIR%rman_%ORACLE_SID%.rcv
msglog=%LOG_DEST%rman_%ORACLE_SID%.log
del %TMPDIR%rman_%ORACLE_SID%.rcv
goto END
:INCR
rman target / catalog=%CATALOG_PASS% cmdfile=%TMPDIR%rman_%ORACLE_SID%.rcv
msglog=%LOG_DEST%rman_%ORACLE_SID%.log
del %TMPDIR%rman_%ORACLE_SID%.rcv
:END

—- end script —-

Advertisements