troubleshooting Question

How to execute RMAN backup windows script w/out passwords and other variables made visable?

Avatar of 7Souls
7SoulsFlag for United States of America asked on
Microsoft DOSOracle DatabaseWindows Server 2003
20 Comments2 Solutions5046 ViewsLast Modified:
Hi, I have a windows .bat file that I would like to schedule in a .cmd file where I can execute the .bat file and not have to show the variables for the user and password. When I access RMAN. The command that I used for testing is:

rman_backup_hot_full_10g.bat  "DBA_USERNAME"  "DBA_PASSWORD" "TNS_ALIAS"

where the variables in the quotes are the actual variables that I need to hide when I schedule this script.

Here is a copy of the script:

@echo off
REM | FILE       : rman_backup_hot_full_10g.bat modified 07/14/2011            |
REM | CLASS      : WINDOWS Shell Scripts                                       |
REM | PURPOSE    : Used to perform a physical backup of an Oracle database     |
REM |              using RMAN. This script uses the database control file as   |
REM |              the RMAN repository. A command script will be dynamically   |
REM |              written to a temporary directory and run through RMAN.      |
REM |                                                                          |
REM | PARAMETERS : DBA_USERNAME       Database username RMAN will use to login |
REM |                                 to the database. This user must have     |
REM |                                 the SYSDBA role.                         |
REM |              DBA_PASSWORD       Database password RMAN will use to login |
REM |                                 to the database.                         |
REM |              TNS_ALIAS          TNS connect string to the target         |
REM |                                 database.                                |
REM | USAGE      :                                                             |
REM |                                                                          |
REM | rman_backup_hot_full_10g.bat  "DBA_USERNAME"  "DBA_PASSWORD" "TNS_ALIAS" |
REM |                                                                          |
REM | NOTE       : As with any code, ensure to test this script in a           |
REM |              development environment.                                    |
REM |                                                                          |
REM +--------------------------------------------------------------------------+

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 +--------------------------------------------------------------------------+

set ORALOG=X:\rman\logs
set ORATMP=X:\rman\temp

if (%ORALOG%)==() goto ENV_VARIABLES
if (%ORATMP%)==() goto ENV_VARIABLES


REM +--------------------------------------------------------------------------+
REM | DECLARE ALL GLOBAL VARIABLES.                                            |
REM +--------------------------------------------------------------------------+

set FILENAME=rman_backup_hot_full_10g
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.
echo run { > %CMDFILE%  
echo.                    
echo sql "alter system archive log current"; >> %CMDFILE%
echo.     >> %CMDFILE%              
echo CONFIGURE CONTROLFILE AUTOBACKUP ON; >> %CMDFILE%
echo.     >> %CMDFILE%
echo backup database >> %CMDFILE%
REM echo filesperset 5 >> %CMDFILE%    
REM echo format 'X:\rman\BACKUPSET\ora_df%%t_s%%s_s%%p' >> %CMDFILE%  
echo (database include current controlfile); >> %CMDFILE%  
echo.    >> %CMDFILE%
echo backup archivelog all >> %CMDFILE%  
echo format 'X:\rman\\ARCHIVE\log_%%t_%%s_%%r.arc'; >> %CMDFILE%  
echo.    >> %CMDFILE%
echo   } >> %CMDFILE%    
echo.    >> %CMDFILE%
echo.    >> %CMDFILE%                
echo.    >> %CMDFILE%
echo show all; >> %CMDFILE%  
echo.          >> %CMDFILE%
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%
REM 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 +--------------------------------------------------------------------------+

find /i "error" "%LOGFILE%"
if %errorlevel% EQU 1 (
"C:\WINDOWS\sendmail\sendmail.exe" -messagefile=X:\somedirectorypath\logs\rman_backup_hot_full_10g.log -subject="RMAN Online Backup was Successful" email1@domain
) else (
"C:\WINDOWS\sendmail\sendmail.exe" -messagefile=X:\somedirectorypath\logs\rman_backup_hot_full_10g.log -subject="RMAN Online Backup Failed" email1@domain
)

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

:END
@echo on
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 20 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros