Hot backup script

This UNIX shell script will facilitate a hot backup of one Oracle database. It has been tested on 7x, 8x and 9x, and was developed using parametric cursors to be more compact. You must edit this file to replace the relevant variables and paths to suit your environment.
# Set env variables

ORACLE_HOME=/prod/applc/ora9201; export ORACLE_HOME
TIMESTAMP=`/bin/date +%d%m%Y_%H%M`

# Check whether the instance is in Arcive log mode or not.
# Create the Backup Directories and log files only if the instance is in 
# archive log mode.

arc=`ps -ef | grep arc | grep ${ORACLE_SID} | grep -v grep`
                if [ -z "$arc" ]; then
echo ""
echo "***********************************************************"
echo "The instance  ${ORACLE_SID}  is NOT in archive log mode!!!"
echo "***********************************************************"
echo ""
   mkdir $DEST/HotBackup_${ORACLE_SID}_${TIMESTAMP}

   echo ""
   echo "**********************************************************************"
   echo "Hot Backup Of Database "${ORACLE_SID}" Started..... Please Wait !!!"
   echo "**********************************************************************"

    Requires Free Membership to View

echo "" fi # Figure out version of database. if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then SQLDBA="sqlplus internal" else SQLDBA="sqlplus /nolog" SQLUSR="connect / as sysdba" fi # Now generate the backup commands ${ORACLE_HOME}/bin/$SQLDBA < /dev/null $SQLUSR set serverout on set echo off set pause off set feed off set head off set lines 250 spool hotbackup declare cursor ts is select distinct(tablespace_name) from dba_data_files; cursor df(p_ts varchar2) is select file_name from dba_data_files where tablespace_name=p_ts; v_tsname dba_data_files.tablespace_name%type; v_dfname dba_data_files.file_name%type; begin open ts; loop fetch ts into v_tsname; exit when ts%notfound; dbms_output.put_line('alter tablespace '||v_tsname||' begin backup;'); open df(v_tsname); loop fetch df into v_dfname; exit when df%notfound; dbms_output.put_line('!cp '||v_dfname||' '||'$BKUPDEST'); end loop; close df; dbms_output.put_line('alter tablespace '||v_tsname||' end backup;'); end loop; close ts; end; / select 'alter system archive log current;' from dual; select 'alter system archive log current;' from dual; select 'alter system archive log current;' from dual; select 'alter database backup controlfile to '||chr(10)||'''$BKUPDEST/control.bkp'''||';' from dual; spool off exit; EOF # Clean up the hotbackup.lst and redirect the output to hotbackup1.lst. tail +25 hotbackup.lst |grep -v SQL> > hotbackup1.lst # Now do the backup and then check the backup mode of the tablespaces. ${ORACLE_HOME}/bin/$SQLDBA < ${BKUPLOG} $SQLUSR set echo on set termout on @hotbackup1.lst set pages 1000 lines 132; column recover heading "Requires|Recovery?" format a10; column time heading "Date Of|Last Backup" format a12; column ts heading "TsName" format a15; column df heading "FileName" format a30; column mode heading "Mode" format a8; select tablespace_name ts ,name df, a.status "Status", decode(fuzzy,'YES','BACKUP','NORMAL') "mode" ,recover, time from v$datafile_header a, v$backup b where a.file#=b.file# order by tablespace_name,name; exit EOF if test $? -eq 0 ; then echo "" echo "****************************************************************" echo "Hot Backup Of Database "${ORACLE_SID}" Completed Successfully." echo "****************************************************************" else echo "" echo "*************************************************************" echo "Hot Backup Of Database "${ORACLE_SID}" Failed Due To Errors." echo "*************************************************************" echo "" fi # Clean up the .lst files rm hotbackup.lst rm hotbackup1.lst

This was first published in February 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.