【RMAN】Oracle_rman中skip引發的血案

xysoul_雲龍發表於2014-09-28
     好久沒有動腦子了,最近一直在跑步、踢球,練就成了四肢發達、頭腦簡單的高階動物,當同學把rman恢復錯誤資訊給我發過來之後,都不知道怎麼下手了,更囧的是一個專案組的哥們讓我幫忙看看資料庫問題,parameter引數竟然瞬間忘了,整天文件、文章的,荒廢了。為了調整,我決定沒事找事,OK,我們看一下下面的問題。(以下資訊是在我的測試機上還原的)

    同學發過來的問題如下:

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of switch command at 09/28/2014 07:59:23

RMAN-20230: datafile copy not found in the repository

RMAN-06015: error while looking up datafile copy name: /oracle/FIRSOUL/datafile/test2.dbf

這個懂得資料庫或者rman的人大多能看出來,switch失敗,找不到那個檔案副本,我就看了一下備份指令碼,指令碼如下:

RMAN> run

2> {

3> allocate channel C1 type disk maxpiecesize 2G format "/oracle/backup/0/%d_%Y_%M_%D_%U.BAK";

4> allocate channel C2 type disk maxpiecesize 2G format "/oracle/backup/0/%d_%Y_%M_%D_%U.BAK";

5> sql 'alter system archive log current';

6> backup incremental level=0 database plus archivelog delete input;

backup current controlfile format '/oracle/backup/0/ctl_%d_%Y_%M_%D.bak'; 

 backup  spfile format '/oracle/backup/0/spfile_%d_%Y_%M_%D.bak';

7> 8> 9>  delete noprompt obsolete REDUNDANCY=2 device type disk;

10>  crosscheck backup;

11>  release channel C1;

12>  release channel C2;

13> }

List backup檢視,並沒有發現備份檔案68,檢視備份指令碼沒有跳過該檔案,但備份日誌中出現一下資訊

file 6 is excluded from whole database backup

file 8 is excluded from whole database backup

說明這兩個檔案沒有備份,那麼在set newname時,也就不能寫。那麼他之前沒有寫,但是隻寫了一個restore database,報錯如下:

Starting recover at 28-SEP-14

using channel ORA_DISK_1

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 09/28/2014 13:37:57

RMAN-06094: datafile 6 must be restored

既然沒有備份,那麼我還原的時候應該可以啊,備份的時候也沒有skip,怎麼就不備份了呢,透過檢視下面檢視,發現test2test4rman時是不備份的。但是在控制檔案資訊中也記錄著沒有備份的表空間、資料檔案資訊,所以要用skip tablespace跳過沒備份的表空間。

sys@FIRSOUL> select * from v$tablespace;

 

       TS# NAME        INC BIG FLA ENC

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

         0 SYSTEM      YES NO  YES

         1 SYSAUX      YES NO  YES

         2 UNDOTBS1    YES NO  YES

         3 TEMP        NO  NO  YES

         4 USERS       YES NO  YES

         5 TEST1       YES NO  YES

         6 TEST2       NO  NO  YES

         7 TEST3       YES NO  YES

         8 TEST4       NO  NO  YES

         9 TEST5       YES NO  YES

官方解釋如下:
Indicates whether the tablespace is included in full database backups using the BACKUP DATABASE RMAN command (YES) or not (NO). NO only if the CONFIGURE EXCLUDERMAN command was used for this tablespace

提示:更改及取消更改表空間是否使用rman備份語句如下,透過rman命令

CONFIGURE EXCLUDE FOR TABLESPACE 'TEST4';

CONFIGURE EXCLUDE FOR TABLESPACE 'TEST4' clear;

完整恢復命令:

RMAN> run

2> {

3> set newname for datafile 1 to '/oracle/FIRSOUL/datafile/system01.dbf';

4> set newname for datafile 2 to '/oracle/FIRSOUL/datafile/sysaux01.dbf';

5> set newname for datafile 3 to '/oracle/FIRSOUL/datafile/undotbs1.dbf';

6> set newname for datafile 4 to '/oracle/FIRSOUL/datafile/users.dbf';

7> set newname for datafile 5 to '/oracle/FIRSOUL/datafile/test1.dbf';

8> set newname for datafile 7 to '/oracle/FIRSOUL/datafile/test3.dbf';

9> set newname for datafile 9 to '/oracle/FIRSOUL/datafile/test5.dbf';

10> restore database skip tablespace test2,test4;

11> switch datafile all;

12> recover database skip tablespace test2,test4;

13> }

關於skip [forever] tablespace 說明

Use an optional SKIPTABLESPACE 'tablespace_name' argument to

avoid restoring specified tablespaces, which is useful when you want to

avoid restoring tablespaces containing temporary data.

If you specify SKIP FOREVER TABLESPACE, then RMAN specifies the DROP

option of ALTER DATABASE DATAFILE ... OFFLINE when taking the

datafiles that belong to the tablespace offline before the restore. The DROP

option indicates that RMAN does not intend to recover these files and

intends to drop their tablespaces from the database after the database is

opened again. In other words, FOREVER indicates that RMAN never

intends to do anything with the skipped tablespaces again.

開始由於無法看到原庫或者沒有仔細看備份日誌,導致我們在還原時有些盲目,網路上的資料對於細節類的東西介紹的比較少,所以好多時候我們就會鑽裡邊出不來。以上步驟是我在測試伺服器上還原的問題,由於原庫資料量較大,每做一次測試(例如restore操作)一個下午或者一天就沒了,為了提高效率,我們應該對相應的文件、日誌仔細檢視、步驟考慮周全。其實歸根結底還是rman不熟悉造成,還有就是有些時候我們盲目去動手,一句話,日誌是個好東西啊。就一個簡單問題,可能憋的太久了,感覺還是很有興趣的,繼續加油。

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

相關文章