@Echo off
REM File: Orabkup.BAT
REM Author: Rauf.Sarwar@ifsna.com
REM Platform: WindowsNT/2000
REM Oracle Ver: 7.3.4.x, 8.0.x, 8.1.x
REM Limitations:
REM 1) NTBackup does not recognize UNC names e.g. \\<YourServer>. Workaround: Map the drive
REM 2) NTBackup does not like spaces in names e.g. C:\Program Files. Workaround: Use 8dot3 C:\Progra~1
REM names instead. To get 8dot3names of a file or folder run dir /x from command line.
REM 3) Using batch file, Cannot backup individual files, can only backup directories.
REM *** Script will copy P-File over to datafile folder before backup. ***
REM 4) Script designed for Databases where DB files are NOT distributed over the network.
REM Although; it can be modified to work for that environment.
REM To get a list of NTBackup limitations, goto
www.microsoft.com and search for NTBackup
REM Can schedule to backup multiple databases using the same script. Just modify the Editable section.
REM To schedule this file use following command from command line. e.g. Run every night at 11:00pm
REM AT \\<ServerName> 23:00 /interactive /every:m,t,w,th,f,s,su FullPath\Orabkup.BAT
REM ***** EDITABLE (REPLACE null WITH YOUR VALUES) ELSE..LEAVE VALUE AS null IF NOT USED ******
REM DO NOT USE SLASHES AT THE END OF PATHS e.g. Correct: D:\Orant\Prod Incorrect: D:\Orant\Prod\
REM DB_SID=<Database SID to backup e.g. PROD>
set DB_SID=null
REM DATAFILE=<DataFile Path e.g. D:\Oradbf\PROD>
set DATAFILE=null
REM PFILE=<P-File path e.g. D:\Orant\Database\initPROD.ORA>
set PFILE=null
REM LOGFILE=<LogFile with full Path e.g. D:\LogFiles\PRODLog.log>
set LOGFILE=null
REM TAPE=<Tape number (Check this from control panel -> Tape Devices e.g. 0)>
set TAPE=null
REM APPEND=<Append to last backup on the tape or not. Valid values: Y for Yes or N for No, Default is Y>
set APPEND=null
REM SVRMGR=<Server manager according to the version e.g. Ver7.x=SVRMGR23 or Ver8.0.x=SVRMGR30 or Ver8.1.x=SVRMGRL>
set SVRMGR=null
REM SVRMGRPWD=<Server Manager internal password e.g. manager>
set SVRMGRPWD=null
REM ARCHLOG=<Archive log file path or else leave it as null if in datafile folder e.g. D:\Orant\PROD\LogFiles>
set ARCHLOG=null
REM CTLFILE=<Control File path or else leave it as null if in datafile folder e.g. D:\Orant\PROD\CtlFiles>
set CTLFILE=null
REM ***** NOT EDITABLE ******
if %DB_SID%==null set STR_VAL=%DB_SID%&set STR_NAME=DB_SID&goto ERROR_
if not exist %DATAFILE%\nul set STR_VAL=%DATAFILE%&set STR_NAME=DATAFILE&goto ERROR_
if not exist %PFILE% set STR_VAL=%PFILE%&set STR_NAME=PFILE&goto ERROR_
if %LOGFILE%==null set STR_VAL=%LOGFILE%&set STR_NAME=LOGFILE&goto ERROR_
if %TAPE%==null set STR_VAL=%TAPE%&set STR_NAME=TAPE&goto ERROR_
if %APPEND%==null set APPEND=Y
if %SVRMGR%==null set STR_VAL=%SVRMGR%&set STR_NAME=SVRMGR&goto ERROR_
if %SVRMGRPWD%==null set STR_VAL=%SVRMGRPWD%&set STR_NAME=SVRMGRPWD&goto ERROR_
if %ARCHLOG%==null goto CONTINUE1
if not exist %ARCHLOG%\nul set STR_VAL=%ARCHLOG%&set STR_NAME=ARCHLOG&goto ERROR_
:CONTINUE1
if %CTLFILE%==null goto CONTINUE2
if not exist %CTLFILE%\nul set STR_VAL=%CTLFILE%&set STR_NAME=CTLFILE&goto ERROR_
:CONTINUE2
REM ***** CREATE TEMP SQL FILES FOR SERVER MANAGER ******
SET ShutDownFile=C:\ShutDown__.SQL
echo connect internal/%SVRMGRPWD% > %ShutDownFile%
echo shutdown immediate >> %ShutDownFile%
echo startup >> %ShutDownFile%
echo shutdown normal >> %ShutDownFile%
echo EXIT >> %ShutDownFile%
SET StartUpFile=C:\Startup__.SQL
echo connect internal/%SVRMGRPWD% > %StartUpFile%
echo startup >> %StartUpFile%
echo EXIT >> %StartUpFile%
REM ***** SHUTDOWN THE DATABASE *******
SET oracle_sid=%DB_SID%
%SVRMGR% @%ShutDownFile%
REM Check for Oracle 8i Rel 8.1.x. NT does not stop the service even after a shutdown from Server manager.
REM Just stop the service to be used later to restart the database from the service
if not %SVRMGR%==SVRMGRL NET STOP OracleStart%DB_SID%
NET STOP OracleService%DB_SID%
REM *** COPY P-FILE OVER TO DATAFILE FOLDER (CANNOT BACKUP INDIVIDUAL FILES FROM BATCH SCRIPT) ***
echo Copying %PFILE% over to %DATAFILE%
xcopy %PFILE% %DATAFILE% /Q
if errorlevel 4 set PFILEERR=Yes
REM ******* START BACKUP *********
if %APPEND%==N NTBACKUP BACKUP %DATAFILE% /d "%DB_SID% Backup" /b /hc:on /l "%LOGFILE%" /tape:%TAPE%
if %APPEND%==Y NTBACKUP BACKUP %DATAFILE% /a /d "%DB_SID% Backup" /b /hc:on /l "%LOGFILE%" /tape:%TAPE%
if %ARCHLOG%==null echo ARCHLOG folder not specified for backup&goto CONTINUE3
NTBACKUP BACKUP %ARCHLOG% /a /d "%ARCHLOG% Backup" /b /hc:on /l "%LOGFILE%" /tape:%TAPE%
:CONTINUE3
if %CTLFILE%==null echo CTLFILE folder not specified for backup&goto CONTINUE4
NTBACKUP BACKUP %CTLFILE% /a /d "%CTLFILE% Backup" /b /hc:on /l "%LOGFILE%" /tape:%TAPE%
:CONTINUE4
REM ******** START UP ORACLE SERVICE AND DATABASE *******
NET START OracleService%DB_SID%
%SVRMGR% @%StartUpFile%
if not %SVRMGR%==SVRMGRL NET START OracleStart%DB_SID%
REM ********* DELETE TEMP FILES **********
if exist %ShutDownFile% DEL /Q %ShutDownFile%
if exist %StartUpFile% DEL /Q %StartUpFile%
REM Delete p-file from Datafile folder after the backup
if exist %DATAFILE%\%PFILE% DEL /Q %DATAFILE%\%PFILE%
goto SUCCESS
:ERROR_
echo Error: Check the value (%STR_VAL%) for (%STR_NAME%) in the editable section and run again&goto END
:SUCCESS
echo Backup was successfull.
if %PFILEERR%==Yes echo Note: %PFILE% not included in backup.
if %PFILEERR%==Yes echo Reason: Cannot copy %PFILE% to %DATAFILE% due to low memory or invalid filename
:END