rem This script will create the scripts necessary for a complete hot backup of an Oracle database on NT. rem Datafiles and controlfiles are backed up in this script. rem These scripts can then be run in batch. Use the AT scheduler to schedule the backup job. rem rem Edit the SID, CONNECT and INIT strings used in this command file. rem rem Author: Craig MacPherson - Oracle Corporation Canada Inc. June/97 rem Edited: Stephen Morse - Oracle Corporation US, November 97 echo. REM echo HOT_GEN.CMD Usage: REM echo Enter HOT_GEN SCRIPT_TARGET BACKUP_TARGET REM echo where SCRIPT_TARGET is the location for the backup scripts e.g. c:\oraback\sid\COLD REM echo and BACKUP_TARGET is the location for the Oracle datafile backups when batch is executed REM echo. REM pause REM setlocal REM 10-DEC-1999 REM 1) commented the above help and pause out REM 2) replaced the connects as sysdba by connect internal REM 25-JAN-2000 REM added set ORACLE_SID=in hot_backup.cmd REM example uses SID=OR85 REM %ORACLE_HOME%=d:\ORA805 REM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REM These values cannot be derived, please set them to reflect your environment REM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! set ORACLE_SID= set O_CONNECT= set O_INIT= rem Oracle Binaries set O_SVRMGR= set O_EXPORT= set O_PLUS= set O_COPY= set O_BACKPATH=%2 set O_SCRIPTPATH=%1 if %O_SCRIPTPATH%.==. goto help if %O_BACKPATH%.==. goto help rem *************************************************************************** rem HOT BACKUP OF THE DATABASE rem *************************************************************************** echo. echo ********************************************************** echo - Create hot_backup.CMD script to coordinate all backup activities - for AT scheduling echo ********************************************************** echo. ECHO REM Backup the init file >%O_SCRIPTPATH%\hot_backup.CMD echo copy %O_INIT% %O_BACKPATH% >>%O_SCRIPTPATH%\hot_backup.CMD echo SET ORACLE_SID=%ORACLE_SID% >>%O_SCRIPTPATH%\hot_backup.CMD ECHO REM Run the svrmgr script to backup the datafiles >>%O_SCRIPTPATH%\hot_backup.CMD echo %O_SVRMGR% @%O_SCRIPTPATH%\svrmgr1.sql >>%O_SCRIPTPATH%\hot_backup.CMD ECHO REM Run the svrmgr2.sql script to backup the controlfiles >>%O_SCRIPTPATH%\hot_backup.CMD echo %O_SVRMGR% @%O_SCRIPTPATH%\svrmgr2.sql >>%O_SCRIPTPATH%\hot_backup.CMD echo. echo ********************************************************** ECHO -- Create a SQL*PLUS script for the datafile backups echo ********************************************************** echo. echo set heading off; >%O_SCRIPTPATH%\plus1.sql echo set feedback off; >>%O_SCRIPTPATH%\plus1.sql echo spool %O_SCRIPTPATH%\svrmgr1.sql; >>%O_SCRIPTPATH%\plus1.sql echo select 'connect %O_CONNECT% ;' from dual; >>%O_SCRIPTPATH%\plus1.sql echo select 'alter system switch logfile;' from dual; >>%O_SCRIPTPATH%\plus1.sql echo select 'alter system switch logfile;' from dual; >>%O_SCRIPTPATH%\plus1.sql echo select 'alter tablespace '^|^|tablespace_name^|^|' begin backup;'^|^|' >>%O_SCRIPTPATH%\plus1.sql echo '^|^|'host start /wait %O_COPY% '^|^|file_name^|^|' %O_BACKPATH%;'^|^|' >>%O_SCRIPTPATH%\plus1.sql echo '^|^|'alter tablespace '^|^|tablespace_name^|^|' end backup;' from dba_data_files; >>%O_SCRIPTPATH%\plus1.sql echo select 'exit;' from dual; >>%O_SCRIPTPATH%\plus1.sql echo exit; >>%O_SCRIPTPATH%\plus1.sql echo. echo ********************************************************** ECHO -- Run the sql*plus script to create the svrmgr1.sql script echo ********************************************************** echo. %O_PLUS% %O_CONNECT% @%O_SCRIPTPATH%\plus1.sql echo. echo ********************************************************** ECHO -- Create a SQL*PLUS script for the control files echo ********************************************************** echo. echo set heading off; >%O_SCRIPTPATH%\plus2.sql echo set feedback off; >>%O_SCRIPTPATH%\plus2.sql echo spool %O_SCRIPTPATH%\svrmgr2.sql; >>%O_SCRIPTPATH%\plus2.sql echo select 'connect %O_CONNECT% ;' from dual; >>%O_SCRIPTPATH%\plus2.sql echo select 'alter database backup controlfile to '''^|^|'%O_BACKPATH%\'^|^|substr(name,instr(name,'\',-1)+1)^|^|''' REUSE;' from v$controlfile; >>%O_SCRIPTPATH%\plus2.sql echo select 'alter database backup controlfile to trace' from dual; >>%O_SCRIPTPATH%\plus2.sql echo spool off; >>%O_SCRIPTPATH%\plus2.sql echo exit; >>%O_SCRIPTPATH%\plus2.sql echo. echo ********************************************************** ECHO -- Run the sql*plus script to create the svrmgr2.sql scripts echo ********************************************************** echo. %O_PLUS% %O_CONNECT% @%O_SCRIPTPATH%\plus2.sql echo. echo ********************************************************** ECHO -- Hot Backup Complete echo ********************************************************** echo. goto END_OF_FILE; rem *************************************************************************** rem USER HELP rem *************************************************************************** :HELP echo. echo HOT_GEN.CMD Usage: echo Enter HOT_GEN SCRIPT_TARGET BACKUP_TARGET echo where SCRIPT_TARGET is the location for the backup scripts e.g. c:\oraback\sid\HOT echo and BACKUP_TARGET is the location for the Oracle datafile backups when batch is executed echo. goto END_OF_FILE :HELP2 echo. echo Error - Cannot write to %O_BACKPATH% echo. goto END_OF_FILE rem *************************************************************************** rem HANDLE ERRORS HERE rem *************************************************************************** findstr /in "error" %O_BACKPATH%\backup.log && findstr /in "error" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log findstr /in "ora-" %O_BACKPATH%\backup.log && findstr /in "ora-" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log findstr /in "cannot" %O_BACKPATH%\backup.log && findstr /in "cannot" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log findstr /in "not logged" %O_BACKPATH%\backup.log && findstr /in "not logged" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log findstr /in "failure" %O_BACKPATH%\backup.log && findstr /in "failure" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log if exist %O_BACKPATH%\error.log c:\ntreskit\logevent -s E "BACKUP FAILURE!" pause endlocal :END_OF_FILE