Oracle 學習之RMAN(十二)恢複實戰--控制檔案丟失

來源:互聯網
上載者:User

標籤:rman 控制檔案丟失

  1. 首先我們進行一次全庫備份

RMAN> run {  backup database   format ‘/backup/full_%d_%T_%s‘  plus archivelog   format ‘/backup/arch_%d_%T_%s‘  delete all input; } Starting backup at 2015/07/09 09:35:03current log archivedusing channel ORA_DISK_1channel ORA_DISK_1: starting archived log backup setchannel ORA_DISK_1: specifying archived log(s) in backup setinput archived log thread=1 sequence=28 RECID=27 STAMP=884590414channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:35:03channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:35:04piece handle=/backup/arch_DEVDB_20150709_115 tag=TAG20150709T093503 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01channel ORA_DISK_1: deleting archived log(s)archived log file name=/backup/archivelog/1_28_884357806.dbf RECID=27 STAMP=884590414channel ORA_DISK_1: starting archived log backup setchannel ORA_DISK_1: specifying archived log(s) in backup setinput archived log thread=1 sequence=1 RECID=28 STAMP=884597703channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:35:05channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:35:06piece handle=/backup/arch_DEVDB_20150709_116 tag=TAG20150709T093503 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01channel ORA_DISK_1: deleting archived log(s)archived log file name=/backup/archivelog/1_1_884591314.dbf RECID=28 STAMP=884597703Finished backup at 2015/07/09 09:35:06Starting backup at 2015/07/09 09:35:06using channel ORA_DISK_1channel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setinput datafile file number=00001 name=/u01/app/oracle/oradata/devdb/system01.dbfinput datafile file number=00002 name=/u01/app/oracle/oradata/devdb/sysaux01.dbfinput datafile file number=00005 name=/u01/app/oracle/oradata/devdb/example01.dbfinput datafile file number=00003 name=/u01/app/oracle/oradata/devdb/undotbs01.dbfinput datafile file number=00004 name=/u01/app/oracle/oradata/devdb/users01.dbfinput datafile file number=00006 name=/u01/app/oracle/oradata/devdb/idx01.dbfchannel ORA_DISK_1: starting piece 1 at 2015/07/09 09:35:06channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:36:41piece handle=/backup/full_DEVDB_20150709_117 tag=TAG20150709T093506 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:01:35channel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setincluding current control file in backup setincluding current SPFILE in backup setchannel ORA_DISK_1: starting piece 1 at 2015/07/09 09:36:42channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:36:43piece handle=/backup/full_DEVDB_20150709_118 tag=TAG20150709T093506 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01Finished backup at 2015/07/09 09:36:43Starting backup at 2015/07/09 09:36:43current log archivedusing channel ORA_DISK_1channel ORA_DISK_1: starting archived log backup setchannel ORA_DISK_1: specifying archived log(s) in backup setinput archived log thread=1 sequence=2 RECID=29 STAMP=884597804channel ORA_DISK_1: starting piece 1 at 2015/07/09 09:36:44channel ORA_DISK_1: finished piece 1 at 2015/07/09 09:36:45piece handle=/backup/arch_DEVDB_20150709_119 tag=TAG20150709T093644 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01channel ORA_DISK_1: deleting archived log(s)archived log file name=/backup/archivelog/1_2_884591314.dbf RECID=29 STAMP=884597804Finished backup at 2015/07/09 09:36:45RMAN>


2.對資料庫中的表進行資料修改。

SQL> conn scott/tigerConnected.SQL> select count(*) from emp_new;  COUNT(*)----------    229376SQL> delete from emp_new where deptno=10;49152 rows deleted.SQL> commit;Commit complete.SQL> select count(*) from emp_new;  COUNT(*)----------    180224

3. 將資料庫關閉。

SQL> conn / as sysdbaConnected.SQL> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.SQL>

4. 刪除控制檔案

SQL> ! rm /u01/app/oracle/oradata/devdb/control01.ctl SQL> ! rm /u01/app/oracle/fast_recovery_area/devdb/control02.ctl

5. 使用rman恢複控制檔案

RMAN> restore controlfile from ‘//backup/full_DEVDB_20150709_118‘;Starting restore at 2015/07/09 09:46:41using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=19 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:02output file name=/u01/app/oracle/oradata/devdb/control01.ctloutput file name=/u01/app/oracle/fast_recovery_area/devdb/control02.ctlFinished restore at 2015/07/09 09:46:43RMAN>

6. 將資料庫啟動到mount狀態

RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1

7.還原並恢複資料庫

RMAN> restore database;Starting restore at 2015/07/09 09:48:56Starting implicit crosscheck backup at 2015/07/09 09:48:56allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=21 device type=DISKCrosschecked 3 objectsFinished implicit crosscheck backup at 2015/07/09 09:48:56Starting implicit crosscheck copy at 2015/07/09 09:48:56using channel ORA_DISK_1Finished implicit crosscheck copy at 2015/07/09 09:48:56searching for all files in the recovery areacataloging files...no files catalogedusing channel ORA_DISK_1channel ORA_DISK_1: starting datafile backup set restorechannel ORA_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/devdb/system01.dbfchannel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/devdb/sysaux01.dbfchannel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/devdb/undotbs01.dbfchannel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/devdb/users01.dbfchannel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/devdb/example01.dbfchannel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/devdb/idx01.dbfchannel ORA_DISK_1: reading from backup piece /backup/full_DEVDB_20150709_117channel ORA_DISK_1: piece handle=/backup/full_DEVDB_20150709_117 tag=TAG20150709T093506channel ORA_DISK_1: restored backup piece 1channel ORA_DISK_1: restore complete, elapsed time: 00:01:15Finished restore at 2015/07/09 09:50:12RMAN> recover database;Starting recover at 2015/07/09 09:51:57using channel ORA_DISK_1datafile 6 not processed because file is read-onlystarting media recoveryarchived log for thread 1 with sequence 2 is already on disk as file /u01/app/oracle/oradata/devdb/redo02.logarchived log for thread 1 with sequence 3 is already on disk as file /u01/app/oracle/oradata/devdb/redo03.logarchived log file name=/u01/app/oracle/oradata/devdb/redo02.log thread=1 sequence=2archived log file name=/u01/app/oracle/oradata/devdb/redo03.log thread=1 sequence=3Oracle Error: ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error belowORA-01190: control file or data file 6 is from before the last RESETLOGSORA-01110: data file 6: ‘/u01/app/oracle/oradata/devdb/idx01.dbf‘media recovery complete, elapsed time: 00:00:04Finished recover at 2015/07/09 09:52:02

我們可以看到,恢複完成了。但是根據日誌可以看出,resetlogs開啟資料庫時會報錯的。

我們嘗試開啟看看

RMAN> alter database open resetlogs;RMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of alter db command at 07/09/2015 09:53:21ORA-01190: control file or data file 6 is from before the last RESETLOGSORA-01110: data file 6: ‘/u01/app/oracle/oradata/devdb/idx01.dbf‘

恢複資料庫時,有這麼一段資訊

datafile 6 not processed because file is read-only

原因找打了,在做Database Backup時,datafile 6是唯讀。我們備份完畢後,修改表emp_new中的資料時,將datafile 6改成了讀寫入模式。在做恢複時,並沒有去恢複datafile 6. 導致資料檔案最終不一致。

所以可以得出結論一旦有資料表空間由唯讀變成讀寫入模式後,一定要做一次全量備份

我們將datafile 6 offline。再次開啟資料庫。

SQL> alter database datafile 6 offline;Database altered.RMAN> alter database open resetlogs;database openedRMAN>

雖說我們是使用resetlogs開啟的資料庫,但是再做資料庫恢複時,也應用了線上日誌。那麼資料就應該沒有丟失。我們做一個檢驗

SQL> conn scott/tigerConnected.SQL> select count(*) from emp_new;  COUNT(*)----------    180224SQL>


但是我們仔細的想一想,其實是有問題的。我丟失的只是控制檔案,不應該真的去恢複我的資料庫。如果是手工管理的備份恢複,只需執行如下語句即可完成恢複

SQL> recover database using backup controlfile;

恢複的速度會快很多。為啥RMAN沒有提供類似功能呢?


本文出自 “叮咚” 部落格,請務必保留此出處http://lqding.blog.51cto.com/9123978/1680701

Oracle 學習之RMAN(十二)恢複實戰--控制檔案丟失

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.