在歸檔下恢復系統資料檔案

skyin_1603發表於2016-10-31
以下是模擬資料庫在歸檔模式(archivelog)下丟失系統關鍵性system表空間及其資料檔案。
該測試也提醒我們,在生成當中一定要將資料庫開啟到歸檔模式下,其次是有計劃地進行有效的備份。
因為一旦丟失資料庫系統關鍵的資料檔案或者表空間之後,若沒有備份,或者沒有開啟歸檔模式,導致
丟失部分資料。嚴重時候,導致控制檔案或者系統關鍵資料檔案丟失資料而導致資料庫無法啟動。

以下是測試的過程:

---檢視資料庫的歸檔模式:
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     6
Next log sequence to archive   8
Current log sequence           8
SQL> 

---開啟rman備份工具:
[oracle@enmo ~]$  rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Oct 31 22:36:37 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=338469376)   #這裡顯示的是目標庫的資訊#

---為了方便管理備份,配置部分備份引數:
--設定備份檔案的存放路徑:
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/app/backup/db_%U.rmn';

new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT   '/u01/app/backup/db_%U.rmn';
new RMAN configuration parameters are successfully stored

--開啟自動備份控制檔案與引數檔案:
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP on;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

---測試恢復系統關鍵資料檔案:
---透過rman備份系統表空間:
RMAN> backup tablespace system;                  #只備份系統表空間

Starting backup at 31-OCT-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf
channel ORA_DISK_1: starting piece 1 at 31-OCT-16
channel ORA_DISK_1: finished piece 1 at 31-OCT-16
piece handle=/u01/app/backup/db_01rjp9rn_1_1.rmn tag=TAG20161031T224511 comment=NONE     #系統表空間備份的控制程式碼
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:38
Finished backup at 31-OCT-16

Starting Control File and SPFILE Autobackup at 31-OCT-16                #因為上面已經設定自動備份控制檔案
piece handle=/u01/app/oracle/fast_recovery_area/PROD/autobackup/2016_10_31/o1_mf_s_926722009_d1gpbvth_.bkp comment=NONE  
#控制檔案以及引數引數檔案備份的控制程式碼
Finished Control File and SPFILE Autobackup at 31-OCT-16
#備份完成。

---檢視兩個生成的備份檔案:
--system表空間的備份檔案:
[oracle@enmo backup]$ ls
db_01rjp9rn_1_1.rmn
[oracle@enmo backup]$ ll
total 660032
-rw-r----- 1 oracle oinstall 675209216 Oct 31 22:46 db_01rjp9rn_1_1.rmn
[oracle@enmo backup]$ 

--控制檔案與引數檔案的備份檔案:
[oracle@enmo backup]$ cd /u01/app/oracle/fast_recovery_area/PROD/
[oracle@enmo PROD]$ ls
autobackup  control02.ctl  onlinelog
[oracle@enmo PROD]$ 
[oracle@enmo PROD]$ cd autobackup/
[oracle@enmo autobackup]$ ls
2016_10_31
[oracle@enmo autobackup]$ ll
total 4
drwxr-x--- 2 oracle oinstall 4096 Oct 31 22:46 2016_10_31
[oracle@enmo autobackup]$ 

--嘗試刪除系統表空間system表空間:
SQL> select file_name from dba_data_files where tablespace_name='SYSTEM';
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/PROD/system01.dbf

--檢視系統表空間資料檔案的路徑:
SQL> !ls /u01/app/oracle/oradata/PROD/system01.dbf
/u01/app/oracle/oradata/PROD/system01.dbf

--刪除系統表空間的資料檔案:
!rm /u01/app/oracle/oradata/PROD/system01.dbf
#已刪除。

--關閉資料庫並嘗試開啟:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 
SQL> startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             541068368 bytes
Database Buffers          289406976 bytes
Redo Buffers                2371584 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/PROD/system01.dbf'
#開啟資料庫時候報錯,發現沒有系統表空間的資料檔案。

---恢復系統表空間數資料檔案:
--透過RMAN的備份恢復system表空間:
[oracle@enmo ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Oct 31 22:57:58 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=338469376, not open)

RMAN> 

--載入系統表表空間:
RMAN> restore tablespace system;

Starting restore at 31-OCT-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 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 00001 to /u01/app/oracle/oradata/PROD/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/backup/db_01rjp9rn_1_1.rmn
channel ORA_DISK_1: piece handle=/u01/app/backup/db_01rjp9rn_1_1.rmn tag=TAG20161031T224511
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:57
Finished restore at 31-OCT-16
#載入完成。

--恢復系統表空間:
RMAN> recover tablespace system;

Starting recover at 31-OCT-16
using channel ORA_DISK_1

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

Finished recover at 31-OCT-16
#恢復系統表空間及其資料檔案完成。

--嘗試開啟資料庫:
RMAN> alter database open;
database opened
RMAN> 

SQL> select status from v$instance;

STATUS
------------
OPEN
#資料庫已經恢復並開啟。

---檢視系統表空間的資料檔案:
SQL>  !ls /u01/app/oracle/oradata/PROD/system01.dbf
/u01/app/oracle/oradata/PROD/system01.dbf

系統表空間及其資料檔案恢復完成。

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

相關文章