ORACLE備份&恢復案例(8)

jss001發表於2009-02-14

4.4.2 RMAN備份下的基於改變的恢復

以上用OS備份說明了一個基於時間的恢復,現在用RMAN說明一個基於改變的恢復

1、連線資料庫,建立測試表並插入記錄

SQL*Plus: Release 8.1.6.0.0 - Production on Tue May 6 13:46:32 2003

(c) Copyright 1999 Oracle Corporation. All rights reserved.

SQL> connect internal/password as sysdba;

Connected.

SQL> create table test(a int);

Table created

SQL> insert into test values(1);

1 row inserted

SQL> commit;

Commit complete

2、備份資料庫

C:>rman

Recovery Manager: Release 8.1.6.0.0 - Production

RMAN> connect rcvcat rman/rman@back

RMAN-06008: connected to recovery catalog database

RMAN> connect target internal/virpure

RMAN-06005: connected to target database: TEST (DBID=874705288)

RMAN> run{

2> allocate channel c1 type disk;

3> backup full tag 'dbfull' format 'd:backupfull%u_%s_%p' database

4> include current controlfile;

5> sql 'alter system archive log current';

6> release channel c1;

7> }

RMAN-03022: compiling command: allocate

RMAN-03023: executing command: allocate

RMAN-08030: allocated channel: c1

RMAN-08500: channel c1: sid=12 devtype=DISK

RMAN-03022: compiling command: backup

RMAN-03023: executing command: backup

RMAN-08008: channel c1: starting full datafile backupset

RMAN-08502: set_count=1 set_stamp=494607834 creation_time=21-MAY-03

RMAN-08010: channel c1: specifying datafile(s) in backupset

RMAN-08522: input datafile fno=00001 name=D:ORACLEORADATATESTSYSTEM01.DBF

RMAN-08011: including current controlfile in backupset

RMAN-08522: input datafile fno=00002 name=D:ORACLEORADATATESTRBS01.DBF

RMAN-08522: input datafile fno=00003 name=D:ORACLEORADATATESTUSERS01.DBF

RMAN-08522: input datafile fno=00004 name=D:ORACLEORADATATESTTEMP01.DBF

RMAN-08522: input datafile fno=00005 name=D:ORACLEORADATATESTTOOLS01.DBF

RMAN-08522: input datafile fno=00006 name=D:ORACLEORADATATESTINDX01.DBF

RMAN-08013: channel c1: piece 1 created

RMAN-08503: piece handle=D:BACKUPFULL01ENM7EQ_1_1 comment=NONE

RMAN-08525: backup set complete, elapsed time: 00:00:16

RMAN-03023: executing command: partial resync

RMAN-08003: starting partial resync of recovery catalog

RMAN-08005: partial resync complete

RMAN-03022: compiling command: sql

RMAN-06162: sql statement: alter system archive log current

RMAN-03023: executing command: sql

RMAN-03022: compiling command: release

RMAN-03023: executing command: release

RMAN-08031: released channel: c1

RMAN>

3、刪除測試表,在刪除之前,便於測試,繼續插入資料並應用到歸檔,並獲取刪除前的scn號。

SQL> insert into test values(2);

1 row inserted

SQL> commit;

Commit complete

SQL> select * from test;

A

---------------------------------------

1

2

SQL> alter system switch logfile;

Statement processed.

SQL> alter system switch logfile;

Statement processed.

SQL> select max(ktuxescnw * power(2, 32) + ktuxescnb) scn from x$ktuxe;

SCN

----------

31014

SQL> drop table test;

Table dropped.

4、準備恢復到SCN 31014,先關閉資料庫,然後啟動到mount

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 53126412 bytes

Fixed Size 70924 bytes

Variable Size 26763264 bytes

Database Buffers 26214400 bytes

Redo Buffers 77824 bytes

Database mounted.

5、開始恢復到改變點SCN 31014

RMAN> run{

2> allocate channel c1 type disk;

3> restore database;

4> recover database until scn 31014;

5> sql 'ALTER DATABASE OPEN RESETLOGS';

6> release channel c1;

7> }

RMAN-03022: compiling command: allocate

RMAN-03023: executing command: allocate

RMAN-08030: allocated channel: c1

RMAN-08500: channel c1: sid=10 devtype=DISK

RMAN-03022: compiling command: restore

RMAN-03022: compiling command: IRESTORE

RMAN-03023: executing command: IRESTORE

RMAN-08016: channel c1: starting datafile backupset restore

RMAN-08502: set_count=1 set_stamp=494613682 creation_time=21-MAY-03

RMAN-08089: channel c1: specifying datafile(s) to restore from backup set

RMAN-08523: restoring datafile 00001 to D:ORACLEORADATATESTSYSTEM01.DBF

RMAN-08523: restoring datafile 00002 to D:ORACLEORADATATESTRBS01.DBF

RMAN-08523: restoring datafile 00003 to D:ORACLEORADATATESTUSERS01.DBF

RMAN-08523: restoring datafile 00004 to D:ORACLEORADATATESTTEMP01.DBF

RMAN-08523: restoring datafile 00005 to D:ORACLEORADATATESTTOOLS01.DBF

RMAN-08523: restoring datafile 00006 to D:ORACLEORADATATESTINDX01.DBF

RMAN-08023: channel c1: restored backup piece 1

RMAN-08511: piece handle=D:BACKUPFULL01ENMD5I_1_1 tag=DBFULL params=NULL

RMAN-08024: channel c1: restore complete

RMAN-03023: executing command: partial resync

RMAN-08003: starting partial resync of recovery catalog

RMAN-08005: partial resync complete

RMAN-03022: compiling command: recover

RMAN-03022: compiling command: recover(1)

RMAN-03022: compiling command: recover(2)

RMAN-03022: compiling command: recover(3)

RMAN-03023: executing command: recover(3)

RMAN-08054: starting media recovery

RMAN-03022: compiling command: recover(4)

RMAN-06050: archivelog thread 1 sequence 191 is already on disk as file D:ORACL

EORADATATESTARCHIVETESTT001S00191.ARC

RMAN-06050: archivelog thread 1 sequence 192 is already on disk as file D:ORACL

EORADATATESTARCHIVETESTT001S00192.ARC

RMAN-03023: executing command: recover(4)

RMAN-08515: archivelog filename=D:ORACLEORADATATESTARCHIVETESTT001S00191.AR

C thread=1 sequence=191

RMAN-08515: archivelog filename=D:ORACLEORADATATESTARCHIVETESTT001S00192.AR

C thread=1 sequence=192

RMAN-08055: media recovery complete

RMAN-03022: compiling command: sql

RMAN-06162: sql statement: ALTER DATABASE OPEN RESETLOGS

RMAN-03023: executing command: sql

RMAN-03022: compiling command: release

RMAN-03023: executing command: release

RMAN-08031: released channel: c1

6、檢查資料

Database altered.

SQL> select * from test;

A

---------------------------------------

1

2

可以看到,表依然存在

說明:

1RMAN也可以實現不完全恢復,方法比OS備份恢復的方法更簡單可靠

2RMAN可以基於時間,基於改變與基於日誌序列的不完全恢復,基於日誌序列的恢復可以指定恢復到哪個日誌序列,如

run {

allocate channel ch1 type disk;

allocate channel ch2 type 'sbt_tape';

set until logseq 1234 thread 1;

restore controlfile to '$ORACLE_HOME/dbs/cf1.f' ;

replicate controlfile from '$ORACLE_HOME/dbs/cf1.f';

alter database mount;

restore database;

recover database;

sql "ALTER DATABASE OPEN RESETLOGS";

}

3、與所有的不完全恢復一樣,必須在mount下,restore所有備份資料檔案,需要resetlogs

4、基於改變的恢復比基於時間的恢復更可靠,但是可能也更復雜,需要知道需要恢復到哪一個改變號(SCN),在正常生產中,獲取SCN的辦法其實也有很多,如查詢資料庫字典表(V$archived_log or v$log_history),或分析歸檔與聯機日誌(logmnr)等。[@more@]

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

相關文章