Oracle 異機恢復 - 僅僅恢復業務表空間

-- 場景
數據庫中單獨的一個表被delete或者truncate。排除可能進行閃回、日誌挖掘、閃回查詢、基於時間點的表空間恢復等方法,在11g上只能進行異機恢復。然後抽出數據,導入到生產庫。在12c開始,支持RMAN對錶的恢復。當庫的大小不太大的時候,異機恢復還可以,當庫爲幾個T的時候,爲了一個表的數據恢復幾個T的數據,時間上比較難以接受。本測試,主要測試,僅僅恢復表所在的表空間,來節約恢復時間。經過測試,能達到目的。
測試環境:RDBMS 11.2.0.4 + redhat7.4
恢復到Windows Server 2008 + RDBMS 11.2.0.4


--測試過程,(在同一臺機器上進行恢復測試,所以不涉及數據文件路徑、redo log路徑轉換。異機的時候轉換下)
## 對數據庫做一次全備
## 刪除掉數據庫所有的文件
## 恢復SPFILE、控制文件
## 在同一臺機器上進行恢復,僅僅恢復SYSTEM、SYSAUX、XTTS等表空間(XTTS爲業務表空間)數據文件,SPFILE、控制文件等
## 重新創建控制文件,去除掉控制文件中除過SYSTEM、SYSAUX、XTTS之外的數據文件
## 對數據庫進行recover(會產生其他表空間的數據文件,實際路徑下並沒有該文件)
## open resetlogs 開庫
## 導出數據 ,導入數據。

-- 數據庫上原有的數據文件

RMAN> report schema;

Report of database schema for database with db_unique_name TESTOGG

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    800      SYSTEM               ***     /u01/app/oracle/oradata/testogg/system01.dbf
2    590      SYSAUX               ***     /u01/app/oracle/oradata/testogg/sysaux01.dbf
3    1150     UNDOTBS1             ***     /u01/app/oracle/oradata/testogg/undotbs01.dbf
4    18       USERS                ***     /u01/app/oracle/oradata/testogg/users01.dbf
5    346      EXAMPLE              ***     /u01/app/oracle/oradata/testogg/example01.dbf
6    200      GGS_TBS              ***     /u01/app/oracle/oradata/testogg/ggs_tbs01.dbf
7    10       BB_TBS               ***     /u01/app/oracle/oradata/testogg/bb_tbs01.dbf
8    50       TEST_TBS             ***     /u01/app/oracle/oradata/testogg/test_tbs01.dbf
9    100      XTTS                 ***     /u01/app/oracle/oradata/testogg/xtts01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    68       TEMP                 32767       /u01/app/oracle/oradata/testogg/temp01.dbf

RMAN>

-- 啓動庫到nomount 狀態

RMAN> startup nomount force;

Oracle instance started

Total System Global Area     835104768 bytes

Fixed Size                     2257840 bytes
Variable Size                281021520 bytes
Database Buffers             545259520 bytes
Redo Buffers                   6565888 bytes

 

-- 還原spfile,略

-- 還原控制文件

RMAN> restore controlfile from '/backup/control_TESTOGG_20200606_0bv22fdf_1_1';

Starting restore at 06-JUN-20
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/testogg/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/testogg/control02.ctl
Finished restore at 06-JUN-20

RMAN> startup mount;

database is already started
database mounted
released channel: ORA_DISK_1

RMAN>

-- 還原表空間 system,sysaux,undotbs1,xtts的數據文件

RMAN> restore tablespace system,sysaux,undotbs1,XTTS ;

Starting restore at 06-JUN-20
Starting implicit crosscheck backup at 06-JUN-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
Crosschecked 7 objects
Finished implicit crosscheck backup at 06-JUN-20

Starting implicit crosscheck copy at 06-JUN-20
using channel ORA_DISK_1
Crosschecked 1 objects
Finished implicit crosscheck copy at 06-JUN-20

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

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 00003 to /u01/app/oracle/oradata/testogg/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/testogg/xtts01.dbf
channel ORA_DISK_1: reading from backup piece /backup/fulldb_TESTOGG_20200606_05v22f8r_1_1
channel ORA_DISK_1: piece handle=/backup/fulldb_TESTOGG_20200606_05v22f8r_1_1 tag=TAG20200606T100203
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
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/testogg/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/testogg/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /backup/fulldb_TESTOGG_20200606_04v22f8r_1_1
channel ORA_DISK_1: piece handle=/backup/fulldb_TESTOGG_20200606_04v22f8r_1_1 tag=TAG20200606T100203
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 06-JUN-20

RMAN>

-- 直接對錶空間進行recover,是不可以的 。

RMAN> recover tablespace system,sysaux,undotbs1,XTTS ;

Starting recover at 06-JUN-20
using channel ORA_DISK_1

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/06/2020 10:19:41
RMAN-06067: RECOVER DATABASE required with a backup or created control file

RMAN>

-- 如果對庫進行recover的話,會提示其他數據文件不存在。比如提示4號文件,USERS表空間文件是不存在的。(所以需要做的事情,就是重建控制文件。排除這些文件)

RMAN> recover database;

Starting recover at 06-JUN-20
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/06/2020 10:23:13
RMAN-06094: datafile 4 must be restored

--無論是drop 表空間,還是offline表空間,都不可以

-- 重新創建控制文件,其他業務表空間的數據文件不需要。前提是system表空間文件要在(這個時候,已經把system、sysaux、xtts表空間的數據文件已經還原出來)

SYS@testogg>startup nomount
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             281021520 bytes
Database Buffers          545259520 bytes
Redo Buffers                6565888 bytes
SYS@testogg>CREATE CONTROLFILE REUSE DATABASE "TESTOGG" RESETLOGS FORCE LOGGING ARCHIVELOG
      2  MAXLOGFILES 16
    M  3  AXLOGMEMBERS 3
   4     MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
LOG  7  FILE
  G  8  ROUP 1 '/u01/app/oracle/oradata/testogg/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/u01/app/oracle/oradata/testogg/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GRO 10  UP 3 '/u01/app/oracle/oradata/testogg/redo03.log'  SIZE 50M BLOCKSIZE 512
-- ST 11  ANDBY LOGFILE
DAT 12  AFILE
 13    '/u01/app/oracle/oradata/testogg/system01.dbf',
   14  '/u01/app/oracle/oradata/testogg/sysaux01.dbf',
 15    '/u01/app/oracle/oradata/testogg/undotbs01.dbf',
   16  '/u01/app/oracle/oradata/testogg/xtts01.dbf'
CHA 17  RACTER SET AL32UTF8
 18  ;

Control file created.

SYS@testogg>

-- catalog 備份文件

RMAN> catalog start with '/backup/';

using target database control file instead of recovery catalog
searching for all files that match the pattern /backup/

List of Files Unknown to the Database
=====================================
File Name: /backup/fulldb_TESTOGG_20200606_07v22fa2_1_1
File Name: /backup/fulldb_TESTOGG_20200606_06v22f9u_1_1
File Name: /backup/arc_TESTOGG_20200606_0av22fde_1_1
File Name: /backup/fulldb_TESTOGG_20200606_04v22f8r_1_1
File Name: /backup/arc_TESTOGG_20200606_09v22fbn_1_1
File Name: /backup/arc_TESTOGG_20200606_08v22fbn_1_1
File Name: /backup/control_TESTOGG_20200606_0bv22fdf_1_1
File Name: /backup/spfile_TESTOGG_20200606_0cv22fdh_1_1
File Name: /backup/fulldb_TESTOGG_20200606_05v22f8r_1_1
File Name: /backup/xtts/full/XTTS_9.tf
File Name: /backup/xtts/inc/02v1lmv6_1_1
File Name: /backup/xtts/inc/03v1lof9_1_1

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /backup/fulldb_TESTOGG_20200606_07v22fa2_1_1
File Name: /backup/fulldb_TESTOGG_20200606_06v22f9u_1_1
File Name: /backup/arc_TESTOGG_20200606_0av22fde_1_1
File Name: /backup/fulldb_TESTOGG_20200606_04v22f8r_1_1
File Name: /backup/arc_TESTOGG_20200606_09v22fbn_1_1
File Name: /backup/arc_TESTOGG_20200606_08v22fbn_1_1
File Name: /backup/control_TESTOGG_20200606_0bv22fdf_1_1
File Name: /backup/spfile_TESTOGG_20200606_0cv22fdh_1_1
File Name: /backup/fulldb_TESTOGG_20200606_05v22f8r_1_1
File Name: /backup/xtts/full/XTTS_9.tf
File Name: /backup/xtts/inc/02v1lmv6_1_1
File Name: /backup/xtts/inc/03v1lof9_1_1

RMAN>

--recover數據庫

RMAN> recover database;

Starting recover at 06-JUN-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=84
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=85
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=86
channel ORA_DISK_1: reading from backup piece /backup/arc_TESTOGG_20200606_09v22fbn_1_1
channel ORA_DISK_1: piece handle=/backup/arc_TESTOGG_20200606_09v22fbn_1_1 tag=TAG20200606T100334
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
archived log file name=/archive_log/1_84_1037791425.dbf thread=1 sequence=84
archived log file name=/archive_log/1_85_1037791425.dbf thread=1 sequence=85
archived log file name=/archive_log/1_86_1037791425.dbf thread=1 sequence=86
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=87
channel ORA_DISK_1: reading from backup piece /backup/arc_TESTOGG_20200606_0av22fde_1_1
channel ORA_DISK_1: piece handle=/backup/arc_TESTOGG_20200606_0av22fde_1_1 tag=TAG20200606T100334
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/archive_log/1_87_1037791425.dbf thread=1 sequence=87
unable to find archived log
archived log thread=1 sequence=88
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 06/06/2020 10:39:19
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 88 and starting SCN of 1493690

RMAN>

-- Open restlogs 打開數據庫

RMAN> alter database open resetlogs;

database opened

RMAN>

-- recover完畢,RMAN下report schema 。發現其他的表空間數據文件是存在的。大小是0.文件名稱是MISSING0000X。

RMAN> report schema;

Report of database schema for database with db_unique_name TESTOGG

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    800      SYSTEM               ***     /u01/app/oracle/oradata/testogg/system01.dbf
2    590      SYSAUX               ***     /u01/app/oracle/oradata/testogg/sysaux01.dbf
3    1150     UNDOTBS1             ***     /u01/app/oracle/oradata/testogg/undotbs01.dbf
4    0        USERS                ***     /u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00004
5    0        EXAMPLE              ***     /u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00005
6    0        GGS_TBS              ***     /u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00006
7    0        BB_TBS               ***     /u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00007
8    0        TEST_TBS             ***     /u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00008
9    100      XTTS                 ***     /u01/app/oracle/oradata/testogg/xtts01.dbf

RMAN>

-- 查看錶空間信息。 其他表空間還是有的。

SYS@testogg>select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
EXAMPLE
GGS_TBS
BB_TBS
TEST_TBS
XTTS

10 rows selected.

SYS@testogg>

SYS@testogg>select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/testogg/xtts01.dbf
/u01/app/oracle/oradata/testogg/undotbs01.dbf
/u01/app/oracle/oradata/testogg/sysaux01.dbf
/u01/app/oracle/oradata/testogg/system01.dbf
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00004
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00005
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00006
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00007
/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00008

9 rows selected.

SYS@testogg>

-- 當進行drop 掉表空間的時候,提示無法drop。

SYS@testogg>drop tablespace users;
drop tablespace users
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-00376: file 6 cannot be read at this time
ORA-01111: name for data file 6 is unknown - rename to correct file
ORA-01110: data file 6:
'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00006'
ORA-06512: at line 1166
ORA-00376: file 6 cannot be read at this time
ORA-01111: name for data file 6 is unknown - rename to correct file
ORA-01110: data file 6:
'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00006'


SYS@testogg>

-- 實際上dbs裏面並沒有這些文件

[oracle@oggtest backup]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs
[oracle@oggtest dbs]$ ll
total 9836
-rw-rw----. 1 oracle oinstall     1544 Apr 15 10:56 hc_orcl.dat
-rw-rw----. 1 oracle oinstall     1544 Apr 15 11:18 hc_test.dat
-rw-rw----. 1 oracle oinstall     1544 Jun  6 10:40 hc_testogg.dat
-rw-r--r--. 1 oracle oinstall     2851 May 15  2009 init.ora
-rw-r-----. 1 oracle oinstall       24 Apr 15 11:23 lkTESTOGG
-rw-r-----. 1 oracle oinstall     1536 Apr 15 14:37 orapwtestogg
-rw-r-----  1 oracle oinstall 10043392 Jun  6 10:04 snapcf_testogg.f
-rw-r-----. 1 oracle oinstall     3584 Jun  6 10:41 spfiletestogg.ora
[oracle@oggtest dbs]$

-- 測試下,啓動關閉庫 ,啓動關閉正常。

SYS@testogg>shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@testogg>startup
ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size                  2257840 bytes
Variable Size             281021520 bytes
Database Buffers          545259520 bytes
Redo Buffers                6565888 bytes
Database mounted.
Database opened.
SYS@testogg>

-- 再次重建控制文件。發下這些MISSING0000X文件還是有的 (過程略)

-- 導出數據試試 ,數據在表空間xtts中 (其實到了這一步,庫能起來,能看到表。方法就比較多了)

SYS@testogg>conn u_xtts/oracle
Connected.
U_XTTS@testogg>desc t_xtts
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 OWNER                                              VARCHAR2(30)
 OBJECT_NAME                                        VARCHAR2(128)
 SUBOBJECT_NAME                                     VARCHAR2(30)
 OBJECT_ID                                          NUMBER
 DATA_OBJECT_ID                                     NUMBER
 OBJECT_TYPE                                        VARCHAR2(19)
 CREATED                                            DATE
 LAST_DDL_TIME                                      DATE
 TIMESTAMP                                          VARCHAR2(19)
 STATUS                                             VARCHAR2(7)
 TEMPORARY                                          VARCHAR2(1)
 GENERATED                                          VARCHAR2(1)
 SECONDARY                                          VARCHAR2(1)
 NAMESPACE                                          NUMBER
 EDITION_NAME                                       VARCHAR2(30)

U_XTTS@testogg>select count(*) from t_xtts;

  COUNT(*)
----------
    261273

U_XTTS@testogg>
U_XTTS@testogg>select default_tablespace from dba_users where username='U_XTTS';

DEFAULT_TABLESPACE
------------------------------
XTTS

U_XTTS@testogg>

--expdp無法導出表(記得以前用RMAN從Linux恢復到Windows下,使用隱含參數_allow_restlogs_corruption打開庫,也是無法使用數據泵,使用exp解決了)

[oracle@oggtest trace]$ expdp 'u_xtts/oracle' directory=UDMP dumpfile=xtts.dmp tables=T_XTTS

Export: Release 11.2.0.4.0 - Production on Sat Jun 6 10:57:16 2020

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-31626: job does not exist
ORA-31633: unable to create master table "U_XTTS.SYS_EXPORT_TABLE_05"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.KUPV$FT", line 1038
ORA-00376: file 6 cannot be read at this time
ORA-01111: name for data file 6 is unknown - rename to correct file
ORA-01110: data file 6: '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00006'
ORA-06512: at line 1166
ORA-00376: file 6 cannot be read at this time
ORA-01111: name for data file 6 is unknown - rename to correct file
ORA-01110: data file 6: '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/MISSING00006'


[oracle@oggtest trace]$

-- 使用exp可以導出數據

[oracle@oggtest trace]$ exp u_xtts/oracle file=/home/oracle/a.dmp tables=t_xtts

Export: Release 11.2.0.4.0 - Production on Sat Jun 6 10:59:47 2020

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


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
. . exporting table                         T_XTTS     261273 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
[oracle@oggtest trace]$

-- 導入測試

PS C:\Users\Administrator> sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on 星期六 6月 6 13:07:58 2020

Copyright (c) 1982, 2017, Oracle.  All rights reserved.

@>conn system/oracle
Connected.

SYSTEM@test>create user u_xtts identified by oracle;

User created.

SYSTEM@test>grant connect,resource to u_xtts;

Grant succeeded.

SYSTEM@test>grant dba to u_xtts;

Grant succeeded.

SYSTEM@test>

PS C:\Users\Administrator> imp u_xtts/oracle file=c:\dump\a.dmp tables=t_xtts

Import: Release 11.2.0.4.0 - Production on 星期六 6月 6 13:12:30 2020

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


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V11.02.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
export client uses US7ASCII character set (possible charset conversion)
export server uses UTF8 NCHAR character set (possible ncharset conversion)
. importing U_XTTS's objects into U_XTTS
. importing U_XTTS's objects into U_XTTS
. . importing table                       "T_XTTS"     261273 rows imported
Import terminated successfully without warnings.
PS C:\Users\Administrator>

-- 驗證下數據

SYSTEM@test>conn u_xtts/oracle
Connected.
U_XTTS@test>select count(*) from t_xtts;

  COUNT(*)
----------
    261273

U_XTTS@test>delete from t_xtts where object_id=500;

3 rows deleted.

U_XTTS@test>commit;

Commit complete.

U_XTTS@test>select count(*) from t_xtts;

  COUNT(*)
----------
    261270

U_XTTS@test>

END

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章