備份與恢復系列 九 丟失表空間資料檔案的還原與恢復
如果個別的資料檔案發生丟失或損壞,在資料庫處於OPEN狀態時可以採用RMAN輕鬆恢復(只要該檔案不屬於系統表空間也不屬於undo表空間)RAMN可以對一個或多個表空間中的資料檔案進行還原與恢復。需要注意的是恢復表空間的資料檔案需要把包含該資料檔案的表空間先離線(offline)然後再還原並恢復資料檔案,最後再將表空間聯機(online),使用的命令如下
ALTER TABLESPACE OFFLINE immediate;
restore
recover
ALTER TABLESPACE OFFLINE/ONLINE;
1,向測試物件SCOTT的dept表新增資料, 實驗的結尾要核對該資料是否被成功恢復
SYS@PRACTICE >select * from scott.dept;
DEPTNO DNAME LOC
---------- ------------------------------------------ ---------------------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SYS@PRACTICE >INSERT INTO scott.dept (deptno,dname,loc) VALUES (50,'SUPPORT','DaLian');
SYS@PRACTICE >commit;
SYS@PRACTICE >ALTER SYSTEM SWITCH LOGFILE;
SYS@PRACTICE >ALTER SYSTEM SWITCH LOGFILE;
SYS@PRACTICE >ALTER SYSTEM SWITCH LOGFILE;
透過檢視DBA_SEGMENTS, 我們可以確認SCOTT使用者的表DEPT屬於表空間USERS
SYS@PRACTICE >col OWNER for a10
SYS@PRACTICE >col SEGMENT_NAME for a10
SYS@PRACTICE >col TABLESPACE_NAME for a10
SYS@PRACTICE >SELECT OWNER,SEGMENT_NAME,TABLESPACE_NAME FROM DBA_SEGMENTS WHERE OWNER='SCOTT';
OWNER SEGMENT_NA TABLESPACE
---------- ---------- ----------
SCOTT DEPT USERS
SCOTT EMP USERS
SCOTT PK_DEPT USERS
SCOTT PK_EMP USERS
SCOTT SALGRADE USERS
2,刪除表空間USERS的資料檔案users01.dbf
SYS@PRACTICE >host
[oracle@practice3 ~]$ rm /oradata/PRACTICE/users01.dbf
[oracle@practice3 ~]$ exit
3,透過ALTER TABLESPACE USERS ONLINE來觸發檢查點事件
系統提示4號資料檔案不存在
SYS@PRACTICE >alter tablespace users online;
alter tablespace users online
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/oradata/PRACTICE/users01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
透過dba_data_files查詢確認了4號檔案為USERS表空間資料檔案
SYS@PRACTICE >col FILE_NAME for a50
SYS@PRACTICE >col TABLESPACE_NAME for a20
SYS@PRACTICE >select FILE_ID,FILE_NAME,TABLESPACE_NAME from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- -------------------------------------------------- --------------------
4 /oradata/PRACTICE/users01.dbf USERS
3 /oradata/PRACTICE/undotbs01.dbf UNDOTBS1
2 /oradata/PRACTICE/sysaux01.dbf SYSAUX
1 /oradata/PRACTICE/system01.dbf SYSTEM
5 /oradata/PRACTICE/example01.dbf EXAMPLE
6 /oradata/tools01.dbf TOOLS
7 /oradata/indx01.dbf INDX
4,恢復USERS表空間的4號資料檔案
用vi編輯恢復指令碼,注意開頭的offline語句和結尾的online語句。
vi /home/oracle/recover_datafile4.sql
sql 'alter tablespace users offline immediate';
run{
allocate channel c1 type disk;
restore datafile 4;
recover tablespace users;
sql 'alter tablespace users online';
}
執行恢復指令碼
RMAN> @recover_datafile4.sql
allocated channel: c1
channel c1: SID=19 device type=DISK
Starting restore at 2014/08/27 13:41:02
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00004 to /oradata/PRACTICE/users01.dbf
channel c1: reading from backup piece /backup/PRACTICE_in0_47_1_855800878
channel c1: piece handle=/backup/PRACTICE_in0_47_1_855800878 tag=WHOLE_IN0
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
Finished restore at 2014/08/27 13:41:03
Starting recover at 2014/08/27 13:41:04
channel c1: starting incremental datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /oradata/PRACTICE/users01.dbf
channel c1: reading from backup piece /backup/db_in1_PRACTICE_55_1_856690214
channel c1: piece handle=/backup/db_in1_PRACTICE_55_1_856690214 tag=WHOLE_INC1
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
starting media recovery
archived log for thread 1 with sequence 38 is already on disk as file /archive/1_38_855750293.arc
archived log for thread 1 with sequence 39 is already on disk as file /archive/1_39_855750293.arc
archived log for thread 1 with sequence 40 is already on disk as file /archive/1_40_855750293.arc
archived log for thread 1 with sequence 41 is already on disk as file /archive/1_41_855750293.arc
archived log for thread 1 with sequence 42 is already on disk as file /archive/1_42_855750293.arc
archived log file name=/archive/1_38_855750293.arc thread=1 sequence=38
archived log file name=/archive/1_39_855750293.arc thread=1 sequence=39
archived log file name=/archive/1_40_855750293.arc thread=1 sequence=40
media recovery complete, elapsed time: 00:00:00
Finished recover at 2014/08/27 13:41:05
sql statement: alter tablespace users online
released channel: c1
RMAN> **end-of-file**
5,驗證4號資料檔案恢復效果
SCOTT@PRACTICE >select * from dept;
DEPTNO DNAME LOC
---------- ------------------------------------------ ---------------------------------------
50 SUPPORT DaLian
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
記錄還在,此次恢復資料檔案實驗成功。
ALTER TABLESPACE
restore
recover
ALTER TABLESPACE
1,向測試物件SCOTT的dept表新增資料, 實驗的結尾要核對該資料是否被成功恢復
SYS@PRACTICE >select * from scott.dept;
DEPTNO DNAME LOC
---------- ------------------------------------------ ---------------------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SYS@PRACTICE >INSERT INTO scott.dept (deptno,dname,loc) VALUES (50,'SUPPORT','DaLian');
SYS@PRACTICE >commit;
SYS@PRACTICE >ALTER SYSTEM SWITCH LOGFILE;
SYS@PRACTICE >ALTER SYSTEM SWITCH LOGFILE;
SYS@PRACTICE >ALTER SYSTEM SWITCH LOGFILE;
透過檢視DBA_SEGMENTS, 我們可以確認SCOTT使用者的表DEPT屬於表空間USERS
SYS@PRACTICE >col OWNER for a10
SYS@PRACTICE >col SEGMENT_NAME for a10
SYS@PRACTICE >col TABLESPACE_NAME for a10
SYS@PRACTICE >SELECT OWNER,SEGMENT_NAME,TABLESPACE_NAME FROM DBA_SEGMENTS WHERE OWNER='SCOTT';
OWNER SEGMENT_NA TABLESPACE
---------- ---------- ----------
SCOTT DEPT USERS
SCOTT EMP USERS
SCOTT PK_DEPT USERS
SCOTT PK_EMP USERS
SCOTT SALGRADE USERS
2,刪除表空間USERS的資料檔案users01.dbf
SYS@PRACTICE >host
[oracle@practice3 ~]$ rm /oradata/PRACTICE/users01.dbf
[oracle@practice3 ~]$ exit
3,透過ALTER TABLESPACE USERS ONLINE來觸發檢查點事件
系統提示4號資料檔案不存在
SYS@PRACTICE >alter tablespace users online;
alter tablespace users online
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: '/oradata/PRACTICE/users01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
透過dba_data_files查詢確認了4號檔案為USERS表空間資料檔案
SYS@PRACTICE >col FILE_NAME for a50
SYS@PRACTICE >col TABLESPACE_NAME for a20
SYS@PRACTICE >select FILE_ID,FILE_NAME,TABLESPACE_NAME from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- -------------------------------------------------- --------------------
4 /oradata/PRACTICE/users01.dbf USERS
3 /oradata/PRACTICE/undotbs01.dbf UNDOTBS1
2 /oradata/PRACTICE/sysaux01.dbf SYSAUX
1 /oradata/PRACTICE/system01.dbf SYSTEM
5 /oradata/PRACTICE/example01.dbf EXAMPLE
6 /oradata/tools01.dbf TOOLS
7 /oradata/indx01.dbf INDX
4,恢復USERS表空間的4號資料檔案
用vi編輯恢復指令碼,注意開頭的offline語句和結尾的online語句。
vi /home/oracle/recover_datafile4.sql
sql 'alter tablespace users offline immediate';
run{
allocate channel c1 type disk;
restore datafile 4;
recover tablespace users;
sql 'alter tablespace users online';
}
執行恢復指令碼
RMAN> @recover_datafile4.sql
allocated channel: c1
channel c1: SID=19 device type=DISK
Starting restore at 2014/08/27 13:41:02
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00004 to /oradata/PRACTICE/users01.dbf
channel c1: reading from backup piece /backup/PRACTICE_in0_47_1_855800878
channel c1: piece handle=/backup/PRACTICE_in0_47_1_855800878 tag=WHOLE_IN0
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
Finished restore at 2014/08/27 13:41:03
Starting recover at 2014/08/27 13:41:04
channel c1: starting incremental datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00004: /oradata/PRACTICE/users01.dbf
channel c1: reading from backup piece /backup/db_in1_PRACTICE_55_1_856690214
channel c1: piece handle=/backup/db_in1_PRACTICE_55_1_856690214 tag=WHOLE_INC1
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
starting media recovery
archived log for thread 1 with sequence 38 is already on disk as file /archive/1_38_855750293.arc
archived log for thread 1 with sequence 39 is already on disk as file /archive/1_39_855750293.arc
archived log for thread 1 with sequence 40 is already on disk as file /archive/1_40_855750293.arc
archived log for thread 1 with sequence 41 is already on disk as file /archive/1_41_855750293.arc
archived log for thread 1 with sequence 42 is already on disk as file /archive/1_42_855750293.arc
archived log file name=/archive/1_38_855750293.arc thread=1 sequence=38
archived log file name=/archive/1_39_855750293.arc thread=1 sequence=39
archived log file name=/archive/1_40_855750293.arc thread=1 sequence=40
media recovery complete, elapsed time: 00:00:00
Finished recover at 2014/08/27 13:41:05
sql statement: alter tablespace users online
released channel: c1
RMAN> **end-of-file**
5,驗證4號資料檔案恢復效果
SCOTT@PRACTICE >select * from dept;
DEPTNO DNAME LOC
---------- ------------------------------------------ ---------------------------------------
50 SUPPORT DaLian
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
記錄還在,此次恢復資料檔案實驗成功。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29047826/viewspace-1259088/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 備份與恢復系列 八 丟失所有資料檔案的還原與恢復
- Oracle備份與恢復【丟失資料檔案的恢復】Oracle
- undo表空間檔案丟失恢復(1)--有備份
- 無新表空間資料檔案備份,歸檔都存在的還原與恢復
- 撤消表空間資料檔案丟失的恢復.
- 備份與恢復--資料檔案損壞或丟失
- 備份與恢復系列 十一 控制檔案的備份與恢復
- 備份恢復之資料檔案丟失
- undo表空間檔案丟失恢復(2)--無備份有redo的情況下恢復
- undo表空間檔案丟失恢復(3)--無備份無redo的情況下恢復
- undo表空間檔案丟失恢復(4)--無備份無recover的情況下恢復
- Oracle備份與恢復【丟失控制檔案的恢復】Oracle
- rman恢復--歸檔模式有備份,丟失資料檔案的恢復模式
- rman恢復--歸檔模式無備份,丟失資料檔案的恢復模式
- 備份與恢復系列 十 引數檔案spfile的備份與恢復
- 恢復案例:歸檔模式下丟失非系統表空間資料檔案的恢復模式
- 【RMAN】SYSTEM表空間資料檔案丟失恢復模擬
- rman恢復資料檔案 恢復表空間
- 【備份恢復】非歸檔模式下丟失任意資料檔案 恢復操作模式
- 【管理篇備份恢復】rman恢復測試(一) 表空間資料檔案
- 【rman 備份與恢復】恢復丟失所有的控制檔案
- 備份與恢復--利用備份的控制檔案恢復
- 【備份恢復】恢復 丟失已歸檔重做日誌檔案
- 【備份恢復】 丟失一個控制檔案 之恢復操作
- 備份與恢復(Parameter 檔案恢復篇)
- RMAN資料庫恢復 之歸檔模式有(無)備份-丟失資料檔案的恢復資料庫模式
- INDEX表空間檔案丟失或者損壞的恢復Index
- 【備份恢復】歸檔模式下丟失系統關鍵資料檔案 利用RMAN備份恢復模式
- 歸檔模式無備份丟失資料檔案後恢復模式
- 歸檔模式有備份丟失資料檔案後恢復模式
- 資料檔案丟失的恢復
- 備份與恢復:polardb資料庫備份與恢復資料庫
- 【備份與恢復】控制檔案的恢復(不完全恢復)
- RMAN恢復案例:丟失全部資料檔案恢復
- 表空間級資料庫備份恢復資料庫
- 備份與恢復--重建控制檔案後資料檔案損壞的恢復
- 【備份與恢復】恢復受損的口令檔案
- 【備份與恢復】archivelog模式中資料檔案的恢復Hive模式