Home > Oracle Database / Applications Tips > Oracle database administrator > Hot backup script
Oracle Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ORACLE DATABASE ADMINISTRATOR

Hot backup script


Ravindra Nookala
05.22.2005
Rating: -3.67- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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_SID=DBADB2; export ORACLE_SID
ORACLE_HOME=/prod/applc/ora9201; export ORACLE_HOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH
PATH=$PATH:$ORACLE_HOME/bin; export PATH
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 ""
                       exit
  else
   DEST=/db/dba/backup
   mkdir $DEST/HotBackup_${ORACLE_SID}_${TIMESTAMP}
   BKUPDEST=$DEST/HotBackup_${ORACLE_SID}_${TIMESTAMP}
   LOGDIR=/db/dba/logs
   BKUPLOG=$LOGDIR/HotBackup_"${ORACLE_SID}"_"${TIMESTAMP}".log

   echo ""
   echo "**********************************************************************"
   echo "Hot Backup Of Database "${ORACLE_SID}" Started..... Please Wait !!!"
   echo "**********************************************************************"
   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

Rate this Tip
To rate tips, you must be a member of SearchOracle.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Oracle database administrator
Understanding SQL string functions
What is the difference between a database engineer, architect and administrator?
Import on one table from dump file
Error during RMAN backup
Can I drop a column in SYS schema?
STATSPACK tool: transaction vs. execution measurement
Should I port from Microsoft Access?
How can I find statistics on total memory usage and database connections?
Installing multiple Oracle homes
Modifying SYS password in a RAC environment

Oracle database backup and recovery
Can I perform an Oracle server backup through a client machine?
How to execute DML in an Oracle trigger with EXECUTE IMMEDIATE
How to restore a dump file with the Oracle SHOW=Y option
Why do I get an Oracle not available error with Oracle 8i on Windows?
Oracle tutorial library: SearchOracle.com's learning guides
How to perform Oracle database recovery with a corrupt online redo log
Can I create an Oracle Catalog Database with the Enterprise Console?
Do I need to recreate views after an Oracle table reorg?
Client-based apps vs. web-based apps in Developer 2000
How to perform an Oracle 8i to 10g migration
Oracle database backup and recovery Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Oracle Development Solutions - SQL, J2EE, XML, SOA
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts