(Les16 執行資料庫恢復)-表空間恢復

請點..頭像發表於2018-05-22
NOARCHIVELOG模式下丟失了資料檔案
    資料庫處於NOARCHIVELOG模式時,如果丟失任何資料檔案,執行以下步驟
        1.如果例項尚未關閉,請關閉例項
        2.從備份還原整個資料庫,包括所有資料檔案和控制檔案
        3.開啟資料庫
        4.讓使用者重新輸入自上次備份以來所做的所有更改
 
ARCHIVELOG模式下丟失了非關鍵性資料檔案(SYSTEM,UNDO除外)
        僅僅恢復當前資料檔案不用整庫恢復,不需要停機
        1.資料檔案離線
        2.restore資料檔案,介質恢復
        3.recover事務
        4.資料檔案聯機
 
ARCHIVELOG模式下丟失了關鍵性資料檔案(SYSTEM,UNDO…)
        資料庫關鍵性資料檔案丟失,需要停機恢復
        1.例項可能會也可能不會自動關閉。如果未自動關閉,請使用SHUTDOWN ABORT關閉例項
        2.裝載資料庫,MOUNT
        3.還原並恢復缺失的資料檔案,restore datafile/database 
        4.recover datafile/database
        5.開啟資料庫
 
 
 
歸檔模式下恢復非關鍵表空間
 
set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;
 
 
建立一個非關鍵表空間進行測試
 
create tablespace redo_data  datafile `/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf` size 32M autoextend on next 32M maxsize 1024M;
 
 
 
SQL> create tablespace redo_data  datafile `/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf` size 32M autoextend on next 32M maxsize 1024M;
 
Tablespace created.
 
SQL> set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;
 
 
TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/xiocpt0/users01.dbf
UNDOTBS1             /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
SYSAUX               /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
SYSTEM               /u01/app/oracle/oradata/xiocpt0/system01.dbf
REDO_DATA            /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
 
 
 
 
BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;
 
對資料進行一次完全備份
 
RMAN> shutdown immediate
RMAN> startup mount
RMAN> run
{
allocate channel c1 device type disk format `/u01/backup/backup01_%U` ;
backup as compressed backupset database;
backup current controlfile;
alter database open;
}
 
 
RMAN> list backup;
 
 
List of Backup Sets
===================
 
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7       Full    321.23M    DISK        00:00:38     22-MAY-18
        BP Key: 7   Status: AVAILABLE  Compressed: YES  Tag: TAG20180522T151208
        Piece Name: /u01/backup/backup01_08t3hoq8_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/system01.dbf
  2       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
  3       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
  4       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/users01.dbf
  5       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8       Full    1.05M      DISK        00:00:03     22-MAY-18
        BP Key: 8   Status: AVAILABLE  Compressed: YES  Tag: TAG20180522T151208
        Piece Name: /u01/backup/backup01_09t3horl_1_1
  SPFILE Included: Modification time: 22-MAY-18
  SPFILE db_unique_name: XIOCPT0
  Control File Included: Ckp SCN: 1058982      Ckp time: 22-MAY-18
 
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9       Full    9.64M      DISK        00:00:01     22-MAY-18
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20180522T151257
        Piece Name: /u01/backup/backup01_0at3horp_1_1
  Control File Included: Ckp SCN: 1058982      Ckp time: 22-MAY-18
 
 
 
建立表並指定表空間
 
SQL> create table REDO_DATA(
  2  id number,
  3  name varchar2(20)
  4  )
  5  tablespace REDO_DATA;
 
Table created.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,`name0`||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> commit;
 
Commit complete.
 
SQL> select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      1000
 
 
 
 
恢復非關鍵表空間
 
 
sql `alter tablespace redo_data offline`;---離線需恢復的表空間
 
 
restore tablespace redo_data;---還原表空間
recover tablespace redo_data;---恢復表空間,期間的事務進行應用
  
  
sql `alter tablespace redo_data online`;---恢復完成,將表空間線上
 
 
刪除資料檔案
SQL> !rm -rf /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
SQL> select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      1000
 
SQL> commit;
 
Commit complete.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,`name0`||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> commit;
 
Commit complete.
 
SQL>  select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      2000
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf: No such file or directory
 
SQL> select table_name ,tablespace_name from dba_tables where table_name=`REDO_DATA`;
 
TABLE_NAME                     TABLESPACE_NAME
------------------------------ --------------------
REDO_DATA                      REDO_DATA
 
SQL> alter system switch logfile;
 
System altered.
 
SQL>  alter system checkpoint;
 
System altered.
 
SQL> select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      2000
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,`name0`||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,`name0`||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> declare
v_count number;
 
begin
  for i in 1..1000 loop
  insert into redo_data values(i,`name0`||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9
 
PL/SQL procedure successfully completed.
 
SQL> commit;
 
Commit complete.
 
SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf: No such file or directory
 
SQL> select count(*) from REDO_DATA;
select count(*) from REDO_DATA
                     *
ERROR at line 1:
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: `/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf`
 
 
開始執行還原/恢復操作
 
RMAN> sql `alter tablespace redo_data offline`;
 
sql statement: alter tablespace redo_data offline
 
RMAN>
restore tablespace redo_data;
RMAN>
 
Starting restore at 22-MAY-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 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 00005 to /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/backup01_08t3hoq8_1_1
channel ORA_DISK_1: piece handle=/u01/backup/backup01_08t3hoq8_1_1 tag=TAG20180522T151208
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 22-MAY-18
 
RMAN>   recover tablespace redo_data;
 
Starting recover at 22-MAY-18
using channel ORA_DISK_1
 
starting media recovery
 
archived log for thread 1 with sequence 74 is already on disk as file /u01/archive/arch_976375926_1_74.arc
archived log for thread 1 with sequence 75 is already on disk as file /u01/archive/arch_976375926_1_75.arc
archived log for thread 1 with sequence 76 is already on disk as file /u01/archive/arch_976375926_1_76.arc
archived log for thread 1 with sequence 77 is already on disk as file /u01/archive/arch_976375926_1_77.arc
archived log for thread 1 with sequence 78 is already on disk as file /u01/archive/arch_976375926_1_78.arc
archived log for thread 1 with sequence 79 is already on disk as file /u01/archive/arch_976375926_1_79.arc
archived log for thread 1 with sequence 80 is already on disk as file /u01/archive/arch_976375926_1_80.arc
archived log for thread 1 with sequence 81 is already on disk as file /u01/archive/arch_976375926_1_81.arc
archived log for thread 1 with sequence 82 is already on disk as file /u01/archive/arch_976375926_1_82.arc
archived log for thread 1 with sequence 83 is already on disk as file /u01/archive/arch_976375926_1_83.arc
archived log for thread 1 with sequence 84 is already on disk as file /u01/archive/arch_976375926_1_84.arc
archived log for thread 1 with sequence 85 is already on disk as file /u01/archive/arch_976375926_1_85.arc
archived log file name=/u01/archive/arch_976375926_1_74.arc thread=1 sequence=74
archived log file name=/u01/archive/arch_976375926_1_75.arc thread=1 sequence=75
archived log file name=/u01/archive/arch_976375926_1_76.arc thread=1 sequence=76
archived log file name=/u01/archive/arch_976375926_1_77.arc thread=1 sequence=77
archived log file name=/u01/archive/arch_976375926_1_78.arc thread=1 sequence=78
archived log file name=/u01/archive/arch_976375926_1_79.arc thread=1 sequence=79
archived log file name=/u01/archive/arch_976375926_1_80.arc thread=1 sequence=80
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-MAY-18
 
RMAN>   sql `alter tablespace redo_data online`;
 
sql statement: alter tablespace redo_data online
 
 
 
SQL>  select count(*) from REDO_DATA;
 
  COUNT(*)
----------
      5000

 

 

 
 
歸檔模式下恢復關鍵表空間
    
    資料庫關鍵性資料檔案丟失,需要停機恢復
        1.例項可能會也可能不會自動關閉。如果未自動關閉,請使用SHUTDOWN ABORT關閉例項
        2.裝載資料庫,MOUNT
        3.還原並恢復缺失的資料檔案,restore datafile/database 
        4.recover datafile/database
        5.開啟資料庫
 
SQL> set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;SQL> SQL> SQL> SQL>
 
TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/xiocpt0/users01.dbf
UNDOTBS1             /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
SYSAUX               /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
SYSTEM               /u01/app/oracle/oradata/xiocpt0/system01.dbf
REDO_DATA            /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
 
SQL>
SQL> !rm -rf /u01/app/oracle/oradata/xiocpt0/system01.dbf
 
 
startup mount ---將資料庫啟動到mount
restore tablespace system;---指定關鍵表空間進行還原
recover tablespace system;---恢復表空間
sql `alter database open`;---將資料庫開啟
 
 
[oracle@t-xi-oracle01 ~]$ rman  target /
 
Recovery Manager: Release 11.2.0.4.0 - Production on Tue May 22 15:30:33 2018
 
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database (not started)
 
RMAN> startup mount
 
Oracle instance started
database mounted
 
Total System Global Area     409194496 bytes
 
Fixed Size                     2253744 bytes
Variable Size                322964560 bytes
Database Buffers              79691776 bytes
Redo Buffers                   4284416 bytes
 
RMAN> restore tablespace system;
 
Starting restore at 22-MAY-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 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/xiocpt0/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/backup01_08t3hoq8_1_1
channel ORA_DISK_1: piece handle=/u01/backup/backup01_08t3hoq8_1_1 tag=TAG20180522T151208
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 22-MAY-18
 
RMAN> recover tablespace system;
 
Starting recover at 22-MAY-18
using channel ORA_DISK_1
 
starting media recovery
 
archived log for thread 1 with sequence 74 is already on disk as file /u01/archive/arch_976375926_1_74.arc
archived log for thread 1 with sequence 75 is already on disk as file /u01/archive/arch_976375926_1_75.arc
archived log for thread 1 with sequence 76 is already on disk as file /u01/archive/arch_976375926_1_76.arc
archived log for thread 1 with sequence 77 is already on disk as file /u01/archive/arch_976375926_1_77.arc
archived log for thread 1 with sequence 78 is already on disk as file /u01/archive/arch_976375926_1_78.arc
archived log for thread 1 with sequence 79 is already on disk as file /u01/archive/arch_976375926_1_79.arc
archived log for thread 1 with sequence 80 is already on disk as file /u01/archive/arch_976375926_1_80.arc
archived log for thread 1 with sequence 81 is already on disk as file /u01/archive/arch_976375926_1_81.arc
archived log for thread 1 with sequence 82 is already on disk as file /u01/archive/arch_976375926_1_82.arc
archived log for thread 1 with sequence 83 is already on disk as file /u01/archive/arch_976375926_1_83.arc
archived log for thread 1 with sequence 84 is already on disk as file /u01/archive/arch_976375926_1_84.arc
archived log for thread 1 with sequence 85 is already on disk as file /u01/archive/arch_976375926_1_85.arc
archived log for thread 1 with sequence 86 is already on disk as file /u01/archive/arch_976375926_1_86.arc
archived log file name=/u01/archive/arch_976375926_1_74.arc thread=1 sequence=74
archived log file name=/u01/archive/arch_976375926_1_75.arc thread=1 sequence=75
archived log file name=/u01/archive/arch_976375926_1_76.arc thread=1 sequence=76
archived log file name=/u01/archive/arch_976375926_1_77.arc thread=1 sequence=77
archived log file name=/u01/archive/arch_976375926_1_78.arc thread=1 sequence=78
archived log file name=/u01/archive/arch_976375926_1_79.arc thread=1 sequence=79
archived log file name=/u01/archive/arch_976375926_1_80.arc thread=1 sequence=80
archived log file name=/u01/archive/arch_976375926_1_81.arc thread=1 sequence=81
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-MAY-18
 
RMAN> sql `alter database open`;
 
sql statement: alter database open

 

 
 
 

 

 
 
 

相關文章