第5章:從開啟的資料庫備份與恢復之備份開啟的資料庫

mengzhaoliang發表於2008-05-27

/* 2008/05/27
*環境:Windows XP +Oracle10.2.0.1
*Oracle 備份與恢復培訓教程 Kenny Smith,Stephan Haisley著 周琪、韓岷、李渝琳等譯
*第二部分:使用者管理的備份與恢復
*第5章:從開啟的資料庫備份與恢復
*/

練習5.1:備份開啟的資料庫
1、產生資料庫活動
SQL> insert into tina.date_log values(sysdate);

已建立 1 行。
SQL> alter system switch logfile;

系統已更改。

2、建立備份指令碼
建立e:\open_backup.sql指令碼
指令碼內容:
Set feedback off pagesize 0 heading off verify off linesize 100 trimspool on
define dir='e:\backup'
define fil='e:\open_backup_commands.sql'
define spo='&dir\open_backup_output.lst'
prompt *** Spooling to &fil

set serveroutput on
spool &fil
prompt spool &spo

prompt archive log list;;
prompt alter system switch logfile;;

declare
   cursor cur_tablespace is
    select tablespace_name from dba_tablespaces
     where status<>'READ ONLY' and tablespace_name<>'TEMP';
   cursor cur_datafile (tn varchar) is
    select file_name
      from dba_data_files
    where tablespace_name=tn;
   begin
    for ct in cur_tablespace loop
      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 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


3、執行熱備份指令碼
SQL> @e:\open_backup.sql


註釋:使用者表空間置於備份模式,檢視聯機資料檔案的備份狀態:
SQL> alter tablespace users begin backup;

表空間已更改。

SQL> select d.tablespace_name tablespace,b.file#,
  2  b.status,b.change#,b.time
  3  from dba_data_files d,v$backup b
  4  where b.file#=d.file_id
  5  order by tablespace_name;

TABLESPACE          FILE# STATUS                CHANGE# TIME
-------------- ---------- ------------------ ---------- --------------
RISE                    5 NOT ACTIVE             572699 27-5月 -08
SYSAUX                  3 NOT ACTIVE             572668 27-5月 -08
SYSTEM                  1 NOT ACTIVE             572636 27-5月 -08
UNDOTBS1                2 NOT ACTIVE             572655 27-5月 -08
USERS                   4 ACTIVE                 573763 27-5月 -08


SQL> alter tablespace users end backup;

表空間已更改。

4、檢查備份命令
檢視e:\open_bakcup_commands.sql檔案,該檔案中的命令是否正確。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12778571/viewspace-312655/,如需轉載,請註明出處,否則將追究法律責任。

相關文章