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','/tmp') 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 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; spool off