define HOT_BACK_DIR = '&backup_directory' define SCRIPT_FILE = '&script_file' column F_HOT_BACK_DIR new_value HOT_BACK_DIR select nvl('&HOT_BACK_DIR','/backup') F_HOT_BACK_DIR from dual; select '&HOT_BACK_DIR' "BACKUP DIRECTORY" from dual; column F_SCRIPT_FILE new_value SCRIPT_FILE select nvl('&SCRIPT_FILE','backup.sql') F_SCRIPT_FILE from dual; select '&SCRIPT_FILE' "SCRIPT FILE" from dual; set feedback off set heading off set pagesize 0 set linesize 128 set verify off set termout oN set echo off set trims on spool &SCRIPT_FILE select 'set echo on' from dual; select 'connect / as sysdba' from dual; -- make a binary backup of the controlfile select 'alter database backup controlfile to ''&HOT_BACK_DIR/controlfile.ctl'';' from dual; -- make a ascii script backup of controlfile select 'alter database backup controlfile to trace; ' from dual; -- the ascii backup is written udump -- the following tries to receate the full path and name -- of the trace file containing the controlfile backup -- so we can copy it to the backup directory prompt column tracefile new_value trace_file prompt select prompt (select value from v$parameter where name='user_dump_dest')||'/'|| prompt (select lower(value) from v$parameter where name='db_name')|| prompt '_ora_' || p.spid ||'.trc' tracefile prompt from prompt v$process p, prompt v$session s prompt where s.paddr = p.addr prompt and s.sid = ( select distinct sid from v$mystat) prompt / prompt -- outputs "!cp &trace_file /backup' -- which when run in the output script, copies -- the tracefile with the controlfile script to the backupdir select '!cp ' ||Chr(38)|| 'trace_file' || ' &HOT_BACK_DIR/control.trc' from dual; select '!cat ' ||Chr(38)|| 'trace_file' || ' | awk "/current/,/OFF/{ print}" | grep -v "^#" > &HOT_BACK_DIR/control.sql' from dual; -- Create Script to backup actual files to a directory -- we want to go through all the tablespaces one by one -- put then in backup mode -- copy and compress the copy of each datafile in tablespace -- and the take the tables out of backu mode -- I do this by selecting each tablespace twice -- once with begin backup, once with end backup -- and then I union select copy datafiles to backup -- all of this is put into the write order -- by a sort on "c1" which is a comment field containing -- the tbalespace name and action beg,copy,end -- which when sorted comes out in the right order select '/* '||tablespace_name||' beg */' c1, 'alter tablespace '|| tablespace_name||' begin backup;' c2 from dba_tablespaces where CONTENTS != 'TEMPORARY' union all select '/* '||tablespace_name||' copy */' c1, '!cat '||file_name||' | compress > &HOT_BACK_DIR' || '/' || substr(file_name,instr(rtrim(file_name),'/',-1,1)+1,length(rtrim(file_name)))|| '.Z' c2 from dba_data_files union all select '/* '||tablespace_name||' end */' c1, 'alter tablespace '|| tablespace_name||' end backup;' c2 from dba_tablespaces where CONTENTS != 'TEMPORARY' order by c1 / select 'alter system switch logfile;' from dual; select '!cp '|| member || ' &HOT_BACK_DIR ' from v$logfile; --select 'exit' from dual; spool off