Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hot backups

Status
Not open for further replies.

KenCunningham

Technical User
Mar 20, 2001
8,475
GB
Good day, folks. I'm playing with implementin a hot backup using the following code gleaned from another web site:

Code:
rem Script Description: This script automates hot backups (only available when
rem                     the archivelog mode is on). It creates a script called hotback.sql,
rem                     that will automatically back up tablespaces and control
files.
rem
rem
rem Output file:        hotbackups.sql
rem
rem Prepared By:        Oracle Resource Stop
rem
rem Usage Information:  SQLPLUS SYS/pswd
rem                     @autohotbackups.sql  {target directory}
rem

set serveroutput on
set heading off
set feedback off

spool hotbackups.sql

declare
fname  varchar2(80);
tname  varchar2(80);
tname1  varchar2(80);

cursor cur1 is
      select tablespace_name,file_name
       from v$datafile,sys.dba_data_files
       where enabled like '%WRITE%'
         and file# = file_id
       order by 1;

begin
  dbms_output.enable(32000);
  dbms_output.put_line('spool hotbackups');

  if cur1%ISOPEN
  then
     close cur1;
  end if;

  open cur1;

  fetch cur1 into tname,fname;

  tname1 := tname;
  dbms_output.put_line('alter tablespace '||tname||' begin backup;');

  while cur1%FOUND loop

        if tname1 != tname then
           dbms_output.put_line('alter tablespace '||tname1||' end backup;');
           dbms_output.put_line('alter tablespace '||tname||' begin backup;');
           tname1 := tname;
        end if;

        dbms_output.put_line('!cp '||fname||' &&target_directory');

        fetch cur1 into tname,fname;

  end loop;
  dbms_output.put_line('alter tablespace '||tname1||' end backup;');

  close cur1;

  dbms_output.put_line('alter database backup controlfile to trace;');

  dbms_output.put_line('alter database backup controlfile to '||''''||
                       '&&target_directory'||'/control.'||
                       to_char(sysdate,'DDMMYYYYHH24MISS')||''''||';');
  dbms_output.put_line('spool off');
end;
/
spool off
set heading on
set feedback on
set serveroutput off

-- Unremark/Uncomment the following line to run the script
-- or can be run from the sqlplus prompt.
@hotbackups

This seems to work fine and copies the data files and a copy of the control file. My question now is when I copy these back to their original locations (I assume the control file will be used to overwrite all copies of the existing ones?), what is the procedure to start up the database? I'm thinking along the lines of:

sqlplus /nolog
connect "/ as sysdba"
startup mount
recover database until cancel using backup controlfile;
supply the path and name of archive log or redo log
alter database open

Is this correct, or is there any other recommended procedure? Any help gratefully received.
 
Sorry, the alter database open should be alter database open resetlogs presumably?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top