@REM $Header: cold_database_backup.cmd,v 1.1 2002/05/28 13:52:48 $ @REM bcpyrght @REM *************************************************************************** @REM * $VRTScprght: Copyright 1993 - 2006 Symantec Corporation, All Rights Reserved $ * @REM *************************************************************************** @REM ecpyrght @REM --------------------------------------------------------------------------- @REM cold_database_backup.cmd @REM --------------------------------------------------------------------------- @REM This script uses Recovery Manager to take a cold (consistent) database @REM backup. A cold backup is one where the database is shutdown cleanly before @REM performing the backup. @REM --------------------------------------------------------------------------- @setlocal ENABLEEXTENSIONS @REM --------------------------------------------------------------------------- @REM No need to echo the commands. @REM --------------------------------------------------------------------------- @echo off @REM --------------------------------------------------------------------------- @REM Put output in the same filename, different extension. @REM --------------------------------------------------------------------------- @set RMAN_LOG_FILE="%~dpn0.out" @REM --------------------------------------------------------------------------- @REM You may want to delete the previous output file so that backup information @REM does not accumulate. If not, delete the following command. @REM --------------------------------------------------------------------------- @if exist %RMAN_LOG_FILE% del %RMAN_LOG_FILE% @REM --------------------------------------------------------------------------- @REM Log the start of this script. @REM --------------------------------------------------------------------------- @for /F "tokens=1*" %%p in ('date /T') do @set DATE=%%p %%q @for /F %%p in ('time /T') do @set DATE=%DATE% %%p @echo ==== started on %DATE% ==== >> %RMAN_LOG_FILE% @echo Script name: %0 >> %RMAN_LOG_FILE% @REM --------------------------------------------------------------------------- @REM Replace H:\oracle\ora81, below, with the Oracle home path. @REM --------------------------------------------------------------------------- @set ORACLE_HOME=D:\oracle\product\10.2.0\db_1 @REM --------------------------------------------------------------------------- @REM Replace ora81, below, with the Oracle SID of the target database. @REM --------------------------------------------------------------------------- @set ORACLE_SID=NTHEPROD @REM --------------------------------------------------------------------------- @REM Several RMAN commands use time parameters that require NLS_LANG and @REM NLS_DATE_FORMAT to be set. This example uses the standard date format. @REM Replace below with the desired language values. @REM --------------------------------------------------------------------------- @set NLS_LANG=american @set NLS_DATE_FORMAT=YYYY-MM-DD:hh24:mi:ss @REM --------------------------------------------------------------------------- @REM Replace the following with the fully qualified path name of the init file @REM for the target database. @REM --------------------------------------------------------------------------- @set TARGET_INIT_FILE=D:\oracle\product\10.2.0\admin\NTHEPROD\pfile\init.ora.072009132344 @REM --------------------------------------------------------------------------- @REM Replace productionDB, below, with the target database TNS alias (service) @REM name from the tnsnames.ora file. @REM --------------------------------------------------------------------------- @set TARGET_TNS=NTHEPROD.WROLD @REM --------------------------------------------------------------------------- @REM Replace sqlplus with the appropriate Oracle utility call. @REM For example, replace "sqlplus.exe /nolog" with svrmgrl.exe @REM --------------------------------------------------------------------------- @set CMD=%ORACLE_HOME%\bin\sqlplus.exe /nolog @REM --------------------------------------------------------------------------- @REM Replace sys/manager, below, with the target connect string. @REM --------------------------------------------------------------------------- @set TARGET_CONNECT_STR=sys/nukesh @REM --------------------------------------------------------------------------- @REM Oracle Recovery Manager name. @REM --------------------------------------------------------------------------- @set RMAN=%ORACLE_HOME%\bin\rman.exe @REM --------------------------------------------------------------------------- @REM Print out the value of the variables set by this script. @REM --------------------------------------------------------------------------- @echo # >> %RMAN_LOG_FILE% @echo TARGET_INIT_FILE: %TARGET_INIT_FILE% >> %RMAN_LOG_FILE% @echo RMAN: %RMAN% >> %RMAN_LOG_FILE% @echo CMD: %CMD% >> %RMAN_LOG_FILE% @echo NLS_LANG : %NLS_LANG% >> %RMAN_LOG_FILE% @echo ORACLE_SID : %ORACLE_SID% >> %RMAN_LOG_FILE% @echo ORACLE_HOME: %ORACLE_HOME% >> %RMAN_LOG_FILE% @echo NLS_DATE_FORMAT : %NLS_DATE_FORMAT% >> %RMAN_LOG_FILE% @REM --------------------------------------------------------------------------- @REM Print out the value of the variables set by bphdb. @REM --------------------------------------------------------------------------- @echo NB_ORA_FULL: %NB_ORA_FULL% >> %RMAN_LOG_FILE% @echo NB_ORA_INCR: %NB_ORA_INCR% >> %RMAN_LOG_FILE% @echo NB_ORA_CINC: %NB_ORA_CINC% >> %RMAN_LOG_FILE% @echo NB_ORA_SERV: %NB_ORA_SERV% >> %RMAN_LOG_FILE% @echo NB_ORA_POLICY: %NB_ORA_POLICY% >> %RMAN_LOG_FILE% @REM --------------------------------------------------------------------------- @REM Call Server Manager to shutdown the target database in immediate priority. @REM This lets current calls to the database complete, but prevents further @REM logons or calls. @REM @REM The shutdown-startup logic of this script can be commented out if you know @REM that the database will always be mounted and in a consistent state before @REM this script is executed. @REM --------------------------------------------------------------------------- @( echo connect %TARGET_CONNECT_STR% as sysdba echo shutdown immediate echo exit ) | %CMD% >> %RMAN_LOG_FILE% @REM --------------------------------------------------------------------------- @REM Now we know that the database is cleanly closed and is ready for a @REM cold backup. RMAN requires that the database be started and mounted @REM to perform a backup. @REM --------------------------------------------------------------------------- @( echo connect %TARGET_CONNECT_STR% as sysdba echo startup mount pfile=%TARGET_INIT_FILE% echo exit ) | %CMD% >> %RMAN_LOG_FILE% @REM --------------------------------------------------------------------------- @REM If this script is executed from a NetBackup schedule, NetBackup @REM sets an NB_ORA environment variable based on the schedule type. @REM For example, when: @REM schedule type is BACKUP_TYPE is @REM ---------------- -------------- @REM Automatic Full INCREMENTAL LEVEL=0 @REM Automatic Differential Incremental INCREMENTAL LEVEL=1 @REM Automatic Cumulative Incremental INCREMENTAL LEVEL=1 CUMULATIVE @REM @REM For user initiated backups, BACKUP_TYPE defaults to incremental @REM level 0 (Full). To change the default for a user initiated @REM backup to incremental or incrementatl cumulative, uncomment @REM one of the following two lines. @REM @set BACKUP_TYPE="INCREMENTAL LEVEL=1" @REM @set BACKUP_TYPE="INCREMENTAL LEVEL=1 CUMULATIVE" @REM @REM Note that we use incremental level 0 to specify full backups. @REM That is because, although they are identical in content, only @REM the incremental level 0 backup can have incremental backups of @REM level > 0 applied to it. @REM --------------------------------------------------------------------------- @REM --------------------------------------------------------------------------- @REM What kind of backup will we perform. @REM --------------------------------------------------------------------------- @if "%NB_ORA_FULL%" EQU "1" @set BACKUP_TYPE=INCREMENTAL Level=0 @if "%NB_ORA_INCR%" EQU "1" @set BACKUP_TYPE=INCREMENTAL Level=1 @if "%NB_ORA_CINC%" EQU "1" @set BACKUP_TYPE=INCREMENTAL Level=1 CUMULATIVE @if NOT DEFINED BACKUP_TYPE @set BACKUP_TYPE=INCREMENTAL Level=0 @REM --------------------------------------------------------------------------- @REM Call Recovery Manager to initiate the backup. This example does not use a @REM Recovery Catalog. If you choose to use one, remove the option, nocatalog, @REM from the rman command line below and add a @REM 'rcvcat /@' statement. @REM @REM NOTE WHEN USING TNS ALIAS: When connecting to a database @REM using a TNS alias, you must use a send command or a parms operand to @REM specify environment variables. In other words, when accessing a database @REM through a listener, the environment variables set at the system level are not @REM visible when RMAN is running. For more information on the environment @REM variables, please refer to the NetBackup for Oracle Admin. Guide. @REM @REM --------------------------------------------------------------------------- @( echo RUN { echo ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE'; echo ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE'; echo BACKUP echo %BACKUP_TYPE% echo FORMAT 'bk_u%%u_s%%s_p%%p_t%%t' echo DATABASE; echo sql 'alter database open'; echo RELEASE CHANNEL ch00; echo RELEASE CHANNEL ch01; echo } ) | %RMAN% target %TARGET_CONNECT_STR%@%TARGET_TNS% rcvcat rman/rman@wb_rman.world msglog '%RMAN_LOG_FILE%' append @SET ERRLEVEL=%errorlevel% @REM --------------------------------------------------------------------------- @REM NetBackup (bphdb) stores the name of a file in an environment variable, @REM called STATUS_FILE. This file is used by an automatic schedule to @REM communicate status information with NetBackup's job monitor. It is up to @REM the script to write a 0 (passed) or 1 (failure) to the status file. @REM --------------------------------------------------------------------------- @if %ERRLEVEL% NEQ 0 goto err @set LOGMSG=ended successfully @if "%STATUS_FILE%" EQU "" goto end @echo 0 > "%STATUS_FILE%" @goto end :err @set LOGMSG=ended in error @if "%STATUS_FILE%" EQU "" goto end @echo 1 > "%STATUS_FILE%" :end @REM --------------------------------------------------------------------------- @REM Log the completion of this script. @REM --------------------------------------------------------------------------- @for /F "tokens=1*" %%p in ('date /T') do @set DATE=%%p %%q @for /F %%p in ('time /T') do @set DATE=%DATE% %%p @echo %0 >> %RMAN_LOG_FILE% @echo ==== %LOGMSG% on %DATE% ==== >> %RMAN_LOG_FILE% @endlocal @REM End of Main Program -----------------------------------------------------