 |
|
Oracle rman backups from Windows Script
Oracle Database Tips by Donald Burleson |
Scheduling tasks such as an Oracle
rman backup can be challenging in a Windows environment without
a third-party approach such as SFU, JavaScript or Visual Basic.
It's tricky, but you can write old-fashioned DOS bat files, a
string of DOS prompt commands, to create an execute an Oracle
rman backup.
Also see these related
RMAN scripts.
Here is yet another RMAN script that will
monitor the progress of your RMAN script.
Example of RMAN shell
script.
Once tested, the bat file is
invoked with the Windows AT scheduling command.
Lets examine
an RMAN backup script. Note that we build the exp parfile
arguments into a DOS variable called %PARFILE%, just like you
can invoke Oracle directly from the DOS prompt: e.g.
rman target %DB_USERNAME%/%DB_PASSWORD%@%TNS_ALIAS%
Above, note that this is all on one
line, an important consideration when doing DOS bat file
scripting.
REM
+--------------------------------------------------------------------------+
REM | VALIDATE COMMAND-LINE
PARAMETERS |
REM
+--------------------------------------------------------------------------+
if (%1)==() goto USAGE
if (%2)==() goto USAGE
if (%3)==() goto USAGE
REM
+--------------------------------------------------------------------------+
REM | VALIDATE ENVIRONMENT VARIABLES
|
REM
+--------------------------------------------------------------------------+
REM set ORALOG=C:\oracle\custom\oracle\log
REM set ORATMP=C:\oracle\custom\oracle\temp
if (%ORALOG%)==() goto ENV_VARIABLES
if (%ORATMP%)==() goto ENV_VARIABLES
REM
+--------------------------------------------------------------------------+
REM | DECLARE ALL GLOBAL
VARIABLES. |
REM
+--------------------------------------------------------------------------+
set FILENAME=rman_backup_hot_full_9i
set DB_USERNAME=%1%
set DB_PASSWORD=%2%
set TNS_ALIAS=%3%
set CMDFILE=%ORATMP%\%FILENAME%_%TNS_ALIAS%.rcv
set LOGFILE=%ORALOG%\%FILENAME%_%TNS_ALIAS%.log
REM
+--------------------------------------------------------------------------+
REM | REMOVE OLD LOG AND RMAN COMMAND
FILES. |
REM
+--------------------------------------------------------------------------+
del /q %CMDFILE%
del /q %LOGFILE%
REM
+--------------------------------------------------------------------------+
REM | WRITE RMAN COMMAND
SCRIPT. |
REM
+--------------------------------------------------------------------------+
echo backup database plus archivelog delete input; > %CMDFILE%
REM echo crosscheck backup of database; >> %CMDFILE%
REM echo crosscheck backup of controlfile; >> %CMDFILE%
REM echo crosscheck archivelog all; >> %CMDFILE%
echo delete noprompt force obsolete;>> %CMDFILE%
REM echo delete force noprompt expired backup of database; >> %CMDFILE%
REM echo delete force noprompt expired backup of controlfile; >>
%CMDFILE%
REM echo delete force noprompt expired archivelog all; >> %CMDFILE%
echo exit; >> %CMDFILE%
REM
+--------------------------------------------------------------------------+
REM | PERFORM RMAN
BACKUP. |
REM
+--------------------------------------------------------------------------+
rman target %DB_USERNAME%/%DB_PASSWORD%@%TNS_ALIAS% nocatalog
cmdfile=%CMDFILE% msglog %LOGFILE%
REM
+--------------------------------------------------------------------------+
REM | SCAN THE RMAN LOGFILE FOR
ERRORS. |
REM
+--------------------------------------------------------------------------+
findstr /i "error" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo WARNING %FILENAME% %TNS_ALIAS%
%COMPUTERNAME% %DATE% %TIME% %LOGFILE%
echo ...
echo END OF FILE REPORT
echo Filename : %FILENAME%
echo Database : %TNS_ALIAS%
echo Hostname : %COMPUTERNAME%
echo Date : %DATE%
echo Time : %TIME%
echo RMAN Log File : %LOGFILE%
REM
+--------------------------------------------------------------------------+
REM | END THIS SCRIPT.
|
REM
+--------------------------------------------------------------------------+
goto END
REM
+==========================================================================+
REM | *** END OF SCRIPT
*** |
REM
+==========================================================================+
REM
+--------------------------------------------------------------------------+
REM | LABEL DECLARATION SECTION.
|
REM
+--------------------------------------------------------------------------+
:USAGE
echo Usage: rman_backup_hot_full_9i.bat DBA_USERNAME
DBA_PASSWORD TNS_ALIAS
echo DBA_USERNAME = Oracle DBA Username - (Requires
SYSDBA Role)
echo DBA_PASSWORD = Oracle DBA Password
echo TNS_ALIAS = Connect String to connect to the
database (ex. ORCL)
goto END
:ENV_VARIABLES
echo ERROR: You must set the following environment variables
before
echo running this script:
echo ORALOG = Directory used to write logfile
to
echo ORATMP = Directory used to write
temporary files to
goto END
:END
@echo on
|
 |
|
Windows for the Oracle DBA
The landmark book
Windows for the Oracle DBA is a comprehensive overview of
everything an Oracle DBA needs to know to manage Oracle on
Windows. Order directly from Rampant and save 30%.
|
|
|