热备份脚本:
(备份数据文件、控制文件)
set feedback off pagesize 0 heading off verify off linesize 1000 trimspool on
define dir='D:/lxc/oradata/practice_bak'
define fil='&dir/back_open_commands.sql'
define spo='&dir/back_open_results.txt'
prompt *** Spooling to &fil
set serveroutput on
spool &fil
prompt spool &spo
prompt archive log list;;
prompt alter system switch logfile;;
declare
num number;
cursor cur_tablespace is
select tablespace_name from dba_tablespaces where status<>'READ ONLY';
cursor cur_datafile (tn varchar) is
select file_name from dba_data_files where tablespace_name=tn;
begin
for ct in cur_tablespace loop
select count(*) into num from dba_data_files where tablespace_name=ct.tablespace_name;
if num>0 then
dbms_output.put_line('alter tablespace '||ct.tablespace_name||' begin backup;');
for cd in cur_datafile (ct.tablespace_name) loop
dbms_output.put_line('host copy '||cd.file_name||' &dir');
end loop;
dbms_output.put_line('alter tablespace '||ct.tablespace_name||' end backup;');
end if;
end loop;
end;
/
prompt alter system switch logfile;;
prompt alter database backup controlfile to '&dir/backup.ctl' reuse;;
prompt archive log list;;
prompt spool off;;
spool off;
@&fil
(备份归档日志)
set feedback off pagesize 0 heading off verify off linesize 1000 trimspool on
define dir='D:/lxc/oradata/practice_bak'
define fil='&dir/back_arch_commands.sql'
spool &fil
prompt alter system switch logfile;;
select 'host move '||name||' &dir' from v$archived_log
where completion_time>=trunc(sysdate)-1 and completion_time<trunc(sysdate);
spool off;
@&fil