溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Oracle 學習之RMAN(十三)恢復實戰(zhàn)--數(shù)據(jù)塊修復

發(fā)布時間:2020-08-02 13:23:03 來源:網(wǎng)絡(luò) 閱讀:708 作者:lqding1980 欄目:關(guān)系型數(shù)據(jù)庫

  在很多情況下,數(shù)據(jù)庫只是某個數(shù)據(jù)文件的些許數(shù)據(jù)塊發(fā)生損壞。這種情況,我們當然可是使用數(shù)據(jù)庫恢復或者數(shù)據(jù)文件恢復的方式來解決問題。但是有點高射炮打蚊子的感覺。幸好RMAN提供了塊級別的恢復。下面我們來演示一下。

 1. 創(chuàng)建一個表空間,大小小一點。

SQL> conn / as sysdba
Connected.
SQL> create tablespace tbs_blkerr datafile '/u01/app/oracle/oradata/devdb/blkerr01.dbf' size 128K;

Tablespace created.

 2. 在這個表空間上創(chuàng)建一個表,并且裝滿數(shù)據(jù)。

SQL> create table emp_blk tablespace tbs_blkerr as select * from scott.emp;

Table created.

SQL> insert into emp_blk select * from scott.emp;

14 rows created.

SQL> /

14 rows created.

。。。。

SQL> insert into emp_blk select * from scott.emp;
insert into emp_blk select * from scott.emp
*
ERROR at line 1:
ORA-01653: unable to extend table SYS.EMP_BLK by 8 in tablespace TBS_BLKERR


SQL> commit;

Commit complete.

SQL> select count(*) from emp_blk;

  COUNT(*)
----------
       686

SQL>

3. 備份該表空間或者數(shù)據(jù)文件。

RMAN> backup datafile '/u01/app/oracle/oradata/devdb/blkerr01.dbf';

Starting backup at 2015/07/09 10:30:11
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/u01/app/oracle/oradata/devdb/blkerr01.dbf
channel ORA_DISK_1: starting piece 1 at 2015/07/09 10:30:11
channel ORA_DISK_1: finished piece 1 at 2015/07/09 10:30:12
piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T103011_bsvq5mw9_.bkp tag=TAG20150709T103011 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2015/07/09 10:30:12

4. 使用vi編輯數(shù)據(jù)文件blkerr01.dbf,對文件尾部做稍微的修改

  

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size		    2233000 bytes
Variable Size		  553651544 bytes
Database Buffers	  281018368 bytes
Redo Buffers		    2379776 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
ORA-01110: data file 7: '/u01/app/oracle/oradata/devdb/blkerr01.dbf'
RMAN> restore datafile 7;

Starting restore at 2015/07/09 10:36:25
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/devdb/blkerr01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T103011_bsvq5mw9_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T103011_bsvq5mw9_.bkp tag=TAG20150709T103011
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2015/07/09 10:36:27

RMAN> recover datafile 7;

Starting recover at 2015/07/09 10:36:40
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 2015/07/09 10:36:41

此次修改破壞了文件的頭部,發(fā)生了意外。(也可能是編輯datafile時,沒有關(guān)閉數(shù)據(jù)庫)我們先恢復數(shù)據(jù)文件。再次編輯文件。

此實驗始終沒有做成功,后續(xù)有時間再研究。

恢復的方法如下:

RMAN TARGET / 
BLOCKRECOVER DATAFILE 12 BLOCK 12;


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI