Oracle

正確恢復 Oracle 備份

  • March 5, 2016

幾週以來,我一直在嘗試正確恢復數據庫,並且我確信我做錯了一些簡單的事情。在使用以下命令更新應用程序之前,我對數據庫進行了冷備份:

backup database include current controlfile;

如果這很重要,數據庫一直在noarchivelog模式下執行。當我執行以下命令時:

list backup recoverable

我看到了我那天做的備份。然後我執行以下命令

shutdown abort
startup nomount
restore database

現在我必須打開數據庫。如果我sql 'alter database open'在 rman 中執行,我會收到以下錯誤

ORA-01190: control file or data file 1 is from before the last RESETLOGS
ORA-01110: data file 1: '+DATA/db-name/datafile/system.333.741265951'

早些時候我從備份中恢復了控製文件,它不再列在list backup recoverable命令的輸出中。

如果我執行以下命令sql 'alter database open resetlogs',該命令將起作用並且數據庫將打開,但我的應用程序將拋出錯誤,我確信這些錯誤來自最近應用的更新。

我認為使用resetlogs標誌是成功的,所以我不再使用備份,但我不知道該怎麼做。

我是這個 DBA 的新手,尤其是 Oracle。很抱歉這篇文章的長度,但我想把所有的細節都拿出來。

編輯:目前既沒有命令也不能alter database open resetlogs打開alter database open noresetlogs數據庫。

編輯:顯示備份輸出:

RMAN> list backup;

List of Backup Sets

===================

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

1 Full 121.27M DISK 00:00:19 29-SEP-11

BP Key: 1 Status: AVAILABLE Compressed: YES Tag: TAG20110929T160134 Piece Name: /u02/backups/dbname/dbname_18mnp8av_1_1_20110929_1 List of Datafiles in backup set 1 File LV Type Ckp SCN Ckp Time Name

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

2 Full 29134673 29-SEP-11 +DATA/dbname/datafile/sysaux.332.741265959 5 Full 29134673 29-SEP-11 +DATA/dbname/datafile/pluto5.327.741268543 BS Key Type LV Size Device Type Elapsed Time Completion Time

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

2 Full 186.50M DISK 00:00:25 29-SEP-11 BP Key: 2 Status: AVAILABLE Compressed: YES Tag: TAG20110929T160134 Piece Name: /u02/backups/dbname/dbname_17mnp8av_1_1_20110929_1 List of Datafiles in backup set 2 File LV Type Ckp SCN Ckp Time Name

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

1 Full 29134673 29-SEP-11 +DATA/dbname/datafile/system.333.741265951 3 Full 29134673 29-SEP-11 +DATA/dbname/datafile/undotbs1.331.741265965 4 Full 29134673 29-SEP-11 +DATA/dbname/datafile/users.329.741265973 BS Key Type LV Size Device Type Elapsed Time Completion Time

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

3 Full 1.05M DISK 00:00:03 29-SEP-11 BP Key: 3 Status: AVAILABLE Compressed: YES Tag: TAG20110929T160134 Piece Name: /u02/backups/dbname/dbname_19mnp8bp_1_1_20110929_1 Control File Included: Ckp SCN: 29134673 Ckp time: 29-SEP-11 BS Key Type LV Size Device Type Elapsed Time Completion Time

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

4 Full 9.36M DISK 00:00:01 29-SEP-11

BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20110929T160205 Piece Name: /u02/backups/dbname/ctldbname_c-3237489303-20110929-00 SPFILE Included: Modification time: 29-SEP-11 SPFILE db_unique_name: dbname Control File Included: Ckp SCN: 29134673 Ckp time: 29-SEP-11 BS Key Type LV Size Device Type Elapsed Time Completion Time

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

5 Full 1.05M DISK 00:00:02 22-DEC-14 BP Key: 5 Status: AVAILABLE Compressed: YES Tag: TAG20141222T172206 Piece Name: /u02/backups/dbname/dbname_1cpqqnpv_1_1_20141222_1 Control File Included: Ckp SCN: 704426960 Ckp time: 22-DEC-14 BS Key Type LV Size Device Type Elapsed Time Completion Time

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

6 Full 303.91M DISK 00:00:52 22-DEC-14 BP Key: 6 Status: AVAILABLE Compressed: YES Tag: TAG20141222T173133 Piece Name: /u02/backups/dbname/dbname_1fpqqobn_1_1_20141222_1

List of Datafiles in backup set 6

File LV Type Ckp SCN Ckp Time Name

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

1 Full 704427620 22-DEC-14 +DATA/dbname/datafile/system.333.741265951 3 Full 704427620 22-DEC-14 +DATA/dbname/datafile/undotbs1.331.741265965

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

7 Full 1.05M DISK 00:00:01 22-DEC-14 BP Key: 7 Status: AVAILABLE Compressed: YES Tag: TAG20141222T173133 Piece Name: /u02/backups/dbname/dbname_1gpqqode_1_1_20141222_1 Control File Included: Ckp SCN: 704427620 Ckp time: 22-DEC-14

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

8 Full 363.18M DISK 00:01:14 22-DEC-14 BP Key: 8 Status: AVAILABLE Compressed: YES Tag: TAG20141222T173133 Piece Name: /u02/backups/dbname/dbname_1epqqobm_1_1_20141222_1 List of Datafiles in backup set 8 File LV Type Ckp SCN Ckp Time Name

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

2 Full 704427620 22-DEC-14 +DATA/dbname/datafile/sysaux.332.741265959 4 Full 704427620 22-DEC-14 +DATA/dbname/datafile/users.329.741265973 5 Full 704427620 22-DEC-14 +DATA/dbname/datafile/pluto5.327.741268543

編輯:更多備份輸出:

RMAN> list backup recoverable;

List of Backup Sets ===================

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

1 Full 121.27M DISK 00:00:19 29-SEP-11 BP Key: 1 Status: AVAILABLE Compressed: YES Tag: TAG20110929T160134 Piece Name: /u02/backups/dbname/dbname_18mnp8av_1_1_20110929_1 List of Datafiles in backup set 1 File LV Type Ckp SCN Ckp Time Name

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

2 Full 29134673 29-SEP-11 +DATA/dbname/datafile/sysaux.332.741265959 5 Full 29134673 29-SEP-11 +DATA/dbname/datafile/pluto5.327.741268543

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

2 Full 186.50M DISK 00:00:25 29-SEP-11

BP Key: 2 Status: AVAILABLE Compressed: YES Tag: TAG20110929T160134 Piece Name: /u02/backups/dbname/dbname_17mnp8av_1_1_20110929_1 List of Datafiles in backup set 2 File LV Type Ckp SCN Ckp Time Name

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

1 Full 29134673 29-SEP-11 +DATA/dbname/datafile/system.333.741265951 3 Full 29134673 29-SEP-11 +DATA/dbname/datafile/undotbs1.331.741265965 4 Full 29134673 29-SEP-11 +DATA/dbname/datafile/users.329.741265973

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

4 Full 9.36M DISK 00:00:01 29-SEP-11

BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20110929T160205 Piece Name: /u02/backups/dbname/ctldbname_c-3237489303-20110929-00 SPFILE Included: Modification time: 29-SEP-11 SPFILE db_unique_name: dbname

BS Key Type LV Size Device Type Elapsed Time Completion Time

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

6 Full 303.91M DISK 00:00:52 22-DEC-14

BP Key: 6 Status: AVAILABLE Compressed: YES Tag: TAG20141222T173133 Piece Name: /u02/backups/dbname/dbname_1fpqqobn_1_1_20141222_1 List of Datafiles in backup set 6 File LV Type Ckp SCN Ckp Time Name

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

1 Full 704427620 22-DEC-14 +DATA/dbname/datafile/system.333.741265951 3 Full 704427620 22-DEC-14 +DATA/dbname/datafile/undotbs1.331.741265965

BS Key Type LV Size Device Type Elapsed Time Completion Time

`——- —- – ———- ———– ———— —————

8 Full 363.18M DISK 00:01:14 22-DEC-14 BP Key: 8 Status: AVAILABLE Compressed: YES Tag: TAG20141222T173133 Piece Name: /u02/backups/dbname/dbname_1epqqobm_1_1_20141222_1 List of Datafiles in backup set 8 File LV Type Ckp SCN Ckp Time Name

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

2 Full 704427620 22-DEC-14 +DATA/dbname/datafile/sysaux.332.741265959 4 Full 704427620 22-DEC-14 +DATA/dbname/datafile/users.329.741265973 5 Full 704427620 22-DEC-14 +DATA/dbname/datafile/pluto5.327.741268543


一種)

命令alter database open顯示:

ORA-01190: control file or data file 1 is from before the last RESETLOGS
ORA-01110: data file 1: '+DATA/db-name/datafile/system.333.741265951'

這可能有幾個原因,但在您的情況下,這意味著數據庫發現了不適合控製文件/數據文件的重做日誌。這可能是這樣發生的:

  1. 您試圖在不刪除原始文件/將原始文件移動到其他地方的情況下恢復舊備份。(我更喜歡選項2)
  2. 您到了應該使用 resetlogs 選項打開數據庫的地步,但您沒有這樣做。您嘗試正常打開數據庫,數據庫會找到先前數據庫的重做日誌,這些重做日誌具有正確的 DBID 但不同的化身。幸運的是,數據庫意識到了錯誤並且不會繼續,否則你會崩潰你新恢復的數據庫。

b)

你發出alter database open resetlogs

此命令完成後,您的數據庫已打開,但您的應用程序仍然存在問題。好吧,首先讓我們明確一點:此時您的數據庫具有與以前完全相同的數據。現在,每個塊、每個字節、每個位都與您發布備份時的位置相同。所以錯誤與數據庫無關。


C)

這是您必須遵循的程序。(我不推薦離線備份,但這是另一回事。)

RMAN 冷備份按照您的方式工作。這是我前段時間寫的指南:

冷備份

  1. 關閉數據庫
  2. 以掛載模式啟動(nomount 不起作用)
  3. backup database;使用和備份數據庫backup current controlfile;

恢復冷備份

  1. 獲取 SPFILE
  2. 以 nomount 模式啟動數據庫
  3. 恢復控製文件restore controlfile from '<controlfile backup>';
  4. 確保控製文件知道所有可用的備份。如果沒有執行catalog start with '<path>';搜尋備份。
  5. 恢復數據庫restore database;
  6. 如果是線上備份,您現在可以執行恢復。但不是冷備份。
  7. 使用重置日誌打開數據庫。

無需應用重做即可恢復數據庫的命令。如果您不希望數據庫前滾,請確保存檔日誌目錄中沒有文件。您可以 tar 並刪除它們,或者只是將它們移動到別處。

shutdown abort;
startup nomount;
restore controlfile from '/u02/backups/dbname/dbname_1cpqqnpv_1_1_20141222_1';
alter database mount;
restore database;
alter database open resetlogs;

引用自:https://dba.stackexchange.com/questions/89408