ITPub博客

首页 > 数据库 > Oracle > RMAN tablespace point-in-time recovery (TSPITR)

RMAN tablespace point-in-time recovery (TSPITR)

Oracle 作者:lsy721 时间:2018-06-22 15:56:34 0 删除 编辑
TSPITR 简单的说就是基于时间点的表空间恢复,它可以把一个或多个表空间恢复到过去某个时间点而不影响剩余的表空间或是数据库对象。
RMAN TSPITR主要应用场景如下:
(1)恢复逻辑数据库到某一个时间点,而在数据库物理结构上与其它表空间时间点不同
(2)恢复因使用DDL语言造成的数据丢失
(3)使用purge删除的table 
(4)表的逻辑损坏
(5)恢复删除的表空间,即使不使用catalog,RMAN 一样可以使用TSPITR

在实验中使用的相关技术名词
name exxxasdfasdf
Target instance contains the tablespace to be recovered to the target time    
target time point in time or SCN of the  tablespace after TSPITR completes
auxiliary destination an optional disk location that RMAN uses to temporarily store the auxiliary set files,only used with an RMAN-managed auxiliary instance.
auxiliary instance a database instance  used in the recovery process to perform the work of recovery
recovery set datafiles in the tablespaces that  you  intend to recover
auxiliary set data files requried  fo TSPITR that are not part of the recovery set.
The auxiliary set typically includes: 1.the SYSTEM or SYSAUX tablespaces 2.data file containing rollback or undo segments from the target database instance. 
3. temporary tablespace 4.control file from source database 5.archived redo logs  that must be restored to recover the auxiliary instance to specified point in time.
6. online redo logs of the auxiliary intance.

一、创建实验环境

点击(此处)折叠或打开

  1. SQL> col name for a60
  2. SQL>  select name from v$datafile;
  3. NAME
  4. ------------------------------------------------------------
  5. /oracle/database/oradata/mhxy/system01.dbf
  6. /oracle/database/oradata/mhxy/sysaux01.dbf
  7. /oracle/database/oradata/mhxy/undotbs01.dbf
  8. /oracle/database/oradata/mhxy/users01.dbf
  9. SQL> create tablespace test datafile '/oracle/database/oradata/mhxy/test.dbf' size 10m autoextend off extent management local;
  10. Tablespace created.
  11. SQL> select name from v$datafile;
  12. NAME
  13. ------------------------------------------------------------
  14. /oracle/database/oradata/mhxy/system01.dbf
  15. /oracle/database/oradata/mhxy/sysaux01.dbf
  16. /oracle/database/oradata/mhxy/undotbs01.dbf
  17. /oracle/database/oradata/mhxy/users01.dbf
  18. /oracle/database/oradata/mhxy/test.dbf
  19. SQL> create user test identified by test default tablespace test temporary tablespace temp;
  20. User created.

  21. SQL>  grant dba to test;
  22. Grant succeeded.
  23. SQL> conn test/test
  24. Connected.
  25. SQL> create table tt as select * from user_objects;
  26. Table created.

  27. SQL> create table test.t1 as select * from dba_objects;
  28. create table test.t1 as select * from dba_objects
  29. *
  30. ERROR at line 1:
  31. ORA-01652: unable to extend temp segment by 128 in tablespace TEST

  32. SQL> alter database datafile '/oracle/database/oradata/mhxy/test.dbf' resize 50m;
  33. Database altered.
  34. SQL> create table test.t1 as select * from dba_objects;
  35. Table created.
  36. SQL> conn / as sysdba
  37. Connected.
  38. SQL> select count(*) from test.t1;
  39. COUNT(*)
  40. ----------
  41. 71904
  42. SQL> exit

  43. #通过RMAN 备份数据库#
  44. RMAN> backup as backupset database plus archivelog;

    Starting backup at 2016-07-26 04:45:02
    current log archived
    using target database control file instead of recovery catalog
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=150 device type=DISK
    channel ORA_DISK_1: starting archived log backup set
    channel ORA_DISK_1: specifying archived log(s) in backup set
    input archived log thread=1 sequence=5 RECID=1 STAMP=918187812
    input archived log thread=1 sequence=6 RECID=2 STAMP=918189905
    channel ORA_DISK_1: starting piece 1 at 2016-07-26 04:45:06
    channel ORA_DISK_1: finished piece 1 at 2016-07-26 04:45:13
    piece handle=/oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_annnn_TAG20160726T044506_csdyllfs_.bkp tag=TAG20160726T044506 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
    Finished backup at 2016-07-26 04:45:13

    Starting backup at 2016-07-26 04:45:13
    using channel ORA_DISK_1
    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=/oracle/database/oradata/mhxy/system01.dbf
    input datafile file number=00002 name=/oracle/database/oradata/mhxy/sysaux01.dbf
    input datafile file number=00003 name=/oracle/database/oradata/mhxy/undotbs01.dbf
    input datafile file number=00005 name=/oracle/database/oradata/mhxy/test.dbf
    input datafile file number=00004 name=/oracle/database/oradata/mhxy/users01.dbf
    channel ORA_DISK_1: starting piece 1 at 2016-07-26 04:45:14
    channel ORA_DISK_1: finished piece 1 at 2016-07-26 04:46:51
    piece handle=/oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_nnndf_TAG20160726T044513_csdyltqt_.bkp tag=TAG20160726T044513 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:01:37
    channel ORA_DISK_1: starting full datafile backup set
    channel ORA_DISK_1: specifying datafile(s) in backup set
    including current control file in backup set
    including current SPFILE in backup set
    channel ORA_DISK_1: starting piece 1 at 2016-07-26 04:46:55
    channel ORA_DISK_1: finished piece 1 at 2016-07-26 04:46:56
    piece handle=/oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_ncsnf_TAG20160726T044513_csdyoz8x_.bkp tag=TAG20160726T044513 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
    Finished backup at 2016-07-26 04:46:56

    Starting backup at 2016-07-26 04:46:56
    current log archived
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting archived log backup set
    channel ORA_DISK_1: specifying archived log(s) in backup set
    input archived log thread=1 sequence=7 RECID=3 STAMP=918190016
    channel ORA_DISK_1: starting piece 1 at 2016-07-26 04:46:57
    channel ORA_DISK_1: finished piece 1 at 2016-07-26 04:46:58
    piece handle=/oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_annnn_TAG20160726T044656_csdyp11c_.bkp tag=TAG20160726T044656 comment=NONE
    channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
    Finished backup at 2016-07-26 04:46:58

    RMAN> exit

二、确定需要恢复的时间点(point-in-time),这个时间在实验环境中可以通过自己判断,然后drop tablespace test。但在实际环境中,需要通过logmintor确定,下一篇会阐述下logmintor的使用。

点击(此处)折叠或打开

  1. SQL> set linesize 300
  2. SQL>
  3. SQL> select to_char(scn_to_timestamp(current_scn),'yyyy-mm-dd hh24:mi:ss'),current_scn from v$database;
  4. TO_CHAR(SCN_TO_TIMESTAMP(CURRENT_SCN), CURRENT_SCN
  5. -------------------------------------- -----------
  6. 2016-07-26 04:48:56 1008558
  7. SQL> drop tablespace test including contents and datafiles;
  8. Tablespace dropped.

  9. SQL> select tablespace_name,status from dba_tablespaces;
  10. TABLESPACE_NAME                                              STATUS
    ------------------------------------------------------------ ------------------
    SYSTEM                                                       ONLINE
    SYSAUX                                                       ONLINE
    UNDOTBS1                                                     ONLINE
    TEMP                                                         ONLINE
    USERS                                                        ONLINE
  11. SQL> col name for a50
  12. SQL> select name from v$datafile;   
  13. NAME
  14. --------------------------------------------------
  15. /oracle/database/oradata/mhxy/system01.dbf
  16. /oracle/database/oradata/mhxy/sysaux01.dbf
  17. /oracle/database/oradata/mhxy/undotbs01.dbf
  18. /oracle/database/oradata/mhxy/users01.dbf
  19. SQL> host ll -lrt /oracle/database/oradata/mhxy/
  20. /bin/bash: ll: command not found
  21. SQL> host ls -lrt /oracle/database/oradata/mhxy/
  22. total 1476888
  23. -rw-r----- 1 oracle oinstall 30416896 Jul 26 04:23 temp01.dbf
  24. -rw-r----- 1 oracle oinstall 52429312 Jul 26 04:45 redo03.log
  25. -rw-r----- 1 oracle oinstall 702554112 Jul 26 04:45 system01.dbf
  26. -rw-r----- 1 oracle oinstall 99622912 Jul 26 04:45 undotbs01.dbf
  27. -rw-r----- 1 oracle oinstall 534781952 Jul 26 04:45 sysaux01.dbf
  28. -rw-r----- 1 oracle oinstall 5251072 Jul 26 04:45 users01.dbf
  29. -rw-r----- 1 oracle oinstall 52429312 Jul 26 04:46 redo01.log
  30. -rw-r----- 1 oracle oinstall 52429312 Jul 26 04:50 redo02.log
  31. -rw-r----- 1 oracle oinstall 9748480 Jul 26 04:50 control01.ctl
  32. SQL> exit
  33. #
  34. # 通过视图和操作系统命令发现,表空间test 数据文件test.dbf以及在操作系统目录下面的test.dbf都已经不存在了
三、通过RMAN 进行TSPITR操作,在执行过程很简单,但是在其中也遇到的很多问题。1. auxiliary destination 目录需要在操作系统中通mkdir创建  2. 表空间的名称需要用引号括起来并行字母大写 ,如"TEST"
点击(此处)折叠或打开
  1. RMAN> recover tablespace "test" until time '2016-07-26 04:48:56' auxiliary destination '/oracle/auxiliary';
  2. # 未创建auxiliary destination,表空间名称未大写
  3. Starting recover at 2016-07-26 04:54:30
  4. using target database control file instead of recovery catalog
  5. allocated channel: ORA_DISK_1
  6. channel ORA_DISK_1: SID=138 device type=DISK
  7. RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-time
  8. List of tablespaces expected to have UNDO segments
  9. Tablespace SYSTEM
  10. Tablespace UNDOTBS1
  11. Creating automatic instance, with SID='knwx'
  12. initialization parameters used for automatic instance:
  13. db_name=MHXY
  14. db_unique_name=knwx_tspitr_MHXY
  15. compatible=11.2.0.0.0
  16. db_block_size=8192
  17. db_files=200
  18. sga_target=280M
  19. processes=50
  20. db_create_file_dest=/oracle/auxiliary
  21. log_archive_dest_1='location=/oracle/auxiliary'
  22. #No auxiliary parameter file used
  23. starting up automatic instance MHXY
  24. RMAN-00571: ===========================================================
  25. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  26. RMAN-00571: ===========================================================
  27. RMAN-03002: failure of recover command at 07/26/2016 04:54:40
  28. RMAN-04014: startup failed: ORA-01261: Parameter db_create_file_dest destination string cannot be translated
  29. ORA-01262: Stat failed on a file destination directory
  30. Linux-x86_64 Error: 2: No such file or directory
  31. RMAN> exit
  32. Recovery Manager complete.
  33. [oracle@mhxy164 ~]$ mkdir -p /oracle/auxiliary
  34. [oracle@mhxy164 ~]$ ll !$
  35. ll /oracle/auxiliary
  36. total 0
  37. [oracle@mhxy164 ~]$ echo $?
  38. $?
  39. [oracle@mhxy164 ~]$ rman target /
  40. Recovery Manager: Release 11.2.0.1.0 - Production on Tue Jul 26 04:55:14 2016
  41. Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
  42. connected to target database: MHXY (DBID=4238569140)
  43. RMAN> recover tablespace "test" until time '2016-07-26 04:48:56' auxiliary destination '/oracle/auxiliary';
  44. #表空间名称未大写
  45. Starting recover at 2016-07-26 04:55:19
  46. using target database control file instead of recovery catalog
  47. allocated channel: ORA_DISK_1
  48. channel ORA_DISK_1: SID=26 device type=DISK
  49. RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-time
  50. List of tablespaces expected to have UNDO segments
  51. Tablespace SYSTEM
  52. Tablespace UNDOTBS1
  53. Creating automatic instance, with SID='cmmh'
  54. initialization parameters used for automatic instance:
  55. db_name=MHXY
  56. db_unique_name=cmmh_tspitr_MHXY
  57. compatible=11.2.0.0.0
  58. db_block_size=8192
  59. db_files=200
  60. sga_target=280M
  61. processes=50
  62. db_create_file_dest=/oracle/auxiliary
  63. log_archive_dest_1='location=/oracle/auxiliary'
  64. #No auxiliary parameter file used
  65. starting up automatic instance MHXY
  66. Oracle instance started
  67. Total System Global Area 292278272 bytes
  68. Fixed Size 2212736 bytes
  69. Variable Size 100666496 bytes
  70. Database Buffers 184549376 bytes
  71. Redo Buffers 4849664 bytes
  72. Automatic instance created
  73. List of tablespaces that have been dropped from the target database:
  74. Tablespace test
  75. contents of Memory Script:
  76. {
  77. # set requested point in time
  78. set until time "2016-07-26 04:48:56";
  79. # restore the controlfile
  80. restore clone controlfile;
  81. # mount the controlfile
  82. sql clone 'alter database mount clone database';
  83. # archive current online log
  84. sql 'alter system archive log current';
  85. # avoid unnecessary autobackups for structural changes during TSPITR
  86. sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
  87. }
  88. executing Memory Script
  89. executing command: SET until clause
  90. Starting restore at 2016-07-26 04:55:29
  91. allocated channel: ORA_AUX_DISK_1
  92. channel ORA_AUX_DISK_1: SID=59 device type=DISK
  93. channel ORA_AUX_DISK_1: starting datafile backup set restore
  94. channel ORA_AUX_DISK_1: restoring control file
  95. channel ORA_AUX_DISK_1: reading from backup piece /oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_ncsnf_TAG20160726T044513_csdyoz8x_.bkp
  96. channel ORA_AUX_DISK_1: piece handle=/oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_ncsnf_TAG20160726T044513_csdyoz8x_.bkp tag=TAG20160726T044513
  97. channel ORA_AUX_DISK_1: restored backup piece 1
  98. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
  99. output file name=/oracle/auxiliary/MHXY/controlfile/o1_mf_csdz6245_.ctl
  100. Finished restore at 2016-07-26 04:55:31
  101. sql statement: alter database mount clone database
  102. sql statement: alter system archive log current
  103. sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
  104. Removing automatic instance
  105. shutting down automatic instance
  106. database dismounted
  107. Oracle instance shut down
  108. Automatic instance removed
  109. auxiliary instance file /oracle/auxiliary/MHXY/controlfile/o1_mf_csdz6245_.ctl deleted
  110. RMAN-00571: ===========================================================
  111. RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
  112. RMAN-00571: ===========================================================
  113. RMAN-03002: failure of recover command at 07/26/2016 04:55:41
  114. RMAN-06136: ORACLE error from auxiliary database: RMAN-20202: Tablespace not found in the recovery catalog
  115. RMAN-06019: could not translate tablespace name "test"

  116. #正确的命令
  117. RMAN> recover tablespace "TEST" until time '2016-07-26 04:48:56' auxiliary destination '/oracle/auxiliary';
  118. Starting recover at 2016-07-26 04:57:30
  119. using channel ORA_DISK_1
  120. RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-time
  121. List of tablespaces expected to have UNDO segments
  122. Tablespace SYSTEM
  123. Tablespace UNDOTBS1
  124. Creating automatic instance, with SID='nAif'
  125. initialization parameters used for automatic instance:
  126. db_name=MHXY
  127. db_unique_name=nAif_tspitr_MHXY
  128. compatible=11.2.0.0.0
  129. db_block_size=8192
  130. db_files=200
  131. sga_target=280M
  132. processes=50
  133. db_create_file_dest=/oracle/auxiliary
  134. log_archive_dest_1='location=/oracle/auxiliary'
  135. #No auxiliary parameter file used
  136. starting up automatic instance MHXY
  137. Oracle instance started
  138. Total System Global Area 292278272 bytes
  139. Fixed Size 2212736 bytes
  140. Variable Size 100666496 bytes
  141. Database Buffers 184549376 bytes
  142. Redo Buffers 4849664 bytes
  143. Automatic instance created
  144. List of tablespaces that have been dropped from the target database:
  145. Tablespace TEST
  146. contents of Memory Script:
  147. {
  148. # set requested point in time
  149. set until time "2016-07-26 04:48:56";
  150. # restore the controlfile
  151. restore clone controlfile;
  152. # mount the controlfile
  153. sql clone 'alter database mount clone database';
  154. # archive current online log
  155. sql 'alter system archive log current';
  156. # avoid unnecessary autobackups for structural changes during TSPITR
  157. sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
  158. }
  159. executing Memory Script
  160. executing command: SET until clause
  161. Starting restore at 2016-07-26 04:57:40
  162. allocated channel: ORA_AUX_DISK_1
  163. channel ORA_AUX_DISK_1: SID=59 device type=DISK
  164. channel ORA_AUX_DISK_1: starting datafile backup set restore
  165. channel ORA_AUX_DISK_1: restoring control file
  166. channel ORA_AUX_DISK_1: reading from backup piece /oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_ncsnf_TAG20160726T044513_csdyoz8x_.bkp
  167. channel ORA_AUX_DISK_1: piece handle=/oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_ncsnf_TAG20160726T044513_csdyoz8x_.bkp tag=TAG20160726T044513
  168. channel ORA_AUX_DISK_1: restored backup piece 1
  169. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
  170. output file name=/oracle/auxiliary/MHXY/controlfile/o1_mf_csdzb4pk_.ctl
  171. Finished restore at 2016-07-26 04:57:41
  172. sql statement: alter database mount clone database
  173. sql statement: alter system archive log current
  174. sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
  175. contents of Memory Script:
  176. {
  177. # set requested point in time
  178. set until time "2016-07-26 04:48:56";
  179. # set destinations for recovery set and auxiliary set datafiles
  180. set newname for clone datafile 1 to new;
  181. set newname for clone datafile 3 to new;
  182. set newname for clone datafile 2 to new;
  183. set newname for clone tempfile 1 to new;
  184. set newname for datafile 5 to
  185. "/oracle/database/oradata/mhxy/test.dbf";
  186. # switch all tempfiles
  187. switch clone tempfile all;
  188. # restore the tablespaces in the recovery set and the auxiliary set
  189. restore clone datafile 1, 3, 2, 5;
  190. switch clone datafile all;
  191. }
  192. executing Memory Script
  193. executing command: SET until clause
  194. executing command: SET NEWNAME
  195. executing command: SET NEWNAME
  196. executing command: SET NEWNAME
  197. executing command: SET NEWNAME
  198. executing command: SET NEWNAME
  199. renamed tempfile 1 to /oracle/auxiliary/MHXY/datafile/o1_mf_temp_%u_.tmp in control file
  200. Starting restore at 2016-07-26 04:57:46
  201. using channel ORA_AUX_DISK_1
  202. channel ORA_AUX_DISK_1: starting datafile backup set restore
  203. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
  204. channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/auxiliary/MHXY/datafile/o1_mf_system_%u_.dbf
  205. channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/auxiliary/MHXY/datafile/o1_mf_undotbs1_%u_.dbf
  206. channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/auxiliary/MHXY/datafile/o1_mf_sysaux_%u_.dbf
  207. channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/database/oradata/mhxy/test.dbf
  208. channel ORA_AUX_DISK_1: reading from backup piece /oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_nnndf_TAG20160726T044513_csdyltqt_.bkp
  209. channel ORA_AUX_DISK_1: piece handle=/oracle/database/flash_recovery_area/MHXY/backupset/2016_07_26/o1_mf_nnndf_TAG20160726T044513_csdyltqt_.bkp tag=TAG20160726T044513
  210. channel ORA_AUX_DISK_1: restored backup piece 1
  211. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
  212. Finished restore at 2016-07-26 04:58:52
  213. datafile 1 switched to datafile copy
  214. input datafile copy RECID=4 STAMP=918190732 file name=/oracle/auxiliary/MHXY/datafile/o1_mf_system_csdzbc66_.dbf
  215. datafile 3 switched to datafile copy
  216. input datafile copy RECID=5 STAMP=918190732 file name=/oracle/auxiliary/MHXY/datafile/o1_mf_undotbs1_csdzbc7g_.dbf
  217. datafile 2 switched to datafile copy
  218. input datafile copy RECID=6 STAMP=918190732 file name=/oracle/auxiliary/MHXY/datafile/o1_mf_sysaux_csdzbc79_.dbf
  219. contents of Memory Script:
  220. {
  221. # set requested point in time
  222. set until time "2016-07-26 04:48:56";
  223. # online the datafiles restored or switched
  224. sql clone "alter database datafile 1 online";
  225. sql clone "alter database datafile 3 online";
  226. sql clone "alter database datafile 2 online";
  227. sql clone "alter database datafile 5 online";
  228. # recover and open resetlogs
  229. recover clone database tablespace "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
  230. alter clone database open resetlogs;
  231. }
  232. executing Memory Script
  233. executing command: SET until clause
  234. sql statement: alter database datafile 1 online
  235. sql statement: alter database datafile 3 online
  236. sql statement: alter database datafile 2 online
  237. sql statement: alter database datafile 5 online
  238. Starting recover at 2016-07-26 04:58:52
  239. using channel ORA_AUX_DISK_1
  240. starting media recovery
  241. archived log for thread 1 with sequence 7 is already on disk as file /oracle/database/flash_recovery_area/MHXY/archivelog/2016_07_26/o1_mf_1_7_csdyp0pw_.arc
  242. archived log for thread 1 with sequence 8 is already on disk as file /oracle/database/flash_recovery_area/MHXY/archivelog/2016_07_26/o1_mf_1_8_csdz67oz_.arc
  243. archived log file name=/oracle/database/flash_recovery_area/MHXY/archivelog/2016_07_26/o1_mf_1_7_csdyp0pw_.arc thread=1 sequence=7
  244. archived log file name=/oracle/database/flash_recovery_area/MHXY/archivelog/2016_07_26/o1_mf_1_8_csdz67oz_.arc thread=1 sequence=8
  245. media recovery complete, elapsed time: 00:00:02
  246. Finished recover at 2016-07-26 04:58:55
  247. database opened
  248. contents of Memory Script:
  249. {
  250. # make read only the tablespace that will be exported
  251. sql clone 'alter tablespace "TEST" read only';
  252. # create directory for datapump import
  253. sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
  254. /oracle/auxiliary''";
  255. # create directory for datapump export
  256. sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
  257. /oracle/auxiliary''";
  258. }
  259. executing Memory Script
  260. sql statement: alter tablespace "TEST" read only
  261. sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/auxiliary''
  262. sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/auxiliary''
  263. Performing export of metadata...
  264. EXPDP> Starting "SYS"."TSPITR_EXP_nAif":
  265. EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
  266. EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
  267. EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
  268. EXPDP> Master table "SYS"."TSPITR_EXP_nAif" successfully loaded/unloaded
  269. EXPDP> ******************************************************************************
  270. EXPDP> Dump file set for SYS.TSPITR_EXP_nAif is:
  271. EXPDP> /oracle/auxiliary/tspitr_nAif_78214.dmp
  272. EXPDP> ******************************************************************************
  273. EXPDP> Datafiles required for transportable tablespace TEST:
  274. EXPDP> /oracle/database/oradata/mhxy/test.dbf
  275. EXPDP> Job "SYS"."TSPITR_EXP_nAif" successfully completed at 05:00:20
  276. Export completed
  277. contents of Memory Script:
  278. {
  279. # shutdown clone before import
  280. shutdown clone immediate
  281. }
  282. executing Memory Script
  283. database closed
  284. database dismounted
  285. Oracle instance shut down
  286. Performing import of metadata...
  287. IMPDP> Master table "SYS"."TSPITR_IMP_nAif" successfully loaded/unloaded
  288. IMPDP> Starting "SYS"."TSPITR_IMP_nAif":
  289. IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
  290. IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
  291. IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
  292. IMPDP> Job "SYS"."TSPITR_IMP_nAif" successfully completed at 05:00:57
  293. Import completed
  294. contents of Memory Script:
  295. {
  296. # make read write and offline the imported tablespaces
  297. sql 'alter tablespace "TEST" read write';
  298. sql 'alter tablespace "TEST" offline';
  299. # enable autobackups after TSPITR is finished
  300. sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
  301. }
  302. executing Memory Script
  303. sql statement: alter tablespace "TEST" read write
  304. sql statement: alter tablespace "TEST" offline
  305. sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
  306. Removing automatic instance
  307. Automatic instance removed
  308. auxiliary instance file /oracle/auxiliary/MHXY/datafile/o1_mf_temp_csdzds8s_.tmp deleted
  309. auxiliary instance file /oracle/auxiliary/MHXY/onlinelog/o1_mf_3_csdzdnmk_.log deleted
  310. auxiliary instance file /oracle/auxiliary/MHXY/onlinelog/o1_mf_2_csdzdlfx_.log deleted
  311. auxiliary instance file /oracle/auxiliary/MHXY/onlinelog/o1_mf_1_csdzdhj7_.log deleted
  312. auxiliary instance file /oracle/auxiliary/MHXY/datafile/o1_mf_sysaux_csdzbc79_.dbf deleted
  313. auxiliary instance file /oracle/auxiliary/MHXY/datafile/o1_mf_undotbs1_csdzbc7g_.dbf deleted
  314. auxiliary instance file /oracle/auxiliary/MHXY/datafile/o1_mf_system_csdzbc66_.dbf deleted
  315. auxiliary instance file /oracle/auxiliary/MHXY/controlfile/o1_mf_csdzb4pk_.ctl deleted
  316. Finished recover at 2016-07-26 05:01:00
  317. RMAN>
四、在sqlplus中验证,发现通过TSPITR恢复的表空间状态是offline,需要alter 到online

点击(此处)折叠或打开

  1. SQL> col name for a60
  2. SQL> select name from v$datafile;
  3. NAME
  4. ------------------------------------------------------------
  5. /oracle/database/oradata/mhxy/system01.dbf
  6. /oracle/database/oradata/mhxy/sysaux01.dbf
  7. /oracle/database/oradata/mhxy/undotbs01.dbf
  8. /oracle/database/oradata/mhxy/users01.dbf
  9. /oracle/database/oradata/mhxy/test.dbf
  10. SQL> select tablespace_name,status from dba_tablespaces;
  11. TABLESPACE_NAME                                              STATUS
    ------------------------------------------------------------ ------------------
    SYSTEM                                                       ONLINE
    SYSAUX                                                       ONLINE
    UNDOTBS1                                                     ONLINE
    TEMP                                                         ONLINE
    USERS                                                        ONLINE
    TEST                                                         OFFLINE


  12. 6 rows selected.
  13. SQL> alter tablespace test online;
  14. Tablespace altered.
  15. SQL> select count(*) from test.t1;
  16. COUNT(*)
  17. ----------
  18. 71904
五、思考,在实际生产环境中需要坚持是否自包含对象,如下就会有自包含现象,需要删除索引等表空间TEST恢复后重新创建

点击(此处)折叠或打开

  1. SQL> create index idx1 on test.t1(owner) tablespace users;
  2. Index created.
  3. SQL> select * from SYS.TS_PITR_CHECK a WHERE a.ts1_name='TEST';
  4. OBJ1_OWNER    OBJ1_NAME   OBJ1_SUBNAME    OBJ1_TYPE    TS1_NAME   OBJ2_NAME  OBJ2_SUBNAME    OBJ2_TYPE    OBJ2_OWNER  TS2_NAME    CONSTRAINT_NAME  REASON
    ----------  -----------   -------------   ----------   ---------  ---------  ------------    ----------  -----------  ----------  ---------------  ----------
    TEST           T1                         BLE           TEST         IDX1         INDEX                    SYS           USERS                      Tables and associated indexes not fully
                                                                                                                                                        contained in the recovery set                                                           
     

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24222399/viewspace-2156516/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2014-03-31

  • 博文量
    26
  • 访问量
    34328