Oracle DBA: Backup and Recovery Scripts

By Rajendra Gutta Having the right backup and recovery procedures is crucial to the operation of any database. It is the responsibility of the database administrator to protect the database from system faults, crashes, and natural calamities resulting from a variety of circumstances. Learn how to choose the best backup and recovery mechanism for your Oracle system.

Having the right backup and recovery procedures is the lifeblood of any database. Companies live on data, and, if that data is not available, the whole company collapses. As a result, it is the responsibility of the database administrator to protect the database from system faults, crashes, and natural calamities resulting from a variety of circumstances. The choice of a backup and recovery mechanism depends mainly on the following factors: • • • • • Database mode (ARCHIVELOG, NOARCHIVELOG) Size of the database Backup and recovery time uptime Type of data (OLTP, DSS, Data Warehouse). The types of backup are • • • Offline backup (Cold or closed database backup) Online backup (Hot or open database backup) Logical export Logical exports create an export file that contains a list of SQL statements to recreate the database. Export is performed when the database is open and does not affect users work. Offline backups can only be performed when the database is shut down cleanly, and the database will be unavailable to users while the offline backup is being performed. Online backups are performed when the database is open, and it does not affect users work. The database needs to run in ARCHIVELOG mode to perform online backups. The database can run in either ARCHIVELOG mode or NOARCHIVELOG mode. In ARCHIVELOG mode, the archiver (ARCH) process archives the redo log files to the archive destination directory. These archive files can be used to recover the database in the case of a failure. In NOARCHIVELOG mode, the redo log files are not archived. When the database is running in ARCHIVELOG mode, the choice can be one or more of the following: • • • Export Hot backup Cold backup When the database is running in NOARCHIVELOG mode, the choice of backup is as follows: • • Export Cold backup

Cold Backup
Offline or cold backups are performed when the database is completely shutdown. The disadvantage of an offline backup is that it cannot be done if the database needs to be run 24/7. Additionally, you can only

recover the database up to the point when the last backup was made unless the database is running in ARCHIVELOG mode. The general steps involved in performing a cold backup are shown in Figure 3.1. These general steps are used in writing cold backup scripts for Unix and Windows NT.

The steps in Figure 3.1 are explained as follows. Step 1—Generating File List An offline backup consists of physically copying the following files: • • • Data files Control files Init.ora and config.ora files

CAUTION
Backing up online redo log files is not advised in all cases, except when performing cold backup with the database running in NOARCHIVELOG mode. If you make a cold backup in ARCHIVELOG mode do not backup redo log files. There is a chance that you may accidentally overwrite your real online redo logs, preventing you from doing a complete recovery. If your database is running in ARCHIVELOG mode, when you perform cold backup you should also backup archive logs that exist. Before performing a cold backup, you need to know the location of the files that need to be backed up. Because the database structure changes day to day as more files get added or moved between directories, it is always better to query the database to get the physical structure of database before making a cold backup. To get the structure of the database, query the following dynamic data dictionary tables: • V$datafile Lists all the data files used in the database SQL>select name from v$datafile; • Backup the control file and perform a trace of the control file using SQL>alter database backup controlfile to '/u10/backup/control.ctl';

SQL>alter database backup controlfile to trace; • Init.ora and config.ora Located under $ORACLE_HOME/dbs directory Step 2—Shut down the database You can shut down a database with the following commands: $su – oracle $sqlplus "/ as sysdba" SQL>shutdown Step 3—Perform a backup In the first step, you generated a list of files to be backed up. To back up the files, you can use the Unix copy command (cp) to copy it to a backup location, as shown in the following code. You have to copy all files that you generated in Step 1. $cp /u01/oracle/users01.dbf /u10/backup You can perform the backup of the Init.ora and config.ora files as follows: $cp $ORACLE_HOME/dbs/init.ora /u10/backup $cp $ORACLE_HOME/dbs/config.ora /u10/backup Step 4—Start the database After the backup is complete, you can start the database as follows: $su – oracle $sqlplus "/ as sysdba" SQL> startup

Hot Backup
An online backup or hot backup is also referred to as ARCHIVE LOG backup. An online backup can only be done when the database is running in ARCHIVELOG mode and the database is open. When the database is running in ARCHIVELOG mode, the archiver (ARCH) background process will make a copy of the online redo log file to archive backup location. An online backup consists of backing up the following files. But, because the database is open while performing a backup, you have to follow the procedure shown in Figure 3.2 to backup the files: • • • • Data files of each tablespace Archived redo log files Control file Init.ora and config.ora files

The general steps involved in performing hot backup are shown in Figure 3.2. These general steps are used in writing hot backup scripts for Unix and Windows NT. The steps in Figure 3.2 are explained as follows. Step 1—Put the tablespace in the Backup mode and copy the data files. Assume that your database has two tablespaces, USERS and TOOLS. To back up the files for these two tablespaces, first put the tablespace in backup mode by using the ALTER statement as follows: SQL>alter tablespace USERS begin backup; After the tablespace is in Backup mode, you can use the SELECT statement to list the data files for the USERS tablespace, and the copy (cp) command to copy the files to the backup location. Assume that the USERS tablespace has two data files—users01.dbf and users02.dbf. SQL>select file_name from dba_data_files where tablespace_name='USERS'; $cp /u01/oracle/users01.dbf /u10/backup $cp /u01/oracle/users01.dbf /u10/backup The following command ends the backup process and puts the tablespace back in normal mode. SQL>alter tablespace USERS end backup; You have to repeat this process for all tablespaces. You can get the list of tablespaces by using the following SQL statement: SQL>select tablespace_name from dba_tablespaces; Step 2—Back up the control and Init.ora files. To backup the control file, SQL>alter database backup controlfile to '/u10/backup/control.ctl'; You can copy the Init.ora file to a backup location using $cp $ORACLE_HOME/dbs/initorcl.ora /u10/backup Step 3—Stop archiving.

Archiving is a continuous process and, without stopping archiver, you might unintentionally copy the file that the archiver is currently writing. To avoid this, first stop the archiver and then copy the archive files to backup location. You can stop the archiver as follows: SQL>alter system switch logfile; SQL>alter system archive log stop; The first command switches redo log file and the second command stops the archiver process. Step 4—Back up the archive files. To avoid backing up the archive file that is currently being written, we find the least sequence number that is to be archived from the V$LOG view, and then backup all the archive files before that sequence number. The archive file location is defined by the LOG_ARCHIVE_DEST_n parameter in the Init.ora file. select min(sequence#) from v$log where archived='NO'; Step 5—Restart the archive process. The following command restarts the archiver process: SQL>alter system archive log start; Now you have completed the hot backup of database. An online backup of a database will keep the database open and functional for 24/7 operations. It is advised to schedule online backups when there is the least user activity on the database, because backing up the database is very I/O intensive and users can see slow response during the backup period. Additionally, if the user activity is very high, the archive destination might fill up very fast.

Database Crashes During Hot Backup
There can be many reasons for the database to crash during a hot backup—a power outage or rebooting of the server, for example. If these were to happen during a hot backup, chances are that tablespace would be left in backup mode. In that case you must manually recover the files involved, and the recovery operation would end the backup of tablespace. It's important to check the status of the files as soon as you restart the instance and end the backup for the tablespace if it's in backup mode. select a.name,b.status from v$datafile a, v$backup b where a.file#=b.file# and b.status='ACTIVE'; or select a.tablespace_name,a.file_name,b.status from dba_data_files a, v$backup b where a.file_id=b.file# and b.status='ACTIVE'; This statement lists files with ACTIVE status. If the file is in ACTIVE state, the corresponding tablespace is in backup mode. The second statement gives the tablespace name also, but this can't be used unless the database is open. You need to end the backup mode of the tablespace with the following command: alter tablespace tablespace_name end backup;

Logical Export
Export is the single most versatile utility available to perform a backup of the database, de-fragment the database, and port the database or individual objects from one operating system to another operating system.

x needs two \\ AIX 4. Export can be used to export the database at different levels of functionality: • • • • Full export (full database export) (FULL=Y) User-level export (exports objects of specified users) (OWNER=userlist) Table-level export (exports specified tables and partitions) (TABLES=tablelist) Transportable tablespaces (TABLESPACES=tools. user-level. dates and so on. Backup and Recovery under Unix The backup and recovery scripts discussed here have been tested under Sun Solaris 2. I advise that you test the scripts under your environment for both backup and recovery before using it as a regular backup script. Sun Solaris. These scripts are written based on the common ground among these three Unix flavors.x needs one \ . They might also work in higher versions of the same operating system. Because in Unix the dollar sign ($) is a special character. Sun Solaris. this is different in each flavor of Unix. whereas other backup methods do not support individual object recovery. But. and the Sun OS needs two forward slashes to make the dollar sign a regular character. because export detects any data or block corruptions in the database. the scripts use v$parameter and v$controlfile to get the user dump destination and control file information. TRANSPORT_TABLESPACE=y) There are two methods of Export: • • Conventional Path (default)—Uses SQL layer to create the export file. you have to precede it with a forward slash (\) that tells Unix to treat it as a regular character. We will discuss scripts to perform the full. and AIX with one slight modification. it is easy to follow the flow for the rest of the scripts. The use of a particular command is discussed if there is a difference between these operating systems. Sun OS 5. AIX and HP-UX need one forward slash.x.x and AIX 4.Export backup detects block corruption Though you perform other types of backup regularly. By using export file. it is also possible to recover individual objects. The fact is that the SQL layer introduces CPU overhead due to character set. and AIX The backup scripts provided here work for HP-UX. That is." That chapter explained some of the common routines that will be used across most of the scripts presented here. This testing not only gives you confidence in the script. Therefore it is much faster than conventional path. This is especially useful if the underlying operating system has a limitation of 2GB maximum file limit. considering standardization across all scripts and the reusability of individual sections for your own writing of scripts. converting numbers. Backup Scripts for HP-UX. However. However.x. and table-level export of database. The scripts also show you how to compress and split the export file while performing the export. After you understand one script. Understand scripting This chapter requires understanding of basic Unix shell and DOS batch programming techniques that are described in Chapter 2 "Building Blocks. it is good to perform full export of database at regular intervals. Direct path (DIRECT=YES)—Skips the SQL layer and reads directly from database buffers or private buffers. it also gives you an understanding of how to use the script in case a recovery is needed and gives you peace of mind when a crisis hits. rather than a temporary fix. This book could have provided much more simple scripts. HP-UX 11. This is time consuming. I am focusing on providing a comprehensive script.

Each function is designed to meet a specific objective so that they are easy to understand and modify. Listing 3. Each box represents a corresponding function in the program. It will shutdown and take a cold backup and brings # the database up again . SID is the instance to be backed up. These small functions are reusable and can be used in the design of your own scripts. Figure 3.HP-UX 11. you can do so easily in the function where you want the change without affecting the whole script. Database #should be online when you start # the script. it is necessary to check the backup status by reviewing log and error files generated by the scripts. Cold Backup Cold backup program (see Listing 3.1 coldbackup_ux ##################################################################### # PROGRAM NAME:coldbackup_ux # PURPOSE:Performs cold backup of the database.3 describes the functionality of the cold backup program. If you want to change a script to fit to your unique needs. The script takes two input parameters—SID and OWNER. Each script consists of a number of small functions and a main section.1) performs the cold backup of the database under the Unix environment. After the backup is complete.x needs one \ These scripts are presented in modular approach. and OWNER is the Unix account under which Oracle is running.

Database is up. Can't generate files to be backed up" } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_verify_shutdown(): Verify that database is down #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_verify_shutdown(){ STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´ if [ $? = 0 ]. exit EOF } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_startup_r(): Startup database in restricted mode #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_startup_r(){ ${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba startup restrict. Owner($ORA_OWNER). exit EOF } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_shutdown_n(): Shutdown database in Normal mode #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_shutdown_n(){ ${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba shutdown normal.# USAGE:$coldbackup_ux SID OWNER # INPUT PARAMETERS: SID(Instance name)."|tee -a ${BACKUPLOGFILE} >> $LOGFILE exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_shutdown_i(): Shutdown database in Immediate mode #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_shutdown_i(){ ${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba shutdown immediate. then echo "´date´" >> $LOGFILE echo "COLDBACKUP_FAIL: ${ORA_SID}. OWNER(Owner of instance) ##################################################################### #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_verify(): Verify that database is online #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_verify(){ STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´ funct_chk_ux_cmd_stat "Database is down for given SID($ORA_SID). exit EOF } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_startup_n(): Startup database in normal mode #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_startup_n(){ . can't make coldbackup if the database is online.

" >> ${BACKUPLOGFILE} #Prepare a restore file to restore coldbackup in case a restore is necessary echo cp -p ${DATAFILE_DIR}/´echo $datafile|awk -F"/" '{print $NF}'´ $datafile >> ${RESTOREFILE} .. exit EOF echo "Backingup controlfile and trace to trace file" >>${BACKUPLOGFILE} ${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off alter database backup controlfile to '${CONTROLFILE_DIR}/backup_control.sql fi fi } # Prepare restore file for control file echo "###### Control File " >> ${RESTOREFILE} echo "# Use your own discretion to copy control file. not advised unless required.. alter database backup controlfile to trace. exit EOF # Backup trace of control file CONTROL=´ls -t ${udump_dest}/*." >> ${BACKUPLOGFILE} datafile_list=´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off select file_name from dba_data_files order by tablespace_name..trc |head -1´ if [ ! -z "$CONTROL" ]. exit EOF } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_build_dynfiles(): Identify the files to backup #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_build_dynfiles(){ # Build datafile list echo "Building datafile list . then cp ${CONTROL} ${CONTROLFILE_DIR}/backup_control." >> ${RESTOREFILE} echo " End of backup of control file" >> ${BACKUPLOGFILE} #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_cold_backup(): Perform cold backup #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_cold_backup(){ #Copy datafiles to backup location echo "############### Data Files " >> ${RESTOREFILE} for datafile in ´echo $datafile_list´ do echo "Copying datafile ${datafile} .${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba startup. exit EOF´ echo "############### SQL for Temp Files " >> ${RESTOREFILE} ${ORACLE_HOME}/bin/sqlplus -s <<EOF >> ${RESTOREFILE} / as sysdba set heading off feedback off select 'alter tablespace '||tablespace_name||' add tempfile '||''|| file_name||''||' reuse'||'..ctl'.' from dba_temp_files. then grep 'CONTROL' ${CONTROL} 1> /dev/null if test $? -eq 0.

fi ${INITFILE_DIR} ]. fi ${DATAFILE_DIR} ]. fi # Remove old backup rm -f ${RESTOREFILE_DIR}/* rm -f ${BACKUPLOG_DIR}/* rm -f ${DATAFILE_DIR}/* rm -f ${CONTROLFILE_DIR}/* rm -f ${REDOLOG_DIR}/* rm -f ${ARCLOG_DIR}/* rm -f ${INITFILE_DIR}/* echo "${JOBNAME}: coldbackup of ${ORA_SID} begun on ´date +\"%c\"´" > ${BACKUPLOGFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_get_vars(): Get environment variables .ora file" >> ${BACKUPLOGFILE} cp -p ${init_file} ${INITFILE_DIR}/init${ORA_SID}. then mkdir -p ${LOGDIR}. then echo "COLDBACKUP_FAIL: ${ORA_SID}. fi ${REDOLOG_DIR} ]. then mkdir -p ${DATAFILE_DIR}.ora ${init_file} >> ${RESTOREFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_parm(): Check for input parameters #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_parm() { if [ ${NARG} -ne 2 ].ora File " >> ${RESTOREFILE} echo cp -p ${INITFILE_DIR}/init${ORA_SID}. fi ${ARCLOG_DIR} ]. then mkdir -p ${INITFILE_DIR}. fi if [ ! -d ${LOGDIR} ]. then mkdir -p ${DYN_DIR}.ora funct_chk_ux_cmd_stat "Failed to copy init.ora file to backup location" echo "################ Init. fi if [ ! -d ${DYN_DIR} ]. then mkdir -p ${BACKUPLOG_DIR}. then mkdir -p ${ARCLOG_DIR}. then mkdir -p ${RESTOREFILE_DIR}.ora file to backup directory echo " Copying current init.cp -p ${datafile} ${DATAFILE_DIR} funct_chk_ux_cmd_stat "Failed to copy datafile file to backup location" done #Copy current init<SID>. fi ${CONTROLFILE_DIR} ]. fi ${BACKUPLOG_DIR} ]. then mkdir -p ${REDOLOG_DIR}.log" if if if if if if if [ [ [ [ [ [ [ ! ! ! ! ! ! ! -d -d -d -d -d -d -d ${RESTOREFILE_DIR} ]. then mkdir -p ${CONTROLFILE_DIR}. Not enough arguments passed" exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_bkup_dir(): Create backup directories if not already existing #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_bkup_dir() { RESTOREFILE_DIR="${BACKUPDIR}/restorefile_dir" BACKUPLOG_DIR="${BACKUPDIR}/backuplog_dir" DATAFILE_DIR="${BACKUPDIR}/datafile_dir" CONTROLFILE_DIR="${BACKUPDIR}/controlfile_dir" REDOLOG_DIR="${BACKUPDIR}/redolog_dir" ARCLOG_DIR="${BACKUPDIR}/arclog_dir" INITFILE_DIR="${BACKUPDIR}/initfile_dir" BACKUPLOGFILE="${BACKUPLOG_DIR}/backup_log_${ORA_SID}" RESTOREFILE="${RESTOREFILE_DIR}/restorefile_${ORA_SID}" LOGFILE="${LOGDIR}/${ORA_SID}.

export ORACLE_SID } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_ux_cmd_stat(): Check the exit status of Unix command #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_ux_cmd_stat() { if [ $? != 0 ]. then echo "´date´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} echo "COLDBACKUP_FAIL: ${1} "| tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi } ############################################################ # MAIN ############################################################ NARG=$# ORA_SID=$1 ORA_OWNER=$2 # Set environment variables BACKUPDIR="/u02/${ORA_SID}/cold" ORATABDIR=/etc/oratab TOOLS="/u01/oracomn/admin/my_dba" DYN_DIR="${TOOLS}/DYN_FILES" . export ORACLE_HOME ORACLE_SID=${ORA_SID}.ora does not exist in ORACLE_HOME/dbs"|tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi if [ x$udump_dest = 'x' ]. then echo "COLDBACKUP_FAIL: user_dump_dest not defined in init$ORA_SID.#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_get_vars(){ ORA_HOME=´sed /#/d ${ORATABDIR}|grep -i ${ORA_SID}|nawk -F ":" '{print $2}'´ ORA_BASE=´echo ${ORA_HOME}|nawk -F "/" '{for (i=2.ora"| tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi ORACLE_HOME=${ORA_HOME}. exit EOF´ if [ x$ORA_HOME = 'x' ]. i++) print "/"$i}'´ ORACLE_BASE=´echo $ORA_BASE|tr -d " "´ init_file=$ORA_HOME/dbs/init$ORA_SID. then echo "COLDBACKUP_FAIL: init$ORA_SID. then echo "COLDBACKUP_FAIL: Can't get ORACLE_HOME from oratab file for $ORA_SID"|tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi if [ ! -f $init_file ].ora #log_arch_dest1=´sed /#/d $init_file|grep -i log_archive_dest| nawk -F "=" '{print $2}'´ #log_arch_dest=´echo $log_arch_dest1|tr -d "'"|tr -d '"'´ udump_dest=´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off select value from v\\$parameter where name='user_dump_dest'. i<=NF-2.

ORATABDIR.ora file in the ORACLE_HOME/dbs directory. These temporary files are session-specific and do not have any content when the database is closed. A sample oratab file can be found at the end of the chapter. With the restore file. refer to Chapter 13. Check for existence of initSID. The variables BACKUPDIR defines the backup location. you must add the instance. funct_startup_r() This function starts up the database in Restricted mode. If it is in a different location.LOGDIR="${TOOLS}/localog" JOBNAME="dbcoldbackup" echo " Starting coldbackup of ${ORA_SID} " funct_chk_parm funct_chk_bkup_dir funct_get_vars funct_verify funct_build_dynfiles funct_shutdown_i funct_startup_r funct_shutdown_n funct_verify_shutdown funct_cold_backup funct_startup_n echo "${ORA_SID}.2. This functionality is added based on the fact that a lot of DBAs perform backups but. you must create one. when it comes to recovery. and TOOLS variables highlighted in the cold backup script. they will not have any procedures to make the recovery faster. The value of USER_DUMP_DEST is used to back up the trace of the control file. If not already there. . "Unix. Pass SID and OWNER as parameters to the program. funct_shutdown_i() This function shuts down the database in Immediate mode. It also creates SQL statements for temporary files. especially after copying files to a backup location. funct_get_vars() This function gets ORACLE_HOME from the oratab file and USER_DUMP_DEST from the initSID. The default location of ORATABDIR is different for each flavor of Unix. funct_build_dynfiles() This function generates a list of files from the database for backup. For information about the default location of the ORATAB file for different flavors of Unix. OWNER is the owner of Oracle software directories. so that any user connected to the database will be disconnected immediately. Coldbackup Completed successfully on ´date +\"%c\"´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} ######## END MAIN ########################## Cold Backup Script under Unix Checklist • In the main function. A sample restore file is shown in Listing 3. • • • • • • • • • • • Restore File A cold backup program creates a restore file that contains the commands to restore the database. you can create a soft link to the ORACLE_HOME/dbs directory. If it is not there. main() The main function defines the variables required and calls the functions to be executed. funct_shutdown_n() This function performs a clean shutdown of the database. The database must be running when you start the program. it is easier to restore files to the original location because it has all the commands ready to restore the backup. ORATABDIR defines the oratab file location." Check for the existence of SID in oratab file. so that no one can connect to the database except users with Restrict privileges. but can be recreated when a restore is performed. set correct values for the BACKUPDIR.ora file. funct_chk_ux_cmd_stat() This function is used to check the status of Unix commands. Otherwise. oratab files maintain the list of instances and their home directories on the machine. you need to know the structure of the database—what files are located where. Windows NT. and Oracle. These temporary files do not need to be backed up. This file is created by default when oracle is installed. It gets required information by querying the database and then shuts down the database and performs cold backup.

. coldbackup_ux SID OWNER 1> coldbackup.dbf' reuse.. Failed to copy control file to backup location BACKUPLOGFILE Listing 3. ######### Data Files cp -p /bkp/DEV/cold/datafile_dir/INDX01.2 Sample Restore File ######### SQL for Temp Files alter tablespace TEMP add tempfile '/u03/oracle/DEV/data/temp03.dbf /u02/oracle/DEV/data/TEMP01. This single file maintains the history of performed backups and their status and timing information.. Coldbackup Completed successfully on Sun May 20 21:19:38 2001 . Apart from the BACKUPLOGFILE and SID.dbf .dbf /u02/oracle/DEV/data/cntrl01. Copying redolog file /u03/oracle/DEV/data/log01a.log files.dbf cp -p /bkp/DEV/cold/datafile_dir/USERS01.dbf cp -p /bkp/DEV/cold/datafile_dir/RBS01.dbf ..dbf cp -p /bkp/DEV/cold/datafile_dir/SYSTEM01.log file...ora Cold Backup Troubleshooting and Status Check The important thing here is that the backup log file defined by BACKUPLOGFILE contains detailed information about each step of the backup process..dbf /u02/oracle/DEV/data/INDX01.dbf /u02/oracle/DEV/data/SYSTEM01. Copying control file /u02/oracle/DEV/data/cntrl01.dbf /u02/oracle/DEV/data/RBS01.ora file DEV. This file is located under the directory defined by the LOGDIR variable. it is always good to capture the out-of-the-ordinary errors displayed onscreen if you are running the backup unattended.dbf . The messages for a cold backup are 'COLDBACKUP_FAIL' if a cold backup failed and 'Coldbackup Completed successfully' if a backup completes successfully.. Copying datafile /u02/oracle/DEV/data/RBS01. This is a very good place to start investigating why the backup failed or for related errors.Listing 3. alter tablespace TEMP add tempfile '/u03/oracle/DEV/data/temp04..dbf ######### Init.ora /u02/apps/DEV/oracle/8.dbf ..dbf cp -p /bkp/DEV/cold/datafile_dir/TEMP01. dbcoldbackup: Building controlfile list Copying datafile /u02/oracle/DEV/data/INDX01. Copying datafile /u02/oracle/DEV/data/TEMP01. Copying datafile /u02/oracle/DEV/data/SYSTEM01. Copying datafile /u02/oracle/DEV/data/USERS01...dbf' reuse.3 Sample BACKUPLOGFILE —dbcoldbackup: coldbackup of DEV begun on Sun May 20 21:15:27 2001 dbcoldbackup: building datafile list . A single line about the success or failure of a backup is appended to SID. You can capture these errors by running the command shown next.dbf . Copying redolog file /u03/oracle/DEV/data/log01b.log 2>&1 The following is an excerpt from the SID.log file every time a backup is performed.dbf /u02/oracle/DEV/data/USERS01.ora File cp -p /bkp/DEV/cold/initfile_dir/initDEV.. This file also has the backup completion time.1. The same thing can be done for hot backups..dbf .. Copying current init.dbf ..dbf ######### Control Files cp -p /bkp/DEV/cold/controlfile_dir/cntrl01. This command captures onscreen errors to the coldbackup.log file: Tue Jul 18 16:48:46 EDT 2000 COLDBACKUP_FAIL: DEV.dbf .7/ dbs/initDEV. This file will also have the start and end time of the backup. A separate file is created for each instance.

4 shows the functionality of the hot backup program. OWNER(Owner of instance) ##################################################################### #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_verify(): Verify that database is online #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_verify(){ STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´ funct_chk_ux_cmd_stat "Database is down for given SID($ORA_SID).Hot Backup Listing 3. The hot backup script takes two input parameters—SID and OWNER. Listing 3.4 provides the script to perform the hot backup of a database under the Unix environment. Each box represents a corresponding function in the program. and OWNER is the Unix account under which Oracle is running. SID is the instance to be backed up. . Figure 3.4 hotbackup_ux ##################################################################### # PROGRAM NAME: hotbackup_ux # PURPOSE: This utility will perform a warm backup of # the database # USAGE: $hotbackup_ux SID OWNER # INPUT PARAMETERS: SID(Instance name).

Can't perform hotbackup " |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_control_backup(): Backup control file #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_control_backup(){ echo "Begin backup of controlfile and trace to trace file" >>${BACKUPLOGFILE} ${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off alter database backup controlfile to '${CONTROLFILE_DIR}/backup_control..." >> ${RESTOREFILE} echo " End of backup of control file" >> ${BACKUPLOGFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_archivelog_backup(): Backup archivelog files #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_archivelog_backup(){ echo "Begin backup of archived redo logs" >> ${BACKUPLOGFILE} #Switch logs to flush current redo log to archived redo before back up ${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off alter system switch logfile. then echo "´date´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} echo "HOTBACKUP_FAIL: $ORA_SID is in NOARCHIVELOG mode.ctl'.sql fi fi # Prepare restore file for control file echo "###### Control File " >> ${RESTOREFILE} echo "# Use your own discretion to copy control file. alter database backup controlfile to trace. exit EOF´ if [ $STATUS = "NOARCHIVELOG" ]. then grep 'CONTROL' ${CONTROL} 1> /dev/null if test $? -eq 0. alter system archive log stop.trc |head -1´ if [ ! -z "$CONTROL" ]. . Can't perform hotbackup " } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_dblogmode(): Check DB log mode #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_dblogmode(){ STATUS=´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off select log_mode from v\\$database. then cp ${CONTROL} ${CONTROLFILE_DIR}/backup_control. exit EOF # Backup trace of control file CONTROL=´ls -t ${udump_dest}/*. not advised unless required.Owner($ORA_OWNER).

ora file to backup directory echo " Copying current init${ORA_SID}.ora file" >> ${BACKUPLOGFILE} cp -p ${init_file} ${INITFILE_DIR}/init${ORA_SID}.ora echo "############# Parameter Files" >> ${RESTOREFILE} echo cp -p ${INITFILE_DIR}/init${ORA_SID}.ora file to backup location" # Prepare restore file for init. exit EOF #Prepare restore file for arc log files echo "##### Archive Log Files" >> ${RESTOREFILE} for arc_file in ´echo $ARCLOG_FILES´ do echo cp -p ${ARCLOG_DIR}/´echo $arc_file|awk -F"/" '{print $NF}'´ $arc_file >> ${RESTOREFILE} done #Copy arc log files to backup location #remove the archived redo logs from the log_archive_dest if copy is successful cp -p ${ARCLOG_FILES} ${ARCLOG_DIR} if [ $? = 0 ].ora ${init_file} >> ${RESTOREFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_temp_backup(): Prepre SQL for temp files #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: . then rm ${ARCLOG_FILES} else echo "´date´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} echo "HOTBACKUP_FAIL: Failed to copy Archive log files" | tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi echo "End backup of archived redo logs" >> ${BACKUPLOGFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_init_backup(): Backup init.ora funct_chk_ux_cmd_stat "Failed to copy init.ora file #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_init_backup(){ #Copy current init<SID>.exit EOF # This gets the redo sequence number that is being archived # and remove this from the list of files to be backed up ARCSEQ=´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off select min(sequence#) from v\\$log where archived='NO'. exit EOF´ #Get current list of archived redo log files ARCLOG_FILES=´ls ${log_arch_dest}/*|grep -v $ARCSEQ´ ${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off alter system archive log start.

. exit EOF # Copy datafiles of current tablespace for datafile in ´echo $datafile_list´ do echo "Copying datafile ${datafile}.." >> ${BACKUPLOGFILE} ${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off alter tablespace ${tblspace} begin backup.' from dba_temp_files.funct_temp_backup(){ echo "############# Recreate the following Temporary Files" >> ${RESTOREFILE} ${ORACLE_HOME}/bin/sqlplus -s <<EOF >> ${RESTOREFILE} / as sysdba set heading off feedback off select 'alter tablespace '||tablespace_name||' add tempfile '||''|| file_name||''||' reuse'||'. exit EOF´ echo "##### DATE:" ´date´ > ${RESTOREFILE} echo "####Data Files(Please restore only corrupted files)" >> ${RESTOREFILE} for tblspace in ´echo $tablespace_list´ do # Get the datafiles for the current tablespace datafile_list=´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off select file_name from dba_data_files where tablespace_name = '${tblspace}'." >> ${BACKUPLOGFILE} # The next command prepares restore file echo cp -p ${DATAFILE_DIR}/´echo $datafile|awk -F"/" '{print $NF}'´ $datafile >> ${RESTOREFILE} cp -p ${datafile} ${DATAFILE_DIR} if [ $? != 0 ]. exit EOF´ echo " Beginning back up of tablespace ${tblspace}.. then echo "´date´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} echo "HOTBACKUP_FAIL: Failed to copy file to backup location "| tee -a ${BACKUPLOGFILE} >> ${LOGFILE} # Ending the tablespace backup before exiting ´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba .. exit EOF } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #funct_hot_backup(): Backup datafiles #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_hot_backup(){ # Get the list of tablespaces echo "Building tablespace list " >> ${BACKUPLOGFILE} tablespace_list=´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off select distinct tablespace_name from dba_data_files order by tablespace_name.

.set heading off feedback off alter tablespace ${tblspace} end backup. fi if [ ! -d ${LOGDIR} ]. fi if [ ! -d ${DYN_DIR} ]. then mkdir -p ${REDOLOG_DIR}. then mkdir -p ${ARCLOG_DIR}. Not enough arguments passed" exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_bkup_dir(): Create backup directories if not already existing #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_bkup_dir() { RESTOREFILE_DIR="${BACKUPDIR}/restorefile_dir" BACKUPLOG_DIR="${BACKUPDIR}/backuplog_dir" DATAFILE_DIR="${BACKUPDIR}/datafile_dir" CONTROLFILE_DIR="${BACKUPDIR}/controlfile_dir" REDOLOG_DIR="${BACKUPDIR}/redolog_dir" ARCLOG_DIR="${BACKUPDIR}/arclog_dir" INITFILE_DIR="${BACKUPDIR}/initfile_dir" BACKUPLOGFILE="${BACKUPLOG_DIR}/backup_log_${ORA_SID}" RESTOREFILE="${RESTOREFILE_DIR}/restorefile_${ORA_SID}" LOGFILE="${LOGDIR}/${ORA_SID}. then mkdir -p ${BACKUPLOG_DIR}. then mkdir -p ${INITFILE_DIR}. fi ${BACKUPLOG_DIR} ]. exit EOF echo " Ending back up of tablespace ${tblspace}. fi ${REDOLOG_DIR} ]. then mkdir -p ${RESTOREFILE_DIR}. fi ${CONTROLFILE_DIR} ].log" if if if if if if if [ [ [ [ [ [ [ ! ! ! ! ! ! ! -d -d -d -d -d -d -d ${RESTOREFILE_DIR} ]. then mkdir -p ${CONTROLFILE_DIR}. fi ${ARCLOG_DIR} ]. fi ${INITFILE_DIR} ]. then mkdir -p ${DYN_DIR}. then mkdir -p ${DATAFILE_DIR}." >> ${BACKUPLOGFILE} done } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_parm(): Check for input parameters #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_parm() { if [ ${NARG} -ne 2 ]. then mkdir -p ${LOGDIR}. fi ${DATAFILE_DIR} ]. fi # Remove old backup rm -f ${RESTOREFILE_DIR}/* rm -f ${BACKUPLOG_DIR}/* rm -f ${DATAFILE_DIR}/* rm -f ${CONTROLFILE_DIR}/* . then echo "HOTBACKUP_FAIL: ${ORA_SID}. exit EOF´ exit 1 fi done ${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off alter tablespace ${tblspace} end backup.

then echo "HOTBACKUP_FAIL: can't get ORACLE_HOME from oratab file for $ORA_SID" | tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi if [ ! echo | tee exit fi -f $init_file ]. then echo "´date´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} echo "HOTBACKUP_FAIL:${1} "|tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi } . i<=NF-2.rm -f ${REDOLOG_DIR}/* rm -f ${ARCLOG_DIR}/* rm -f ${INITFILE_DIR}/* echo "${JOBNAME}: hotbackup of ${ORA_SID} begun on ´date +\"%c\"´" > ${BACKUPLOGFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_get_vars(): Get environment variables #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_get_vars(){ ORA_HOME=´sed /#/d ${ORATABDIR}|grep -i ${ORA_SID}|nawk -F ":" '{print $2}'´ ORA_BASE=´echo ${ORA_HOME}|nawk -F "/" '{for (i=2. export ORACLE_HOME ORACLE_SID=${ORA_SID}.ora does not exist in ORACLE_HOME/dbs" -a ${BACKUPLOGFILE} >> ${LOGFILE} 1 if [ x$log_arch_dest = 'x' -o x$udump_dest = 'x' ]. export ORACLE_SID } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_ux_cmd_stat(): Check the exit status of Unix command #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_ux_cmd_stat() { if [ $? != 0 ].ora #log_arch_dest1=´sed /#/d $init_file|grep -i log_archive_dest| nawk -F "=" '{print $2}'´ #log_arch_dest=´echo $log_arch_dest1|tr -d "'"|tr -d '"'´ udump_dest=´${ORACLE_HOME}/bin/sqlplus -s <<EOF / as sysdba set heading off feedback off select value from v\\$parameter where name='user_dump_dest'. i++) print "/"$i}'´ ORACLE_BASE=´echo $ORA_BASE|tr -d " "´ init_file=$ORA_HOME/dbs/init$ORA_SID. then echo "HOTBACKUP_FAIL: user_dump_dest or log_archive_dest not defined " | tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi ORACLE_HOME=${ORA_HOME}. exit EOF´ if [ x$ORA_HOME = 'x' ]. then "HOTBACKUP_FAIL: init$ORA_SID.

OWNER is the owner of the Oracle software directories. Apart from this.. ORATABDIR. hotbackup Completed successfully on ´date +\"%c\"´" | tee -a ${BACKUPLOGFILE} >> ${LOGFILE} ######## END MAIN ######################### Hot Backup Script under Unix Checklist • • • In the main function..ora file in the ORACLE_HOME/dbs directory. and log_arch_dest variables highlighted in the script. If it is in a different location.ora file because there are some changes between Oracle 7 and 8 in the way the archive destination is defined. The default location of ORATABDIR is different for each flavor of Unix. funct_temp_backup() Oracle 7 and Oracle 8 support permanent temporary tablespaces (created with create tablespce tablespace_name . I have given the option to define log_archive_dest in main function. Check for the existence of the initSID. There are a variety of ways that you can define log_archive_dest based on how many destinations you are using.ora file. This file is created by default when Oracle is installed. funct_get_vars() Make sure that the USER_DUMP_DEST parameter is set correctly in Init.############################################################ # MAIN ############################################################ NARG=$# ORA_SID=$1 ORA_OWNER=$2 # Set environment variables BACKUPDIR="/u02/${ORA_SID}/hot" ORATABDIR=/etc/oratab TOOLS="/u01/oracomn/admin/my_dba" log_arch_dest="/export/home/orcl/arch" DYN_DIR="${TOOLS}/DYN_FILES" LOGDIR="${TOOLS}/localog" JOBNAME="dbhotbackup" echo " Starting hotbackup of . you must create one... Pass SID and OWNER as parameters to the program: • main() BACKUPDIR defines the backup location. oratab files maintain the list of instances and their home directories on the • • machine. ORATABDIR defines the oratab file location. . ${ORA_SID}" funct_chk_parm funct_chk_bkup_dir funct_get_vars funct_verify funct_chk_dblogmode funct_hot_backup funct_temp_backup funct_control_backup funct_archivelog_backup funct_init_backup echo "${ORA_SID}. TOOLS. Consequently. you must add the instance. If it is not there.. If not already there. set the correct values for BACKUPDIR. temporary). I was reluctant to get LOG_ARCHIVE_DEST from the Init. Check for existence of the SID instance in the oratab file. you must create a soft link to the ORACLE_HOME/dbs directory.

This single file maintains the history of the performed backups. control. The export script takes two input parameters—SID and OWNER. init files. Figure 3.5) performs a full export of the database under Unix environment. The files for these temporary tablespaces are listed under the dba_temp_files data dictionary view. Listing 3. and OWNER is the Unix account under which Oracle is running.. and 'Hotbackup Completed successfully'. This file will also have the start and end time of the backup. The trace of the control file will be useful to examine the structure of the database.5 Functions in export and split export scripts for Unix. A single line about the success or failure of a backup is appended to the SID. this function also backs up the trace of the control file. Data in these temporary tablespaces is session-specific and gets deleted as soon as the session is disconnected. A separate file is created for each instance. Restore file The restore file for hot backup looks similar to cold backup. SID is the instance to be backed up.). Figure 3.5 xport_ux ###################################################################### # PROGRAM NAME: xport_ux # PURPOSE: Performs export of the database # USAGE: $xport_ux SID OWNER # INPUT PARAMETERS: SID(Instance name). and timing information. Because of the nature of these temporary tablespaces.5 shows the functionality of the export and split export programs. Hot Backup Troubleshooting and Status Check The important thing here is that the backup log file defined by (BACKUPLOGFILE) contains detailed information about each step of the backup process. The following is an excerpt from the log file: Tue Jul 18 16:48:46 EDT 2000 HOTBACKUP_FAIL: DEV.. funct_chk_bkup_dir() This function creates backup directories for data. in the case of a restore. redo log. you do not need to back them up. their status. and backup log files. The messages for a hot backup are 'HOTBACKUP_FAIL'. This file is located under the directory defined by the LOGDIR variable. you can just add the data file for these temporary tablespaces. if the backup completes successfully. OWNER(Owner of instance) ) . restore files.• • Oracle 8I has new features to create temporary tablespaces that do not need back up (created with create tablespace temporary. This is a very good place to start investigating why a backup has failed or for related errors. This file also has the backup completion time.log file every time a backup is performed. Not enough arguments passed Export The export program (see Listing 3. funct_control_backup() In addition to taking backup of control file. archivelog. especially if the database has hundreds of files. Please refer to the explanation under the heading restore file for cold backup. This is the single most important piece of information that you need to perform a good recovery. Each box represents a corresponding function in the program. if the hot backup failed.

log">>${PARFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_export(): Export the database #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_export() { # Remove old export file rm -f ${FILE} ${ORACLE_HOME}/bin/exp parfile=${PARFILE} if [ $? != 0 ].log funct_cleanup exit 1 fi } . Owner($ORA_OWNER).###################################################################### #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_verify(): Verify that database is online #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_verify(){ STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´ funct_chk_unix_command_status "Database is down for given SID($ORA_SID). see next line. Can't perform export " } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_cleanup(): Cleanup interim files #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_cleanup() { echo "Left for user convenience" > /dev/null } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_build_parfile(): This will create parameter file #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_build_parfile() { # This line makes sure that it always creates a new parameter file echo " " >${PARFILE} echo "userid=system/manager">>${PARFILE} # if you use connect string. Export Failed" >> $LOGDIR/${ORA_SID}.log echo "EXPORT_FAIL: ${ORA_SID}. #userid=system/manager@${CON_STRING} #echo "Owner=scott">>${PARFILE} #echo "Tables=scott. then echo ´date´ >> $LOGDIR/${ORA_SID}.T1">>${PARFILE} echo "Full=Y">>${PARFILE} #echo "Direct=Y">>${PARFILE} echo "Grants=Y">>${PARFILE} echo "Indexes=Y">>${PARFILE} echo "Rows=Y">>${PARFILE} echo "Constraints=Y">>${PARFILE} echo "Compress=N">>${PARFILE} echo "Consistent=Y">>${PARFILE} echo "File=${FILE}">>${PARFILE} echo "Log=${EXPORT_DIR}/${ORA_SID}.exp.

com } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_unix_command_status(): Check exit status of Unix command #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_unix_command_status() { if [ $? != 0 ]. fi } FILE="${EXPORT_DIR}/${ORA_SID}. then mkdir -p ${EXPORT_DIR}. export ORACLE_SID #CON_STRING=${ORA_SID}. fi if [ ! -d ${DYN_DIR} ].log echo "EXPORT_FAIL: ${1} " >> ${LOGDIR}/${ORA_SID}. then echo "EXPORT_FAIL: ${ORA_SID}. then mkdir -p ${LOGDIR}.dmp" #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_get_vars(): Get environment variables #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_get_vars(){ ORA_HOME=´sed /#/d ${ORATABDIR}|grep -i ${ORA_SID}|nawk -F ":" '{print $2}'´ ORA_BASE=´echo ${ORA_HOME}|nawk -F "/" '{for (i=2. i++) print "/"$i}'´ ORACLE_BASE=´echo $ORA_BASE|tr -d " "´ ORACLE_HOME=${ORA_HOME}. then echo "´date´" >> ${LOGDIR}/${ORA_SID}. i<=NF-2. then mkdir -p ${DYN_DIR}. export ORACLE_HOME ORACLE_SID=${ORA_SID}. fi if [ ! -d ${LOGDIR} ].#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_parm(): Check for input parameters #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_parm() { if [ ${NARG} -ne 2 ].company.log exit 1 fi } ###################################### # MAIN ###################################### NARG=$# ORA_SID=$1 ORA_OWNER=$2 # Set up the environment BACKUPDIR="/u02/${ORA_SID}/export" ORATABDIR=/etc/oratab . Not enough arguments passed" exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_bkup_dir(): Create backup directories if not already exist #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_bkup_dir() { EXPORT_DIR=${BACKUPDIR} if [ ! -d ${EXPORT_DIR} ].

or table-level). funct_build_parfile() Export Troubleshooting and Status Check The 'Log' parameter value set in the parameter file will have detailed information about the status of export.par parameter file dynamically. The following is an excerpt from a log file: Tue Apr 8 16:07:12 EST 2000 DEV .or table-level export. To perform a different type of export (user. The messages for an export are 'EXPORT_FAIL'. This single file maintains the history of performed backups. and TOOLS variables highlighted in the export script. This is a very good place to start investigating why an export has failed or for related errors.. based on the information provided in this function. You can modify the parameters to perform a user. ORATABDIR.. A separate file is created for each instance.. export completed successfully . if the export completes successfully. export completed successfully" >> $LOGDIR/${ORA_SID}.log ####################### END MAIN ############################### Export Script under Unix Checklist • • • In the main function. their status. Pass SID and OWNER as parameters to the program: • • Builds the export. ${ORA_SID}" funct_chk_parm funct_get_vars funct_verify funct_chk_bkup_dir funct_build_parfile funct_export funct_cleanup echo ´date´ >> $LOGDIR/${ORA_SID}. This file also has the backup completion time. it performs a full export. you must add the instance.par" LOGDIR="${TOOLS}/localog" echo ".log file every time an export is performed. and timing information. By default. set the correct parameters. If not already there. Check for existence of SID in the oratab file..TOOLS="/u01/oracomn/admin/my_dba" DYN_DIR="${TOOLS}/DYN_FILES" PARFILE="${DYN_DIR}/export. funct_cleanup() Removes the interim files.log echo "${ORA_SID}. This function is configured for a full export of the database. The funct_build_parfile() function builds the parameter file. if the export failed. set the correct values for BACKUPDIR. and 'Export Completed successfully'.. A single line about the success or failure of export is appended to SID. This file is located under the directory defined by the LOGDIR variable. Now exporting . The default location of ORATABDIR is different for each flavor of Unix.

FILESIZE specifies the maximum file size of each dump file. OWNER(Owner of instance) ###################################################################### #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_verify(): Verify that database is online #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_verify(){ STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´ funct_chk_unix_command_status "Database is down for given SID($ORA_SID). you can export the subset of a table data. you have to specify the same FILESIZE limit. During an import.6) performs an export of the database. Export New Features in 8i In 8i. The script uses the Unix commands split and compress to perform splitting and compressing of the files. New features in 8I allow you to split the export file into multiple files. By using the QUERY parameter.5. This overcomes the 2GB file system limitations of export command operating systems. Oracle introduced two new export parameters called FILESIZE and QUERY. Listing 3. Can't perform export " } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_cleanup(): Cleanup interim files #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_cleanup() { rm –f ${PIPE_DEVICE} rm –f ${SPLIT_PIPE_DEVICE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_splitcompress_pipe(): Creates pipe for compressing and splitting of file #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: . SID is the instance to be backed up. and OWNER is the Unix account under which Oracle is running. The split export script takes two input parameters—SID and OWNER. The functions of the script are explained in Figure 3. if the export file is larger than 2GB. This is the only way to split the export file prior to Oracle 8i.6 splitZxport_ux ###################################################################### # PROGRAM NAME: splitZxport_ux # # PURPOSE: Performs export of the database # Compresses the export file on the fly while splitting. Owner($ORA_OWNER). the script compresses the export file and splits into multiple files to overcome the export limitation of a 2GB file system size.Split Export The split export program (see Listing 3. but it does not compress the files on-the-fly to save space. when using split export files. # Useful if the size of export file goes beyond 2GB # USAGE: $splitZxport_ux SID OWNER # INPUT PARAMETERS: SID(Instance name). Additionally.

log">>${PARFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_export(): Export the database #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_export() { # Remove old export file rm -f ${ZFILE} ${ORACLE_HOME}/bin/exp parfile=${PARFILE} if [ $? != 0 ]. then /etc/mknod ${SPLIT_PIPE_DEVICE} p fi # Splits the file for every 500MB # As it splits it adds aa.t1">>${PARFILE} echo "Grants=Y">>${PARFILE} echo "Indexes=Y">>${PARFILE} echo "Rows=Y">>${PARFILE} echo "Constraints=Y">>${PARFILE} echo "Compress=N">>${PARFILE} echo "Consistent=Y">>${PARFILE} echo "File=${PIPE_DEVICE}">>${PARFILE} echo "Log=${EXPORT_DIR}/${ORA_SID}.log funct_cleanup exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_parm(): Check for input parameters #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_parm() { if [ ${NARG} -ne 2 ].exp..funct_splitcompress_pipe() { # Creates pipe for compressing if [ ! -r ${PIPE_DEVICE} ].. Export Failed" >> $LOGDIR/${ORA_SID}. Not enough arguments passed" exit 1 . then /etc/mknod ${PIPE_DEVICE} p fi #Creates pipe for splitting if [ ! -r ${SPLIT_PIPE_DEVICE} ]. then echo "EXPORT_FAIL: ${ORA_SID}.bb.${ZFILE} < ${SPLIT_PIPE_DEVICE} & nohup compress < ${PIPE_DEVICE} >${SPLIT_PIPE_DEVICE} & } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_build_parfile(): Creates parameter file #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_build_parfile() { # This line makes sure that it always creates a new parameter file echo " " >${PARFILE} echo "userid=system/manager">>${PARFILE} echo "Full=Y">>${PARFILE} #echo "tables=scott. zz to the name nohup split -b1000m . then echo ´date´ >> $LOGDIR/${ORA_SID}.cc .log echo "EXPORT_FAIL: ${ORA_SID}.

fi if [ ! -d ${DYN_DIR} ].log exit 1 fi } ####################################### ## MAIN ####################################### NARG=$# ORA_SID=$1 ORA_OWNER=$2 # Set up environment BACKUPDIR="/u02/${ORA_SID}/export" ORATABDIR=/etc/oratab TOOLS="/u01/oracomn/admin/my_dba" DYN_DIR="${TOOLS}/DYN_FILES" PARFILE="${DYN_DIR}/export.log echo "EXPORT_FAIL: ${1} " >> ${LOGDIR}/${ORA_SID}.dmp.fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_bkup_dir(): Create backup directories if not already existing #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_bkup_dir() { EXPORT_DIR=${BACKUPDIR} if [ ! -d ${EXPORT_DIR} ].Z" } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_get_vars(): Get environment variables #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_get_vars(){ ORA_HOME=´sed /#/d ${ORATABDIR}|grep -i ${ORA_SID}|nawk -F ":" '{print $2}'´ ORA_BASE=´echo ${ORA_HOME}|nawk -F "/" '{for (i=2. ${ORA_SID}" funct_chk_parm .. then echo "´date´" >> ${LOGDIR}/${ORA_SID}. fi if [ ! -d ${LOGDIR} ]..par" LOGDIR="${TOOLS}/localog" PIPE_DEVICE="/tmp/export_${ORA_SID}_pipe" SPLIT_PIPE_DEVICE="/tmp/split_${ORA_SID}_pipe" echo ". export ORACLE_HOME ORACLE_SID=${ORA_SID}. i<=NF-2.. Now exporting . then mkdir -p ${DYN_DIR}. fi ZFILE="${EXPORT_DIR}/${ORA_SID}. then mkdir -p ${EXPORT_DIR}. then mkdir -p ${LOGDIR}... export ORACLE_SID } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_unix_command_status(): Check exit status of Unix command #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_unix_command_status() { if [ $? != 0 ]. i++) print "/"$i}'´ ORACLE_BASE=´echo $ORA_BASE|tr -d " "´ ORACLE_HOME=${ORA_HOME}.

Owner($ORA_OWNER). compress and split are Unix commands. cc..7 splitZmport_ux ###################################################################### # PROGRAM NAME: splitZmport_ux # PURPOSE: Performs import of the database using export files created by #splitZxport program. Uncompresses the dump file on the fly while desplitting.funct_get_vars funct_verify funct_chk_bkup_dir funct_splitcompress_pipe funct_build_parfile funct_export funct_cleanup echo ´date´ >> $LOGDIR/${ORA_SID}. The output of split command is passed to a file.log echo "${ORA_SID}. # USAGE: $splitZmport_ux SID OWNER # INPUT PARAMETERS: SID(Instance name). it appends aa. The export dump file is passed to the compress pipe for compression.7) performs an import using the compressed split export dump files created by the splitZxport program. bb. Split Import The split import program (see Listing 3. and the output of the compress command is passed to the split command for the split operation. and OWNER is the Unix account under which Oracle is running. The split command splits the dump file into pieces of 1000MB. funct_build_parfile() In building the parameter file. we pass the pipe name as a filename to the export command. The pipe acts as a medium to transfer output from one command to another. SID is the instance to be backed up.log ####################### END MAIN ############################### Split Export Script under Unix Checklist The checklist of things to verify before the splitZxport is run is the same as for the export program. Listing 3. • funct_splitcompress_pipe() This • function creates two pipes—one for compressing and another for splitting.zz to the name of the original file to maintain different names for individual pieces. export completed successfully" >> $LOGDIR/${ORA_SID}. When the split operation occurs.. OWNER(Owner of instance) ###################################################################### #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_verify(): Verify that database is online #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_verify(){ STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´ funct_chk_unix_command_status "Database is down for given SID($ORA_SID). Can't perform impot" } . The script takes two input parameters—SID and OWNER.

then /etc/mknod ${PIPE_DEVICE} p fi #Creates pipe for desplitting if [ ! -r ${SPLIT_PIPE_DEVICE} ].imp. then echo ´date´ >> $LOGDIR/${ORA_SID}.t4">>${PARFILE} echo "Full=Y">>${PARFILE} echo "Ignore=Y">>${PARFILE} echo "Commit=y">>${PARFILE} echo "File=${PIPE_DEVICE}">>${PARFILE} echo "Log=${BACKUPDIR}/${ORA_SID}.ddl">>${PARFILE} #echo "Owner=scott">>${PARFILE} #echo "Fromuser=kishan">>${PARFILE} #echo "Touser=aravind">>${PARFILE} #echo "Tables=T1.T2.log echo "IMPORT_FAIL: ${ORA_SID}.log funct_cleanup . Import Failed" >> $LOGDIR/${ORA_SID}.log">>${PARFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_import(): Import the database #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_import() { ${ORACLE_HOME}/bin/imp parfile=${PARFILE} if [ $? != 0 ]. then /etc/mknod ${SPLIT_PIPE_DEVICE} p fi nohup sleep nohup sleep } cat ${ZFILES} > ${SPLIT_PIPE_DEVICE} & 5 uncompress < ${SPLIT_PIPE_DEVICE} >${PIPE_DEVICE} & 30 #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_build_parfile(): Creates parameter file #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_build_parfile() { # This line makes sure that it always creates a new parameter file echo " " >${PARFILE} echo "userid=system/manager">>${PARFILE} #echo "indexfile=${BACKUPDIR}/${ORA_SID}.#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_cleanup(): Cleanup interim files #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_cleanup() { rm –f ${PIPE_DEVICE} rm –f ${SPLIT_PIPE_DEVICE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_desplitcompress_pipe(): Creates pipe for uncompressing and desplitting of file #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_desplitcompress_pipe() { # Creates pipe for uncompressing if [ ! -r ${PIPE_DEVICE} ].t3.

log exit 1 fi } ####################################### ## MAIN ####################################### NARG=$# ORA_SID=$1 ORA_OWNER=$2 # Set up environment BACKUPDIR="/u02/${ORA_SID}/export" ORATABDIR=/etc/oratab TOOLS="/u01/oracomn/admin/my_dba" . then mkdir -p ${DYN_DIR}.fi } exit 1 #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_parm(): Check for input parameters #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_parm() { if [ ${NARG} -ne 2 ].log echo "IMPORT_FAIL: ${1} " >> ${LOGDIR}/${ORA_SID}. Not enough arguments passed" exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_bkup_dir(): Check for backup directories #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_bkup_dir() { if [ ! -d ${DYN_DIR} ]. fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_get_vars(): Get environment variables #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_get_vars(){ ORA_HOME=´sed /#/d ${ORATABDIR}|grep -i ${ORA_SID}|nawk -F ":" '{print $2}'´ ORA_BASE=´echo ${ORA_HOME}|nawk -F "/" '{for (i=2. i++) print "/"$i}'´ ORACLE_BASE=´echo $ORA_BASE|tr -d " "´ ORACLE_HOME=${ORA_HOME}. export ORACLE_HOME ORACLE_SID=${ORA_SID}. then echo "´date´" >> ${LOGDIR}/${ORA_SID}. export ORACLE_SID } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_unix_command_status(): Check exit status of Unix command #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_unix_command_status() { if [ $? != 0 ]. i<=NF-2. fi if [ ! -d ${LOGDIR} ]. then mkdir -p ${LOGDIR}. then echo "IMPORT_FAIL: ${ORA_SID}.

export NLS_LANG echo ". set the correct values for the BACKUPDIR. Backing up software is also a very important part of a backup strategy. If not already there. We have already discussed how to back up the database.par" LOGDIR="${TOOLS}/localog" PIPE_DEVICE="/tmp/import_${ORA_SID}_pipe" SPLIT_PIPE_DEVICE="/tmp/split_${ORA_SID}_pipe" NLS_LANG=AMERICAN_AMERICA.. That is accomplished by creating two pipes. you must add the instance. Check for the existence of the SID in the oratab file.dmp. You can modify the settings to perform a user or table import. The output from the uncompress command is sent to the Oracle import command.# List all split files in ZFILES variable #ZFILES=´echo ${BACKUPDIR}/file. Here. import completed successfully" >> $LOGDIR/${ORA_SID}. cat and uncompress are Unix commands.log ####################### END MAIN ############################### SplitImport Script under Unix Checklist • • • • In the main() function. ${ORA_SID}" funct_chk_parm funct_get_vars funct_verify funct_chk_bkup_dir funct_desplitcompress_pipe funct_build_parfile funct_import funct_cleanup echo ´date´ >> $LOGDIR/${ORA_SID}. Now importing . The software might not need to be backed up as often as the database because it does not change quite as often. Everything else is the same as a regular import.WE8ISO8859P1. The default location of ORATABDIR is different for each flavor of Unix. or before you apply any patches to existing software. The split pipe device is passed to the uncompress command.dmp.dmp.... funct_desplitcompress_pipe() The Oracle Software Backup This section discusses backing up the software directories of Oracle. By default.Zab" DYN_DIR="${TOOLS}/DYN_FILES" PARFILE="${DYN_DIR}/import. it performs a full import.log echo "${ORA_SID}. it is important to make a backup copy of it to avoid getting into trouble. The funct_build_parfile() function builds the parameter file.Z??|sort´ ZFILES="${BACKUPDIR}/file. we use the cat command to send output from split files to the split pipe device. List all split filenames in the ZFILES variable in the main() function. But as you upgrade. . and TOOLS variables highlighted in the import script.Zaa ${BACKUPDIR}/file. Pass SID and OWNER as parameters to the program: only trick here is that we need to split and uncompress the files before we use them as input to import command.. ORATABDIR.

SID is the instance to be backed up. then echo "´date´" >> ${LOGFILE} echo "SOFTWAREBACKUP_FAIL: ${ORA_SID}." |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_shutdown_i(): Shutdown database in Immediate mode #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_shutdown_i(){ ${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba shutdown immediate. The script takes two input parameters—SID and OWNER. Listing 3. exit EOF } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_software_bkup(): Backup software #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_software_bkup(){ . exit EOF } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_startup_n(): Startup database in normal mode #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_startup_n(){ ${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba startup.8 OraSoftware_ux ##################################################################### # PROGRAM NAME: OraSoftware_ux # PURPOSE: Backup ORACLE_HOME & ORACLE_BASE # USAGE: $OraSoftware_ux SID OWNER # INPUT PARAMETERS: SID(Instance name). and OWNER is the Unix account under which Oracle is running. OWNER(Owner of instance) ##################################################################### #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_verify_shutdown(): Verify that database is down #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_verify_shutdown(){ STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´ if [ $? = 0 ]. Database is up.Listing 3.8 contains the script to perform a backup of Oracle software. can't do software backup if the database is online.

${ORA_BASE} | compress > ${ORABASEFILE} 2> ${BACKUPLOGFILE} #Prepare restore file echo "zcat ${ORAHOMEFILE}| tar xvlpf .echo "tarring ${ORA_HOME}" >> ${BACKUPLOGFILE} echo "tarring ${ORA_BASE}" >> ${BACKUPLOGFILE} nohup tar cvlpf .${ORA_BASE}" >> ${RESTOREFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_parm(): Check for input parameters #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_parm() { if [ ${NARG} -ne 2 ].${ORA_HOME} | compress > ${ORAHOMEFILE} 2> ${BACKUPLOGFILE} nohup tar cvlpf . then mkdir -p ${LOGDIR}. Not enough arguments passed" exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_bkup_dir(): Create backup directories if not already exist #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_bkup_dir() { RESTOREFILE_DIR="${BACKUPDIR}/restorefile_dir" BACKUPLOG_DIR="${BACKUPDIR}/backuplog_dir" SOFTWARE_DIR="${BACKUPDIR}/software_dir" BACKUPLOGFILE="${BACKUPLOG_DIR}/backup_log_${ORA_SID}" RESTOREFILE="${RESTOREFILE_DIR}/restorefile_${ORA_SID}" ORAHOMEFILE="${SOFTWARE_DIR}/orahome_${ORA_SID}. fi if [ ! -d ${BACKUPLOG_DIR} ].Z" ORABASEFILE="${SOFTWARE_DIR}/orabase_${ORA_SID}.log" if [ ! -d ${RESTOREFILE_DIR} ].${ORA_HOME}" > ${RESTOREFILE} echo "zcat ${ORABASEFILE}| tar xvlpf .Z" LOGFILE="${LOGDIR}/${ORA_SID}. then mkdir -p ${RESTOREFILE_DIR}. fi if [ ! -d ${LOGDIR} ]. then mkdir -p ${DYN_DIR}.tar. then echo "SOFTWAREBACKUP_FAIL: ${ORA_SID}. fi # Remove old files rm -f ${RESTOREFILE_DIR}/* rm -f ${BACKUPLOG_DIR}/* rm -f ${SOFTWARE_DIR}/* echo "${JOBNAME}: software backup of ${ORA_SID} begun on ´date +\"%c\"´ " >> ${BACKUPLOGFILE} } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_get_vars(): Get environment variables #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_get_vars(){ ORA_HOME=´sed /#/d ${ORATABDIR}|grep -i ${ORA_SID}|nawk -F ":" '{print $2}'´ ORA_BASE=´echo ${ORA_HOME}|nawk -F "/" '{for (i=2. then mkdir -p ${SOFTWARE_DIR}. i++) print "/"$i}'´ ORACLE_BASE=´echo $ORA_BASE|tr -d " "´ init_file=$ORA_HOME/dbs/init$ORA_SID. fi if [ ! -d ${DYN_DIR} ].ora . i<=NF-2.tar. then mkdir -p ${BACKUPLOG_DIR}. fi if [ ! -d ${SOFTWARE_DIR} ].

export ORACLE_SID if [ x$ORA_HOME = 'x' ]. . Software Backup Completed successfully on ´date +\"%c\"´ " |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} ######## END MAIN ######################### Oracle Software Backup Script under Unix Checklist • In the main function. then echo "´date´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE} echo "SOFTWAREBACKUP_FAIL: ${1}"| tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi } ############################################################ ## MAIN ############################################################ NARG=$# ORA_SID=$1 ORA_OWNER=$2 # Set environment variables BACKUPDIR="/u02/${ORA_SID}/software" ORATABDIR=/etc/oratab TOOLS="/u01/oracomn/admin/my_dba" DYN_DIR="${TOOLS}/DYN_FILES" LOGDIR="${TOOLS}/localog" JOBNAME="orasoftware" echo "Preparing to make software backup of ${ORA_SID}" funct_chk_parm funct_chk_bkup_dir funct_get_vars funct_shutdown_i funct_verify_shutdown funct_software_bkup funct_startup_n echo "${ORA_SID}. The default location of ORATABDIR is different for each flavor of Unix. Used by funct_startup_n to start database"|tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # funct_chk_unix_command_status(): Check the exit status of Unix command #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: funct_chk_unix_command_status() { if [ $? != 0 ]. ORATABDIR. then echo "SOFTWAREBACKUP_FAIL: int$ORA_SID. export ORACLE_HOME ORACLE_SID=${ORA_SID}. then echo "SOFTWAREBACKUP_FAIL: Can't get ORACLE_HOME from oratab for $ORA_SID"| tee -a ${BACKUPLOGFILE} >> ${LOGFILE} exit 1 fi if [ ! -f $init_file ].ora does not exist in ORACLE_HOME/dbs. and TOOLS variables highlighted in the software backup script.ORACLE_HOME=${ORA_HOME}. set correct values for BACKUPDIR.

and 'Software Backup Completed'.Z | tar xvlpf . we use the DOS Shell batch programming techniques to automate the backup process. Pass SID and OWNER as parameters to the program: • funct_software_bkup() This function tars the software directories of ORACLE_HOME ORACLE_BASE and compresses the output using the compress command. zcat ora_home. Restoring Oracle Software The steps to restore the software are as follows: 1. it restarts the database. After the backup is complete. if the backup completes successfully. For example. This is a very good place to start investigating why a backup has failed or for related errors. 'nohup' commands submit the tar command at the server. it is important to check the backup status by reviewing log and error files generated by the scripts. set ORA_BASE and ORA_HOME manually in funct_get_vars(). if the software backup failed. it shuts down the database and starts backing up the software directories. Here. When the backup is complete.Z: /oracle/ora81: File to extract Destination directory Backup and Recovery under Windows NT Before reading through this section. successfully'./oracle/ora81 ora_home. I strongly recommend that you go through the Windows NT programming section in Chapter 2. Start up the database.tar. This section presents and explains the scripts for taking a backup and recovering a database in the Windows NT environment. you have to manually set ORA_BASE and ORA_HOME in the funct_get_vars() function. If your Oracle software directory structure does not follow OFA guidelines. you must add the instance.tar. This file will also have the start and end time of backup. Here. .• • Check for the existence of the SID in the oratab file. A single line about the success or failure of backup is appended to SID. If not already there. The messages for a software backup are 'SOFTWAREBACKUP_FAIL'. main() If the database is running. If not. we are and • assuming that the Oracle software is installed using OFA (optimal Flexible Architecture) guidelines. The restore command in the restore file first does a zcat (uncompress and cat) of the output file and passes it to tar for extraction. Use restore file from the backup to restore the directories. This file is located under the directory defined by the LOGDIR variable. Shutdown database. 3. 2.log file every time backup is performed. Troubleshooting and status check: The important thing here is that the backup log file defined by BACKUPLOGFILE contains detailed information about each step of the backup process.

6 shows the functionality of a cold backup program under Windows NT. the instance to be backed up. Each box represents a corresponding section in the program. Listing 3. For example. as the input parameter.bat REM PURPOSE: This utility performs cold backup of REM the database on Windows NT REM USAGE: c:\>coldbackup_nt.9 performs a cold backup of a database under the Windows NT environment. The cold backup script takes SID. Figure 3.ora set TOOLS=c:\oracomn\admin\my_dba set LOGDIR=%TOOLS%\localog set LOGFILE=%LOGDIR%\%ORACLE_SID%.log set set set set CFILE=%BACKUP_DIR%\log\coldbackup.bat @echo off REM ############################################################## REM PROGRAM NAME: coldbackup_nt.log BKP_DIR=%BACKUP_DIR% .bat SID REM INPUT PARAMETERS: SID (Instance name) '' REM ############################################################### REM ::::::::::::::::::::Begin Declare Variables Section set ORA_HOME=c:\oracle\ora81\bin set CONNECT_USER="/ as sysdba" set ORACLE_SID=%1 set BACKUP_DIR=c:\backup\%ORACLE_SID%\cold set INIT_FILE=c:\oracle\admin\orcl\pfile\init. The general steps to write a backup script in Unix and Windows NT are the same.Cold Backup Listing 3. The only difference is that we will be using commands that are understood by Windows NT.9 coldbackup_nt. the Parameter Checking section checks for the necessary input parameters and also checks for the existence of the backup directories.log LOG_FILE=%BACKUP_DIR%\log\cbackup.sql ERR_FILE=%BACKUP_DIR%\log\cerrors.

> %LOG_FILE% (echo Cold Backup started & date/T & time/T) >> %LOG_FILE% echo Parameter Checking Completed >> %LOG_FILE% REM :::::::::::::::::::: End Parameter Checking Section REM :::::::::::::::::::: Begin Create Dynamic files Section echo. >>%CFILE% echo exec dbms_output. >%CFILE% echo set termout off heading off feedback off >>%CFILE% echo set linesize 300 pagesize 0 >>%CFILE% echo set serveroutput on size 1000000 >>%CFILE% echo. >>%CFILE% echo exec dbms_output. >>%CFILE% echo exec dbms_output. >>%CFILE% echo. >>%CFILE% echo select 'copy '^|^| file_name^|^| ' %BKP_DIR%\data ' >>%CFILE% echo from dba_data_files order by tablespace_name.put_line('REM ******Init. > %ERR_FILE% echo.ora file ' ). >>%CFILE% echo select 'copy '^|^| name^|^| ' %BKP_DIR%\control ' >>%CFILE% echo from v$controlfile order by name.put_line('REM ******Control files' ). >>%CFILE% echo spool off >>%CFILE% echo exit >>%CFILE% echo Dynamic files Section Completed >> %LOG_FILE% REM :::::::::::::::::::: End Create Dynamic files Section REM :::::::::::::::::::: Begin ColdBackup Section .REM :::::::::::::::::::: End Declare Variables Section REM :::::::::::::::::::: Begin Parameter Checking Section if "%1" == " goto usage REM Create backup directories if already not exist if not exist %BACKUP_DIR%\data mkdir %BACKUP_DIR%\data if not exist %BACKUP_DIR%\control mkdir %BACKUP_DIR%\control if not exist %BACKUP_DIR%\redo mkdir %BACKUP_DIR%\redo if not exist %BACKUP_DIR%\log mkdir %BACKUP_DIR%\log if not exist %LOGDIR% mkdir %LOGDIR% REM Check to if not exist if not exist if not exist if not exist see that there were no create errors %BACKUP_DIR%\data goto backupdir %BACKUP_DIR%\control goto backupdir %BACKUP_DIR%\redo goto backupdir %BACKUP_DIR%\log goto backupdir REM Deletes previous backup. del/q %BACKUP_DIR%\data\* del/q %BACKUP_DIR%\control\* del/q %BACKUP_DIR%\redo\* del/q %BACKUP_DIR%\log\* echo.put_line('@echo off' ). >>%CFILE% echo exec dbms_output. >>%CFILE% echo. >>%CFILE% echo exec dbms_output. >>%CFILE% echo select ' copy %INIT_FILE% %BKP_DIR%\control ' >>%CFILE% echo from dual. Make sure you have it on tape.').put_line('REM ******Data files' ). >>%CFILE% echo.put_line('exit.bat >>%CFILE% echo. >>%CFILE% echo spool %BACKUP_DIR%\log\coldbackup_list.

A single line about the success or failure of backup is appended to the SID. pass SID as a parameter. Define the INIT_FILE variable to the location of the Init. Verify that CONNECT_USER is set to correct the username and password. This file is located under the directory defined by the LOGDIR variable. . if the cold backup failed.sql (echo ColdBackup Completed Successfully & date/T & time/T) >> %LOG_FILE% (echo ColdBackup Completed Successfully & date/T & time/T) >> %LOGFILE% goto end REM :::::::::::::::::::: End ColdBackup Section REM :::::::::::::::::::::::::::: Begin Error handling section :usage echo Error. This is a very good place to start investigating why a backup has failed or for related errors. The messages for a cold backup are 'COLDBACKUP_FAIL'. Usage: coldbackup_nt. and TOOLS are set to correct values according to your directory structure. Be sure that the user running the program has Write access to backup directories.sql @shutdown_n_nt.bat 1>> %LOG_FILE% 2>> %ERR_FILE% %ORA_HOME%\sqlplus -s %CONNECT_USER% @startup_n_nt.sql @startup_r_nt.log file every time a backup is performed. BACKUP_DIR. ERR_FILE has error information.bat SID goto end :backupdir echo Error creating Backup directory structure >> %ERR_FILE% (echo COLDBACKUP_FAIL:Error creating Backup directory structure & date/T & time/T) >> %LOGFILE% REM :::::::::::::::::::: End Error handling section REM :::::::::::::::::::: Cleanup Section :end set ORA_HOME= set ORACLE_SID= set CONNECT_USER= set BACKUP_DIR= set INIT_FILE= set CFILE= set ERR_FILE= set LOG_FILE= set BKP_DIR= Cold Backup Script for Windows NT Checklist • • • • • Check to see that ORA_HOME.sql REM Copy the files to backup location start/b %BACKUP_DIR%\log\coldbackup_list. This file will also have the start and end time of backup. and 'Cold Backup Completed successfully'.%ORA_HOME%\sqlplus %ORA_HOME%\sqlplus %ORA_HOME%\sqlplus %ORA_HOME%\sqlplus -s -s -s -s %CONNECT_USER% %CONNECT_USER% %CONNECT_USER% %CONNECT_USER% @%CFILE% @shutdown_i_nt. Cold Backup under Windows NT Troubleshooting and Status Check Backup log files defined by LOG_FILE contain detailed information about each step of the backup process. When you run the program. These variables are highlighted in the script. if the backup completes successfully.ora file.

select ' copy c:\oracle\admin\orcl\pfile\init. as shown in the following: at 23:00 "c:\backup\coldbackup_nt.10 coldbackup.put_line('@echo off' ).put_line('REM ******Control files' ).bat program.DBF c:\backup\orcl\cold\data copy C:\ORADATA\SYSTEM01.bat @echo off REM ******Data files copy C:\ORADATA\DSGN01. A sample coldbackup. This is only a sample file.sql file (see Listing 3. at 23:00 /every:M. Listing 3. select 'copy '|| name|| ' c:\backup\orcl\cold\control from v$controlfile order by name.bat exec dbms_output.DBF c:\backup\orcl\cold\data copy C:\ORADATA\USERS01. control. control. The contents of this file are derived based on the structure of the database.11).sql file is called from the coldbackup_nt.11 coldbackup_list. spool offexit ' ' When the coldbackup. exec dbms_output. coldbackup.You can schedule automatic backups using the 'at' command. exec dbms_output.put_line('exit.bat DOS batch file (see Listing 3. This file has the commands necessary for performing the cold backup.bat ORCL" Runs at 23:00 hrs on current date.sql is shown in Listing 3.sql is called from coldbackup_nt. Tuesday. it spools output to the coldbackup_list.bat program creates the coldbackup. Wednesday.ora file ' ). and Init.'). select 'copy '|| file_name|| ' c:\backup\orcl\cold\data from dba_data_files order by tablespace_name.bat ORCL " This command runs a backup at 23:00 hours every Monday.F "c:\backup\coldbackup_nt. and redo log files to be backed up from the database. and Friday.Th.put_line('REM ******Init.DBF c:\backup\orcl\cold\data copy C:\ORADATA\INDX01.W.10) under the log directory.T.10 for your understanding.ora c:\backup\orcl\cold\control ' from dual.DBF c:\backup\orcl\cold\data copy C:\ORADATA\RBS01.DBF c:\backup\orcl\cold\data copy C:\ORADATA\TEMP01. exec dbms_output.sql set termout off heading off feedback off set linesize 300 pagesize 0 set serveroutput on size 1000000 spool c:\backup\orcl\cold\log\coldbackup_list. Listing 3. The "Create Dynamic Files" section in the coldbackup_nt.DBF c:\backup\orcl\cold\data copy C:\ORADATA\OEM01. redo log. exec dbms_output. Thursday.put_line('REM ******Data files' ). Note that in the contents of file data.DBF c:\backup\orcl\cold\data .bat and generates a list of data.ora files are copied to respective backup directories.

ora ARC_DEST=c:\oracle\oradata\orcl\archive set TOOLS=c:\oracomn\admin\my_dba set LOGDIR=%TOOLS%\localog set LOGFILE=%LOGDIR%\%ORACLE_SID%.12) performs a hot backup of a database under the Windows NT environment. The hot backup script takes SID.log set BKP_DIR=%BACKUP_DIR% REM :::::::::::::::::::: End Declare Variables Section REM :::::::::::::::::::: Begin Parameter Checking Section if "%1" == " goto usage REM Create if not exist if not exist if not exist if not exist if not exist backup directories if already not exist %BACKUP_DIR%\data mkdir %BACKUP_DIR%\data %BACKUP_DIR%\control mkdir %BACKUP_DIR%\control %BACKUP_DIR%\arch mkdir %BACKUP_DIR%\arch %BACKUP_DIR%\log mkdir %BACKUP_DIR%\log %LOGDIR% mkdir %LOGDIR% REM Check to see that there were no create errors if not exist %BACKUP_DIR%\data goto backupdir if not exist %BACKUP_DIR%\control goto backupdir if not exist %BACKUP_DIR%\arch goto backupdir if not exist %BACKUP_DIR%\log goto backupdir .sql set ERR_FILE=%BACKUP_DIR%\log\herrors.log set HFILE=%BACKUP_DIR%\log\hotbackup.bat @echo off REM ##################################################################### REM PROGRAM NAME: hotbackup_nt. as the input parameter.12 hotbackup_nt.ora c:\backup\orcl\cold\control exit. Listing 3.ora file copy c:\oracle\admin\orcl\pfile\init.bat REM PURPOSE: This utility performs hot backup of REM the database on Windows NT REM USAGE: c:\>hotbackup_nt.CTL c:\backup\orcl\cold\control REM ******Init.REM ******Control files copy C:\ORADATA\CONTROL01.log set LOG_FILE=%BACKUP_DIR%\log\hbackup.CTL c:\backup\orcl\cold\control copy C:\ORADATA\CONTROL02.bat SID REM INPUT PARAMETERS: SID (Instance name) '' REM ##################################################################### REM :::::::::::::::::::: Begin Declare Variables Section set set set set set set ORA_HOME=c:\oracle\ora81\bin CONNECT_USER="/ as sysdba" ORACLE_SID=%1 BACKUP_DIR=c:\backup\%ORACLE_SID%\hot INIT_FILE=c:\oracle\admin\orcl\pfile\init. the instance to be backed up. Hot Backup The hot backup program (see Listing 3.

put_line(chr(10) ).sql >>%HFILE% echo Declare >>%HFILE% echo cursor c1 is select distinct tablespace_name from dba_data_files order by tablespace_name. >>%HFILE% echo.tablespace_name) loop >>%HFILE% echo dbms_output.put_line(chr(10) ). >>%HFILE% echo dbms_output. >>%HFILE% echo dbms_output. >>%HFILE% echo dbms_output. >>%HFILE% echo. Make sure you have it on tape.'). >>%HFILE% echo dbms_output.'). >>%HFILE% echo dbms_output.put_line(' host copy '^|^|dbf. del/q %BACKUP_DIR%\data\* del/q %BACKUP_DIR%\control\* del/q %BACKUP_DIR%\arch\* del/q %BACKUP_DIR%\log\* echo. >>%HFILE% echo dbms_output.'). >>%HFILE% echo.tablespace_name ^|^|' begin backup. >>%HFILE% echo dbms_output.put_line(' alter system switch logfile.'). >>%HFILE% echo dbms_output.put_line(' alter database backup controlfile to '^|^| ''^|^|'%BKP_DIR% \control\coltrol_file.put_line('host REM ******Data files' ).put_line('set termout off heading off feedback off').').put_line(' host copy %INIT_FILE% %BKP_DIR%\control 1^>^> %LOG_FILE% 2^>^> %ERR_FILE%').put_line('host REM ******Init. >>%HFILE% echo dbms_output.ora file ' ). >>%HFILE% echo dbms_output. >>%HFILE% echo end loop. >>%HFILE% echo for dbf in c2(tbs. >>%HFILE% echo dbms_output. > %LOG_FILE% (echo Hot Backup started & date/T & time/T) >> %LOG_FILE% echo Parameter Checking Completed >> %LOG_FILE% REM :::::::::::::::::::: End Parameter Checking Section REM :::::::::::::::::::: Begin Create Dynamic files Section echo.put_line(' alter system archive log stop.put_line(' alter database backup controlfile to trace. >%HFILE% echo set termout off heading off feedback off >>%HFILE% echo set linesize 300 pagesize 0 >>%HFILE% echo set serveroutput on size 1000000 >>%HFILE% echo spool %BACKUP_DIR%\log\hotbackup_list. >>%HFILE% echo cursor c2( ptbs varchar2) is select file_name from dba_data_files where tablespace_name = ptbs order by file_name.'). >>%HFILE% echo for tbs in c1 loop >>%HFILE% echo dbms_output.put_line('host REM ******Control files ' ).REM Deletes previous backup. > %ERR_FILE% echo.put_line('host move %ARC_DEST%\* %BKP_DIR%\arch . >>%HFILE% echo dbms_output. >>%HFILE% echo.tablespace_name ^|^|' end backup.ctl'^|^|''^|^|'. >>%HFILE% echo dbms_output. >>%HFILE% echo dbms_output.put_line(chr(10) ). >>%HFILE% echo dbms_output. >>%HFILE% echo end loop.file_name^|^|' %BKP_DIR%\data 1^>^> %LOG_FILE% 2^>^> %ERR_FILE%').put_line('host REM ******Archivelog files' ).put_line(chr(10) ).put_line(' alter tablespace '^|^|tbs.put_line(' alter tablespace '^|^| tbs. >>%HFILE% echo Begin >>%HFILE% echo dbms_output.

ora file. Define the ARC_DEST variable to the location archive destination.'). End.'). These variables are highlighted in the script. The sections and their purposes in the program are the same as for a cold backup.bat SID goto end :backupdir echo Error creating Backup directory structure >> %ERR_FILE% (echo HOTBACKUP_FAIL:Error creating Backup directory structure & date/T & time/T) >> %LOGFILE% REM :::::::::::::::::::: End Error handling section REM :::::::::::::::::::: Cleanup Section :end set ORA_HOME= set ORACLE_SID= set CONNECT_USER= set BACKUP_DIR= set INIT_FILE= set ARC_DEST= set HFILE= set ERR_FILE= set LOG_FILE= set BKP_DIR= Hot backup program functionality can be shown with the similar diagram as for a cold backup. BACKUP_DIR. Hot Backup Script under Windows NT Checklist • • • • • Check to see that ORA_HOME. Usage: hotbackup_nt. >>%HFILE% / >>%HFILE% spool off >>%HFILE% exit. Define the INIT_FILE variable to the location of the Init. . Verify that CONNECT_USER is set to the correct username and password.put_line('exit. Be sure that the user running the program has Write access to the backup directories. >>%HFILE% echo echo echo echo echo dbms_output. >>%HFILE% echo dbms_output.put_line(' alter system archive log start.sql (echo HotBackup Completed Successfully & date/T & time/T) >> %LOG_FILE% (echo HotBackup Completed Successfully & date/T & time/T) >> %LOGFILE% goto end REM :::::::::::::::::::: End HotBackup Section REM :::::::::::::::::::: Begin Error handling section :usage echo Error. >>%HFILE% >>%HFILE% echo Dynamic files Section Completed >> %LOG_FILE% REM :::::::::::::::::::: End Create Dynamic files Section REM :::::::::::::::::::: Begin HotBackup Section %ORA_HOME%\sqlplus -s %CONNECT_USER% @%HFILE% REM Copy the files to backup location %ORA_HOME%\sqlplus -s %CONNECT_USER% @%BACKUP_DIR%\log\hotbackup_list.1^>^> %LOG_FILE% 2^>^> %ERR_FILE%' ). and TOOLS are set to the correct values according to your directory structure.

ERR_FILE has error information. dbms_output.put_line(' host copy '||dbf. dbms_output.put_line(' alter database backup controlfile to trace.put_line(' alter database backup controlfile to '|| ''||'c:\backup\orcl\hot\control\coltrol_file. dbms_output.13 hotbackup.tablespace_name || ' end backup. if a backup completes successfully. if a hot backup failed.put_line(' alter system archive log stop. It is called from the hotbackup_nt.log 2>> herrors. pass SID as a parameter. for dbf in c2(tbs.'). and 'Hot Backup Completed successfully'. cursor c2( ptbs varchar2) is select file_name from dba_data_files where tablespace_name = ptbs order by file_name.put_line(chr(10) ).tablespace_name) loop dbms_output. control. Listing 3. dbms_output.log'). This is a very good place to start investigating why a backup has failed or for related errors.put_line(' alter system switch logfile. Begin dbms_output. The "Create Dynamic Files" section.log file every time a backup is performed. dbms_output. in the hotbackup_nt. dbms_output.• When you run the program. end loop.').sql set termout off heading off feedback off set linesize 300 pagesize 0 set serveroutput on size 1000000 spool c:\backup\orcl\hot\log\hotbackup_list.put_line('host REM ******Archivelog files' ). This file will also have the start and end time of backup. dbms_output.').bat program.put_line(chr(10) ). dbms_output.'). and redo log files from the database. dbms_output.put_line(chr(10) ).put_line(' alter tablespace '||tbs.').put_line('set termout off heading off feedback off').log 2>> herrors. data.put_line('host copy c:\oracle\admin\orcl\pfile\init.put_line('host REM ******Control files ' ).put_line('host REM ******Data files' ).file_name||' c:\backup\orcl\hot\data 1>> hbackup. end loop. dbms_output.put_line(' alter tablespace '|| tbs. This generates a list of tablespaces.log'). for tbs in c1 loop dbms_output. dbms_output. A single line about the success or failure of backup is appended to the SID. dbms_output.sql Declare cursor c1 is select distinct tablespace_name from dba_data_files order by tablespace_name.sql file (see Listing 3.put_line(chr(10) ). The messages for a hot backup are 'HOTBACKUP_FAIL'. .ora file ' ).'). Hot Backup under Windows NT Troubleshooting and Status Check The backup log file defined by LOG_FILE contains detailed information about each step of the backup process.tablespace_name ||' begin backup.put_line('host REM ******Init.bat creates the hotbackup. This file is located under the directory defined by the LOGDIR variable.ctl '||''||'.13) under the log directory. dbms_output.orac:\backup\orcl\hot\control 1>> hbackup. dbms_output.

alter database backup controlfile to trace. Listing 3. alter tablespace DESIGNER_INDX begin backup.bat and it spools output to the hotbackup_list. Listing 3. host REM ******Init. as shown in hotbackup_list.log alter system archive log start. In a real environment. The hotbackup.bat.log file. host REM ******Control files alter database backup controlfile to 'c:\hot\control\coltrol_file. and then turns off the Backup mode for that tablespace.log 2>> herrors.sql file is called from hotbackup_nt.DBF c:backup\orcl\hot\data 1>> hbackup. control. alter tablespace OEM_REPOSITORY begin backup. Because of this.put_line('exit.14). host copy C:\ORADATA\OEMREP01.log 2>> herrors. dbms_output.ora 1>> hbackup. host copy C:\ORADATA\DSGN_INDX01.').14 hotbackup_list. and Init. alter tablespace INDX begin backup.log 2>> herrors.logalter tablespace DESIGNER end backup. it puts the tablespace into Backup mode. End.log 2>> herrors. c:backup\orcl\hot\control c:\backup\orcl\hot\arch . Note in the file that the data. exit.sql. the database structure changes as more data files or tablespaces get added.dbms_output.ora files are copied to their respective backup directories.log host REM ******Archivelog files alter system switch logfile. It performs the actual backup and is called from hotbackup_nt. archive log.ctl'. alter system archive log stop. dbms_output. host copy C:\ORADATA\DSGN01.log 2>> herrors.put_line(' alter system archive log start.DBF c:backup\orcl\hot\data 1>> hbackup.sql set termout off heading off feedback off host REM ******Data files alter tablespace DESIGNER begin backup. copies the corresponding files to backup location.DBF c:backup\orcl\hot\data 1>> hbackup. This is only a sample file. it is important to generate the backup commands dynamically. host move c:\oracle\oradata\orcl\archive\* 1>> hbackup.'). host copy C:\ORADATA\INDX01. / spool off exit.sql SQL file (see Listing 3.DBF c:backup\orcl\hot\data 1>> hbackup.log alter tablespace OEM_REPOSITORY end backup. This file has the commands necessary for performing a hot backup.14 is generated based on the structure of the database. and each copy command puts the status of the copy operation to hbackup.log and reports any errors to the herrors.put_line('host move c:\oracle\oradata\orcl\archive\* c:\backup\orcl\hot\arch 1>> hbackup.ora file host copy c:\oracle\admin\orcl\pfile\init.log 2>> herrors.log2>> herrors.log alter tablespace DESIGNER_INDX end backup.log' ).log alter tablespace INDX end backup. First. This process is repeated for each tablespace.

Usage: coldbackup_nt.15) performs a full export of the database under a Windows NT environment. del/q %BACKUP_DIR%\* REM :::::::::::::::::::: End Parameter Checking Section REM :::::::::::::::::::: Begin Export Section %ORA_HOME%\exp %CONNECT_USER% parfile=export_par.txt (echo Export Completed Successfully & date/T & time/T) >> %LOGFILE% goto end REM :::::::::::::::::::: End Export Section REM :::::::::::::::::::: Begin Error handling section :usage echo Error. the instance to be backed up. as the input parameter.15 export_nt. The export script takes SID.bat SID REM INPUT PARAMETERS: SID (Instance name) '' REM ##################################################################### REM :::::::::::::::::::: Begin Declare Variables Section set set set set ORA_HOME=c:\oracle\ora81\bin ORACLE_SID=%1 CONNECT_USER=system/manager BACKUP_DIR=c:\backup\%ORACLE_SID%\export set TOOLS=c:\oracomn\admin\my_dba set LOGDIR=%TOOLS%\localog set LOGFILE=%LOGDIR%\%ORACLE_SID%.log REM :::::::::::::::::::: End Declare Variables Section REM :::::::::::::::::::: Begin Parameter Checking Section if "%1" == " goto usage REM Create backup directories if already not exist if not exist %BACKUP_DIR% mkdir %BACKUP_DIR% if not exist %LOGDIR% mkdir %LOGDIR% REM Check to see that there were no create errors if not exist %BACKUP_DIR% goto backupdir REM Deletes previous backup.bat SID goto end :backupdir . Make sure you have it on tape.bat REM PURPOSE: REM REM USAGE: This utility performs a full export of database on Windows NT c:\>export_nt.bat @echo off REM ##################################################################### REM PROGRAM NAME: export_nt. Listing 3.Export The export program (see Listing 3.

if the export completes successfully. hot backup.log file every time an export is performed.16 is a sample parameter file that performs a full export of the database. The messages for an export are 'EXPORT_FAIL'. TOOLS are set to correct values according to your directory structure. Export under Windows NT Troubleshooting and Status Check The log file specified in the parameter file contains detailed information about each step of the export process. Definitions • Control File—The control file contains records that describe and maintain information about the physical structure of a database. Be sure that the user running the program has Write access to the backup directories.echo Error creating Backup directory structure (echo EXPORT_FAIL:Error creating Backup directory structure & date/T & time/T) >> %LOGFILE% REM :::::::::::::::::::: End Error handling section REM ::::::::::::::::::::Cleanup Section :end set ORA_HOME= set ORACLE_SID= set CONNECT_USER= set BACKUP_DIR= This program performs an export of the database by using the parameter file specified by export_par. The following are general guidelines for recovery using a cold backup.dmp log= %BACKUP_DIR%\export. Listing 3.txt. When you run the program. regardless of whether you are in a Unix or Windows NT environment. Recovery Principles Recovery principles are the same. This is a very good place to start investigating why an export has failed or for related errors. pass SID as a parameter. A single line about the success or failure of export is appended to the SID. and 'Export Completed successfully'. You can modify the parameter file to suit to your requirements. Edit the parameter file to your specific requirements. This file is located under the directory defined by the LOGDIR variable.16 export_par.txt file= %BACKUP_DIR%\export. if the export failed.log full=y compress=n consistent=y Export Script under Windows NT Checklist • • • • • Check to see that ORA_HOME and BACKUP_DIR. Verify that CONNECT_USER is set to the correct username and password. Specify the full path of the location of your parameter file in the program. In Listing 3. These variables are highlighted in the program. and export. The control file is updated continuously during .

• • database use and must be available for writing whenever the database is open. This command is generally used when the system data file is lost. RECOVER DATAFILE 'filename' This command performs a recovery on listed data files. Checkpoints are used by recovery to ensure that Oracle starts reading the log threads for the redo application at the correct point. If the connection succeeds. open the database and issue the 'RECOVER DATAFILE 'FILE_NAME' command. mount the database and put the troubled data file offline. If the database is open. $ps –ef|grep –i ORCL . This command is generally used when a non-system data file is lost. For a parallel server. the database will not open. Where to Start? You are a new DBA and you get a call from the project manager saying that the users are not able to connect to the database. This can be used only when the database is mounted but not open. Performing Recovery. Media Recovery Commands To perform either a complete media recovery or incomplete media recovery. because some errors that are seen by regular users do not show up when you connect as Internal or SYSDBA (such as Max sessions reached). System Change Number (SCN)—The system change number is a clock value for the database that describes a committed version of the database. Checkpoints are similar to SCNs and they also describe which threads exist at that SCN. The SCN functions as a sequence generator for a database and controls concurrency and redo record ordering. As a first step. To recover the tablespace. • • • • • • • RECOVER DATABASE This • • • • command performs a media recovery on all the data files that require the application of redo. and put the data file online. Think of the SCN as a timestamp that helps ensure transaction consistency. you need to mount the database first. The database must be mounted and open. The tablespace in question must be offline to perform the media recovery. put the data file that is in trouble offline. $sqlplus user/pwd Now you determined that you are not able to connect to the database. If the control file is not accessible. data file recovery can only recover offline files. try to connect as a regular user and see if you receive any errors during connection. RECOVER TABLESPACE tablespace_name This command performs a media recovery on all the data files in the tablespaces listed. you need to be familiar with the following three media recovery commands. try to see whether the processes are running by using the following command. Then give the recover tablespace tablespace_name command and put the tablespace online when the recovery is complete. and then open the database and put the tablespace offline. try to establish a connection for yourself as a DBA as shown. As a second step. The database can be open or closed. each checkpoint has its own redo information. To recover the data file in question. Checkpoint—A checkpoint is a data structure in the control file that defines a consistent point of the database across all threads of a redo log.

This depends on the types of backups your site is employing to protect from database crashes. Where group 1 is the corrupted log group number. do the following: 1. try to determine what kind of backups you have taken recently and see which one is most beneficial for recovering as much data as possible. For this the database need to be in NOMOUNT state (startup NOMOUNT). As a third step. Recovery When a Redo Log File Is LostTo recover the database when a redo log file is lost or corrupted alter database clear logfile group 1. and redo log files from the backup location to the original location. inform the project manager that somebody has caused a problem in the database and try to find out what happened (a hard disk problem or perhaps somebody deleted the file). and error message. As a sixth step. follow the instructions in this chapter. This file lists any errors encountered by database. Copy all data files. Verify the owner and permissions for the files (for Unix only). As a fourth step. If you see any errors. check the alert log file for any errors. Recovery When a Data File Is Lost To recover a database using c cold backup. If you have a hot backup mechanism in place. the data changes since the time of last backup will be lost. start up the database (sometimes it will report an error when you try to startup the database). If it does not list any processes. As a fifth step. error number. Limit your time to this research based on time available.This should list the processes that are running. If the database starts. Recovery Using Cold Backup To restore a full database. Shutdown the database. just restore all the files from the backup location to their original locations and open the database. Start up the database. that is wonderful! If it doesn't start. control files. given your recovery scenario. You cannot recover the transactions that occurred between the last backup and the point of failure—that information is lost. 2. If you do not see any errors. you are sure that the database is down. it will generally complain about the error onscreen and also report the error in the alert log file. note the time of the error. If you have an export or cold backup mechanism in place. The alert log file is located under the directory defined by BACKGROUND_DUMP_DEST in the Init. The reset logs option resets the redo log sequence numbering and recreates any . 3. Check the alert log again for more information. you can be sure that you can recover all or most of the data.ora file. You can find the original physical location in the trace file you generated as part of the backup. Or you can create a new control file and open the database in the Reset Logs mode (alter database open resetlogs). Now you determined from the error that the database is not finding one of the data files.

if a user drops a table accidentally and comes to you for help. Recovery Using Hot Backup When the database is running in ARCHIVELOG mode and online backup is being used. "Incomplete Media Recovery. mission-critical database. we always try to perform a complete recovery unless the need is to recover the database only to a specific point in time for specific reasons. If you lose system data files. To create the new control file. users can access the rest of the database while the recovery is being performed on the damaged data files. you can restore the database from a backup.missing logfiles. Point in Time Recovery . for example. and only part of the database (non-system) is damaged." for creating a new control file. We have taken the trace of control file by using Alter database backup controlfile to trace as part of the backup. Follow the steps explained in Chapter 10." The choice of whether to use a closed or open database recovery is based on the type of failure. we want to be able to fully recover the data in case of a database failure. Suppose that you are running a 24/7. Recovery When a Control File Is Lost To recover the database in case of a lost control file. such as those discussed in the next section. If a non-system data file is lost. that provide maximum protection for your data. you can perform recovery by using either a closed or open database method. the only choice is a closed database recovery. Recovery can be classified as follows: • • • • • • • • Complete media recovery Closed database recovery Open database/offline tablespace recovery Open database/offline tablespace/individual data file recovery Incomplete media recovery Cancel-based recovery Time-based recovery Change-based recovery Complete Media Recovery At all costs. By using the latest control file. up to the point of failure. Consequently. "Database Maintenance and Reorganization. Follow the steps explained in Chapter 10 for creating a new control file. In this situation. you need to know the full structure of the database. If you know the time the table drop occurred. you simply recreate the control file knowing the structure of the database (from the trace of control file) and open the database with reset logs. you can roll forward the changes by applying redo log files up to the point just before the accidental drop (time-based recovery). you can open the database for users by taking the damaged data files offline and then performing a recovery on the damaged files. there are a variety of options for recovering the database. Incomplete Media Recovery Incomplete media recovery is very useful as well. This way.

Start media recovery as follows: recover database At this point. After the database is open. 6. tablespace can be taken offline either with a normal. the database opened and immediately died as soon as I started executing any SQL statement. Open the database: alter database open Verify that the recovery worked. take the tablespace offline. Take the corrupted data file offline: alter datafile '/u01/oradata/users01. 2. For example. Start the recovery on the tablespace: recover tablespace users. 2. . Open the database as follows: alter database open. 4. so that the Oracle knows what archived redo log files to apply.dbf' offline. you have to use the latest control file to roll forward with the archived redo log files. Here. you will be prompted for the location of the archived redo log files. mount database but do not open it: startup mount 3. if the corrupted data file belongs to USERS tablespace. 5. Remember. 4. I restored the database from a backup and applied the archive redo log files up to just before the time of the crash and the database came up fine. use the following command: alter tablespace users offline. With the following command. take the damaged tablespace offline with a normal or temporary priority to minimize the amount of recovery. Closed Database Recovery Steps 1. Offline Tablespace Recovery Steps 1. When I tried to bring up the database.m. Restore the damaged files from the backup. temporary. or immediate priority.There was a database corruption at 5 p. mount the database but do not open it: startup mount 3. This crippled my ability to perform troubleshooting of the problem. Restore the damaged files from backup. if necessary. If possible. in the evening and the database crashed. With the following command.

5. Cancel-Based Recovery Steps 1. Using the following command.At this point. Verify that the recovery worked. Here. For example. After the database is open.dbf'. 6. take the tablespace offline. Start the recovery on the data file: recover datafile '/u01/oradata/users01. Take the corrupted data file offline: alter datafile '/u01/oradata/users01. 7. take the damaged tablespace offline with a normal or temporary priority to minimize the amount of recovery. you will be prompted for the location of the archived redo log files. Restore the damaged files from the backup. if necessary. 7. 8. use the following command: alter tablespace users offline. 2. if the corrupted data file belongs to USERS tablespace. mount the database but do not open it: startup mount 3. Bring the tablespace online: alter tablespace users online. 2. tablespace can be taken offline either with a normal. Start the recovery: . you will be prompted for the location of the archived redo log files.dbf' offline. Bring the tablespace online: alter tablespace users online. 8. or immediate priority. mount the database but do not open it: Startup mount 3. At this point. 4. if necessary. Restore the damaged files from the backup. Verify that the recovery worked. Using the following command. Open the database: alter database open. If possible. Offline Datafile Recovery Steps 1. temporary.

Open the database: alter database open resetlogs Whenever an incomplete media recovery is being performed or the backup control file is used. if necessary. Enter cancel to cancel recovery after Oracle has applied the archived redo log file just prior to the point of corruption. the database should be opened with the resetlogs option. Otherwise. you should specify the using backup controlfile option. If a backup control file or recreated control file is being used with incomplete recovery. you will not be able to recover changes made after you reset the logs. 2. If a backup control file or recreated control file is being used with incomplete recovery. Oracle automatically terminates the recovery when it reaches the correct time. if necessary. 6. In time-based recovery. so that it resets the log numbering.recover database until cancel [using backup controlfile] At this point. you cannot stop in the middle of applying a redo log file. you will be prompted for the location of the archived redo log files. Using the following command. Restore the damaged files from the backup. Time-Based Recovery Steps 1. You either completely apply a redo log file or you don't apply it at all. Perform a full backup of database. Start the recovery: recover database until time [using backup controlfile] For example recover database until time '1999-01-01:12:00:00' using backup controlfile At this point. mount the database but do not open it: startup mount 3. . Verify that the recovery worked. Open the database: alter database open resetlogs Whenever an incomplete media recovery is being performed or the backup control file is used for recovery. If you open the database with resetlogs. you will be prompted for the location of the archived redo log files. 4. you should specify the using backup controlfile option. 4. you can apply to a specific point in time. the database should be opened with the resetlogs option. regardless of the archived redo log number. In cancel-based recovery. 5. a full backup of the database should be performed immediately after recovery. The resetlogs option will reset the redo log files.

Restore the damaged files from the backup. you will not be able to recover the changes made after you reset the logs. the only way to recover the database is by doing a closed database recovery using RECOVER DATABASE command. This command works when the database is mounted or open. status from v$datafile. 4. Change-Based Recovery Steps 1. a full backup of the database should be performed immediately after recovery. Start the recovery: recover database until change [using backup controlfile] For example recover database until change 2315 using backup controlfile At this point. you will be prompted for the location of the archived redo log files. If the database is opened with resetlogs. Open the database. Checking for Files Needing Recovery The following command can be used to check the data file status. Verify that the recovery worked. 6. alter database open resetlogs 5. mount the database but do not open it: startup mount 3.5. Perform a full backup of the database. Otherwise. if necessary. Oracle automatically terminates the recovery when it reaches the correct system change number (SCN). Perform a full backup of the database. select name. Verify that the recovery worked. you should specify using the backup controlfile option. 6. If a backup control file or a recreated control file is being used with an incomplete recovery. . Otherwise. 2. System Tablespace Versus a Non-System Tablespace Recovery When a system data file is lost or damaged. a full backup of the database should be performed immediately after recovery. Using the following command. you will not be able to recover the changes made after you reset the logs. If the database is opened with resetlogs.

you can obtain information about the files that need recovery by executing the following command.Before you actually start recovering the database. and the DESTROY=N option does not destroy the existing tablespaces.dmp. 1. The command also gives error information. Import the database—The following command performs a full database import. 1. you have a full export of the database from yesterday and your database crashed this afternoon. Verify the import log for any errors—With this import. Set your ORACLE_SID to ORCL.file# Recovery Using Import The import utility is used to import the database from the dump file generated through the export utility. 2. if one of the developers requests that you transfer the EMP and DEPT tables of user SCOTT from database ORCL to TEST. You can use the following steps to transfer these two tables. select b.file# = b. . The restore steps are as follows. Table-Level Import A table level import allows you to import specific objects without importing the whole database. the data changes between your previous backup and the crash will be lost. assuming that your export dump filename is export. The IGNORE=Y option ignores any create errors. Create a blank database—Refer to Chapter 10 for instructions on how to create a database. This is very useful for transferring data across platforms and importing only specific objects or users. For example. It works whether archiving is turned on or off. You can use the import command to restore the database from the previous day's backup.log full=y ignore=y destroy=n 3.error from v$recover_file a. a. C:\>imp system/manager file=export. Example 1: For example. To execute the statement.dmp log=import. C:\>set ORACLE_SID=ORCL This step sets the correct database to which to connect. v$datafile b where a. the database must be mounted. There are three levels of Import: • • • Full User-level Table-level Full Import A full import can be used to restore the database in case of a database crash.name. Full database import performance can be improved by turning off archiving during the import.

C:\>imp system/manager fromuser=scott touser=scott tables=(EMP. 5. Connect to TEST database. He wants to see whether you can do anything to restore the table. Import the tables to TEST. constraints and any indexes on the table. C:\>exp system/manager tables=(scott.DEPT) 8. we need to precede them with the owner in the export command. Verify the export. file=export.emp.log file to make sure there are no errors in the export.SQL>Drop table DEPT.2. Example 2: Suppose you walk into the office in the morning and a developer meets you in the hallway and says that he accidentally dropped the SALES table. . Because the tables belong to owner scott. 6.SQL>Truncate table DEPT.dmp log=import. Set your ORACLE_SID to the TEST database. Perform an export of EMP and DEPT. 3.log ignore=Y This command imports the SALES table from previous backup. C:\>imp system/manager tables=(SCOTT. log=import.dept) file=export.dmp 4.dmp log=export. Drop the tables if it already exists. After the import check the import log file for any errors. C:\>set ORACLE_SID=TEST 7.scott. Or SQL>Drop table EMP.SALES) file=export. you could do something if you have an export dump file from your previous backup. 3. SQL>Truncate table EMP.log ignore=Y Check for any errors in the import log file. Import the table from previous backup. Well.log This command exports table data. SQL>Connect system/manager@TEST 4. If the TEST database already has EMP and DEPT tables. The steps to restore the table are as follows (assuming that this happened in the TEST database): 1. you can truncate the tables or drop the tables as shown. C:\>set ORACLE_SID=TEST 2.

If the recovery catalog is destroyed and no backups of it are available. then you can partially reconstruct the catalog from the current control file or control file backups. Oracle home directory. loss of the recovery catalog can be disastrous. The auto startup flag tells whether the Oracle database should be started automatically when the system is rebooted. Each instance listed on a separate line # SID:ORACLE_HOME:Y/N DEV:/u02/oracle/DEV/oracle/8. Listing 3. If you do not want to use the recovery catalog RMAN can use the target database control file to perform backup and recovery operations. Typically the recovery catalog is stored in a separate database. control files and archived redo log files. A single recovery catalog is able to store information for multiple target databases. and auto startup flag (Y/N) for the database in the format [SID:ORACLE_HOME:FLAG].17 is created by the Oracle installer when you install the Oracle database under Unix operating system. You should back up the recovery catalog frequently. Using RMAN you can backup and restore datafiles. The installer adds the instance name. RMAN supports using the target database control file instead of a recovery catalog.Backup and Recovery Tools Recovery Manager (RMAN) RMAN is an Oracle provided tool that allows you perform backup and recovery operations on the database. the RMAN environment is comprised of the following components • • • • RMAN executable Recovery catalog database (Database to hold the catalog) Recovery catalog schema in the recovery catalog database (Schema to hold the metadata information) Optional Media Management Software (for tape backups) Sample Files Sample oratab File Listing 3. RMAN operates using the recovery catalog to store metadata information about backup and recovery operations. Using the control file is especially appropriate for small databases where installation and administration of another database for the sole purpose of maintaining the recovery catalog is burdensome. When you use RMAN with a recovery catalog. To avoid this you should make frequent backups of the control file.1. The disadvantage of using the control file is that RMAN does not support restore or recovery when the control file is lost. Consequently. information about the backup is stored in the catalog and the actual backups(physical files) are stored on disk or tape(requires media management software). Because most information in the recovery catalog is also available in the target database's control file.1.1.7:N .7:N #PREPROD:/u06/oracle/PREPROD/oracle/8. When you perform a backup using RMAN.17 oratab # All the entries in oratab file follow the # following syntax.7:N TEST:/u05/oracle/TEST/oracle/8.

'/u02/oracle/DEV/data/rbs01.dbf'.730 *** 2001-05-17 21:15:28.dbf'. Listing 3. # Recovery is required if any of the datafiles are restored backups.730 # The following commands will create a new control file and use it # to open the database.13) 2001-05-17 21:15:28. This is useful if you need to recreate the control file.1. ALTER DATABASE OPEN.dbf' REUSE.6 Version: Generic_105181-25 Machine: sun4u Instance name: DEV Redo thread mounted by this instance: 1 Oracle process number: 10 Unix process pid: 11817. CHARACTER SET WE8ISO8859P1 .18 will have the structure of the database.0 . GROUP 2 ( '/u03/oracle/DEV/data/log02a. It lists the data files. image: oracle@mking07 (TNS V1-V3) *** SESSION ID:(9. RECOVER DATABASE # Database can now be opened normally.dbf'. A trace of the control file can be generated by using the alter database backup control file to trace. Additional logs may # be required for media recovery of offline data files.7.1.0 .7 System name: SunOS Node name: mking07 Release: 5. '/u02/oracle/DEV/data/users. STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "DEV" NORESETLOGS NOARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 4 MAXDATAFILES 1022 MAXINSTANCES 1 MAXLOGHISTORY 453 LOGFILE GROUP 1 ( '/u03/oracle/DEV/data/log01a. control files. # or if the last shutdown was not normal or immediate. '/u02/oracle/DEV/data/indx01. # Other tempfiles may require adjustment. '/u03/oracle/DEV/data/log01b. # End of tempfile additions.dbf' REUSE.Production ORACLE_HOME = /u02/oracle/DEV/oracle/8.dbf' ) SIZE 400M.dbf' ) SIZE 400M. # Online tempfiles have complete space information.7. '/u02/oracle/DEV/data/temp01. DATAFILE '/u02/oracle/DEV/data/system01.Sample Trace of Control File Listing 3.1.dbf'. # Commands to add tempfiles to temporary tablespaces.1. '/u03/oracle/DEV/data/log02b.dbf'. ALTER TABLESPACE TEMP ADD TEMPFILE '/u03/oracle/DEV/data/temp03.18 trace of control file /u02/oracle/DEV/common/admin/udump/DEV_ora_11817.Production With the Partitioning option JServer Release 8. Use this # only if the current version of all online logs are available.trc Oracle8i Enterprise Edition Release 8.dbf'. . ALTER TABLESPACE TEMP ADD TEMPFILE '/u03/oracle/DEV/data/temp04.1. and the redo log files and their location.dbf'. # Data used by the recovery manager will be lost.

# .

Sign up to vote on this title
UsefulNot useful