• Oracle-表空间基于时间点恢复(TSPITR)


    前言:

    Oracle在10G推出了tablespace point-in-time recovery(TSPITR)基于表空间的时间点恢复,可以快速的在目标库上根据备份恢复一个或多个表空间到指定的时间点,恢复期间不影响其他表空间的使用以及对象,可以快速的恢复误删数据。

    TSPITR工作原理:

    1. The figure contains the following entities:
    2. • The target instance, containing the tablespace to be recovered
    3. • The Recovery Manager client
    4. • The control file and (optional) recovery catalog, used for the RMAN repository records of backup activity
    5. • Archived redo logs and backup sets from the target database, which are the source of the reconstructed tablespace.
    6. • The auxiliary instance, an Oracle database instance used in the recovery process to perform the actual work of recovery.
    7. There are four other important terms related to TSPITR, which will be used in the rest of this discussion:
    8. • The target time, the point in time or SCN that the tablespace will be left at after TSPITR
    9. • The recovery set, which consists of the datafiles containing the tablespaces to be recovered;
    10. • The auxiliary set, which includes datafiles required for TSPITR of the recovery set which are not themselves part of the recovery set. The auxiliary set typically includes:
    11. ○ A copy of the SYSTEM tablespace
    12. ○ Datafiles containing rollback or undo segments from the target instance
    13. In some cases, a temporary tablespace, used during the export of database objects from the auxiliary instance
    14. The auxiliary instance has other files associated with it, such as a control file, parameter file, and online logs, but they are not part of the auxiliary set.
    15. • The auxiliary destination, an optional location on disk which can be used to store any of the auxiliary set datafiles, control files and online logs of the auxiliary instance during TSPITR. Files stored here can be deleted after TSPITR is complete.
    16. All of these terms will be referenced throughout the remainder of this chapter.
    17. How TSPITR Works With an RMAN-Managed Auxiliary Instance
    18. To perform TSPITR of the recovery set using RMAN and an automated auxiliary instance, you carry out the preparations for TSPITR described in "Planning and Preparing for TSPITR", and then issue the RECOVER TABLESPACE command, specifying, at a minimum, the tablespaces of the recovery set and the target time for the point-in-time recovery, and, if desired, an auxiliary destination as well.
    19. RMAN then carries out the following steps:
    20. If there is no connection to an auxiliary instance, RMAN creates the auxiliary instance, starts it up and connects to it.
    21. Takes the tablespaces to be recovered offline in the target database
    22. Restores a backup control file from a point in time before the target time to the auxiliary instance
    23. Restores the datafiles from the recovery set and the auxiliary set to the auxiliary instance. Files are restored either in locations you specify for each file, or the original location of the file (for recovery set files) or in the auxiliary destination (for auxiliary set files, if you used the AUXILIARY DESTINATION argument of RECOVER TABLESPACE)
    24. Recovers the restored datafiles in the auxiliary instance to the specified time
    25. Opens the auxiliary database with the RESETLOGS option
    26. Exports the dictionary metadata about objects in the recovered tablespaces to the target database
    27. Shuts down the auxiliary instance
    28. Issues SWITCH commands on the target instance, so that the target database control file now points to the datafiles in the recovery set that were just recovered at the auxiliary instance.
    29. Imports the dictionary metadata from the auxiliary instance to the target instance, allowing the recovered objects to be accessed.
    30. Deletes all auxiliary set files.
    31. At that point the TSPITR process is complete. The recovery set datafiles are returned to their contents at the specified point in time, and belong to the target database.

    1 通过创建一个辅助的实例

    2 将需要point in time recovery(PITR)的目标数据库表空间recover offline

    3 从备份里面依据PITR点恢复控制文件到辅助实例

    4 从备份里面依据PITR点恢复system,undo表空间到 AUXILIARY DESTINATION 路径下,恢复PITR目标表空间到原始路径下

    5 open resetlogs打开辅助实例

    6 从恢复的表空间里面导出元数据

    7 关闭辅助实例

    8目标库执行切换命令,目标库的控制文件指向,以便目标数据库控制文件现在指向刚刚在辅助实例上恢复的恢复集中的数据文件。

    9 导入元数据到目标实例。

    10 删除所有辅助实例设置文件

    ​TSPITR使用限制:

    1. • Recovery Manager Tablespace Point-in-Time Recovery (TSPITR) enables you to recover one or more tablespaces to a point in time that is different from that of the rest of the database.But there are a number of situations which you cannot resolve by using TSPITR.
    2. They are as follows.
    3. • You cannot recover dropped tablespaces.
    4. • You cannot recover a renamed tablespace to a point in time before it was renamed. If you try to perform a TSPITR to an SCN earlier than the rename operation, RMAN cannot find the new tablespace name in the repository as of that earlier SCN (because the tablespace did not have that name at that SCN). In this situation, you must recover the entire database to a point in time before the tablespace was renamed. The tablespace will be found under the name it had at that earlier time.
    5. • Recover a tablespace that has been dropped and re-created with the same name.
    6. • You cannot recover tables without their associated constraints, or constraints without the associated table
    7. • You cannot use TSPITR to recover any of the following:
    8. 1. Replicated primary tables
    9. 2. Partial tables (for example, if you perform RMAN TSPITR on partitioned tables and spread partitions across multiple tablespaces, then you must recover all tablespaces which include partitions of the table.)
    10. 3. Tables with VARRAY columns, nested tables, or external files
    11. 4. Snapshot logs and snapshot tables
    12. 5. Tablespaces containing undo or rollback segments
    13. 6. Tablespaces that contain objects owned by SYS, including rollback segments
    14. If a datafile was added after the point to which RMAN is recovering, an empty datafile by the same name will be included in the tablespace after RMAN TSPITR.
    15. • TSPITR will not recover query optimizer statistics for recovered objects. You must gather new statistics after the TSPITR.
    16. • Assume that you run TSPITR on a tablespace, and then bring the tablespace online at time t. Backups of the tablespace created before time t are no longer usable for recovery with a current control file. You cannot run TSPITR again on this tablespace to recover it to any time less than or equal to time t, nor can you use the current control file to recover the database to any time less than or equal to t. Therefore, you must back up the tablespace as soon as TSPITR is complete.
    17. Limitations of TSPITR Without a Recovery Catalog
    18. ====================================
    19. • The undo segments at the time of the TSPITR must be part of the auxiliary set. Because RMAN has no historical record of the undo in the control file, RMAN assumes that the current rollback or undo segments were the same segments present at the time to which recovery is performed. If the undo segments have changed since that time, then TSPITR will fail.
    20. • TSPITR to a time that is too old may not succeed if Oracle has reused the control file records for needed backups. (In planning your database, set the CONTROL_FILE_RECORD_KEEP_TIME initialization parameter to a value large enough to ensure that control file records needed for TSPITR are kept.)
    21. When not using a recovery catalog, the current control file has no record of the older incarnation of the recovered tablespace. Thus, recovery with a current control file that involves this tablespace can no longer use a backup taken prior to time t. You can, however, perform incomplete recovery of the whole database to any time less than or equal to t, if you can restore a backup control file from before time t.

    TSPITR使用测试

    模拟误删除场景

    1. ---在PDB ebsdb里面创建测试数据
    2. alter session set container=ebsdb;
    3. alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
    4. create tablespace tbstest datafile size 100M;
    5. create table test(id number,insert_date date) tablespace tbstest;
    6. insert into test values(1,sysdate);
    7. commit;
    8. ---进行全量备份
    9. run{
    10. allocate channel c1 type disk;
    11. allocate channel c2 type disk;
    12. allocate channel c3 type disk;
    13. backup as compressed backupset database format='/backup/%d_full_%s_%p.bak';
    14. backup archivelog all format='/backup/%d_arch_%s_%p.bak' delete all input;
    15. release channel c1;
    16. release channel c2;
    17. release channel c3;
    18. }
    19. ---再插入数据
    20. insert into test values(2,sysdate);
    21. commit;
    22. ---模拟误删除数据truncate
    23. alter session set container=ebsdb;
    24. alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
    25. select sysdate from dual;
    26. select * from test;
    27. ##########要恢复的时间点
    28. SQL> select sysdate from dual;
    29. SYSDATE
    30. -------------------
    31. 2022-11-09 02:10:29
    32. SQL> select * from test;
    33. ID INSERT_DATE
    34. ---------- -------------------
    35. 1 2022-11-09 02:08:03
    36. 2 2022-11-09 02:10:22
    37. SQL>
    38. ---truncate表数据
    39. truncate table test;
    40. ---在备份归档
    41. run{
    42. allocate channel c1 type disk;
    43. allocate channel c2 type disk;
    44. allocate channel c3 type disk;
    45. backup archivelog all format='/backup/%d_arch_%s_%p.bak' delete all input;
    46. release channel c1;
    47. release channel c2;
    48. release channel c3;
    49. }

    开始通过TSPITR基于表空间的时间点恢复

    由于恢复是直接在目标数据库的表空间上恢复,所以恢复的是表空间里面全部数据到指定的时间点,这种恢复在实际的生产环境中是不太可能的,因为我们往往只需要恢复某一张表,而不是将整个表空间里面的数据恢复到某个时间点

    所以将恢复的目标数据库放在备库是比较合理的,接下来的恢复操作,我们也是模拟在误删数据库的备库进行操作

    1. ---关闭主库的mrp进程
    2. alter database recover managed standby database cancel;
    3. ---failover激活备库,因为恢复需要在open write模式下进行,并且控制文件的类型不能为standby control,不能创建检查点
    4. #RMAN-05010: target database must be opened in READ WRITE mode for Tablespace Point-in-Time Recovery
    5. ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
    6. ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
    7. alter database open;
    8. alter pluggable database all open instances=all;
    9. ---将备份发生到备库主机
    10. scp -rp /backup oracle@xxxxx:/
    11. ---并注册备份到控制文件,确保数据库可以访问到备份文件
    12. rman target /
    13. crosscheck backup
    14. catalog start with '/backup'
    15. ---在备库执行TSPITR恢复命令,恢复EBSDB PDB里面的表空间tbstest
    16. ---AUXILIARY DESTINATION
    17. rman target /
    18. RECOVER TABLESPACE ebsdb:tbstest until time "to_date('11/09/2022 02:10:29','MM/DD/YYYY HH24:MI:SS')" AUXILIARY DESTINATION '/u01/app/oracle/auxinstance';

    TSPITR恢复日志分析

    1. ####################创建辅助实例
    2. Creating automatic instance, with SID='Csgj'
    3. initialization parameters used for automatic instance:
    4. db_name=RACPDB
    5. db_unique_name=Csgj_pitr_ebsdb_RACPDB
    6. compatible=19.0.0
    7. db_block_size=8192
    8. db_files=200
    9. diagnostic_dest=/u01/app/oracle
    10. _system_trig_enabled=FALSE
    11. sga_target=2320M
    12. processes=200
    13. db_create_file_dest=/u01/app/oracle/auxinstance
    14. log_archive_dest_1='location=/u01/app/oracle/auxinstance'
    15. enable_pluggable_database=true
    16. _clone_one_pdb_recovery=true
    17. #No auxiliary parameter file used
    18. starting up automatic instance RACPDB
    19. Oracle instance started
    20. Total System Global Area 2432695632 bytes
    21. Fixed Size 9137488 bytes
    22. Variable Size 536870912 bytes
    23. Database Buffers 1879048192 bytes
    24. Redo Buffers 7639040 bytes
    25. Automatic instance created
    26. Running TRANSPORT_SET_CHECK on recovery set tablespaces
    27. TRANSPORT_SET_CHECK completed successfully
    28. ####################从备份恢复控制文件
    29. contents of Memory Script:
    30. {
    31. # set requested point in time
    32. set until time "to_date('11/09/2022 02:10:29','MM/DD/YYYY HH24:MI:SS')";
    33. # restore the controlfile
    34. restore clone controlfile;
    35. # mount the controlfile
    36. sql clone 'alter database mount clone database';
    37. # archive current online log
    38. sql 'alter system archive log current';
    39. # avoid unnecessary autobackups for structural changes during TSPITR
    40. sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
    41. }
    42. executing Memory Script
    43. ####################指定时间点restore,system,sysaux,undo到指定的auxiliray路径下,恢复的PITR表空间会到原路径下
    44. contents of Memory Script:
    45. {
    46. # set requested point in time
    47. set until time "to_date('11/09/2022 02:10:29','MM/DD/YYYY HH24:MI:SS')";
    48. plsql <<<--
    49. declare
    50. sqlstatement varchar2(512);
    51. pdbname varchar2(128);
    52. offline_not_needed exception;
    53. pragma exception_init(offline_not_needed, -01539);
    54. begin
    55. pdbname := 'EBSDB'; -- pdbname
    56. sqlstatement := 'alter tablespace '|| 'TBSTEST' ||' offline immediate';
    57. krmicd.writeMsg(6162, sqlstatement);
    58. krmicd.execSql(sqlstatement, 0, pdbname);
    59. exception
    60. when offline_not_needed then
    61. null;
    62. end; >>>;
    63. # set destinations for recovery set and auxiliary set datafiles
    64. set newname for clone datafile 1 to new;
    65. set newname for clone datafile 16 to new;
    66. set newname for clone datafile 5 to new;
    67. set newname for clone datafile 18 to new;
    68. set newname for clone datafile 19 to new;
    69. set newname for clone datafile 3 to new;
    70. set newname for clone datafile 17 to new;
    71. set newname for clone tempfile 1 to new;
    72. set newname for clone tempfile 5 to new;
    73. set newname for datafile 63 to
    74. "/u01/app/oracle/oradata/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_tbstest_kpzcnwbw_.dbf";
    75. # switch all tempfiles
    76. switch clone tempfile all;
    77. # restore the tablespaces in the recovery set and the auxiliary set
    78. restore clone datafile 1, 16, 5, 18, 19, 3, 17, 63;
    79. switch clone datafile all;
    80. }
    81. executing Memory Script
    82. executing command: SET until clause
    83. sql statement: alter tablespace TBSTEST offline immediate
    84. executing command: SET NEWNAME
    85. executing command: SET NEWNAME
    86. executing command: SET NEWNAME
    87. executing command: SET NEWNAME
    88. executing command: SET NEWNAME
    89. executing command: SET NEWNAME
    90. executing command: SET NEWNAME
    91. executing command: SET NEWNAME
    92. executing command: SET NEWNAME
    93. executing command: SET NEWNAME
    94. renamed tempfile 1 to /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_temp_%u_.tmp in control file
    95. renamed tempfile 5 to /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_temp_%u_.tmp in control file
    96. Starting restore at 2022/11/12 22:41:31
    97. using channel ORA_AUX_DISK_1
    98. channel ORA_AUX_DISK_1: starting datafile backup set restore
    99. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
    100. channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_system_%u_.dbf
    101. channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_sysaux_%u_.dbf
    102. channel ORA_AUX_DISK_1: reading from backup piece /backup/backup/RACPDB_full_250_1.bak
    103. channel ORA_AUX_DISK_1: piece handle=/backup/backup/RACPDB_full_250_1.bak tag=TAG20221109T020837
    104. channel ORA_AUX_DISK_1: restored backup piece 1
    105. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
    106. channel ORA_AUX_DISK_1: starting datafile backup set restore
    107. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
    108. channel ORA_AUX_DISK_1: restoring datafile 00016 to /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_system_%u_.dbf
    109. channel ORA_AUX_DISK_1: reading from backup piece /backup/backup/RACPDB_full_252_1.bak
    110. channel ORA_AUX_DISK_1: piece handle=/backup/backup/RACPDB_full_252_1.bak tag=TAG20221109T020837
    111. channel ORA_AUX_DISK_1: restored backup piece 1
    112. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
    113. channel ORA_AUX_DISK_1: starting datafile backup set restore
    114. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
    115. channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_undotbs1_%u_.dbf
    116. channel ORA_AUX_DISK_1: reading from backup piece /backup/backup/RACPDB_full_254_1.bak
    117. channel ORA_AUX_DISK_1: piece handle=/backup/backup/RACPDB_full_254_1.bak tag=TAG20221109T020837
    118. channel ORA_AUX_DISK_1: restored backup piece 1
    119. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
    120. channel ORA_AUX_DISK_1: starting datafile backup set restore
    121. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
    122. channel ORA_AUX_DISK_1: restoring datafile 00018 to /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_undotbs1_%u_.dbf
    123. channel ORA_AUX_DISK_1: reading from backup piece /backup/backup/RACPDB_full_253_1.bak
    124. channel ORA_AUX_DISK_1: piece handle=/backup/backup/RACPDB_full_253_1.bak tag=TAG20221109T020837
    125. channel ORA_AUX_DISK_1: restored backup piece 1
    126. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
    127. channel ORA_AUX_DISK_1: starting datafile backup set restore
    128. channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
    129. channel ORA_AUX_DISK_1: restoring datafile 00019 to /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_undo_2_%u_.dbf
    130. channel ORA_AUX_DISK_1: restoring datafile 00017 to /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_sysaux_%u_.dbf
    131. channel ORA_AUX_DISK_1: restoring datafile 00063 to /u01/app/oracle/oradata/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_tbstest_kpzcnwbw_.dbf
    132. channel ORA_AUX_DISK_1: reading from backup piece /backup/backup/RACPDB_full_251_1.bak
    133. channel ORA_AUX_DISK_1: piece handle=/backup/backup/RACPDB_full_251_1.bak tag=TAG20221109T020837
    134. channel ORA_AUX_DISK_1: restored backup piece 1
    135. channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
    136. Finished restore at 2022/11/12 22:42:55
    137. datafile 63 switched to datafile copy
    138. input datafile copy RECID=9 STAMP=1120603375 file name=/u01/app/oracle/oradata/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_tbstest_kpzcnwbw_.dbf
    139. datafile 1 switched to datafile copy
    140. input datafile copy RECID=10 STAMP=1120603375 file name=/u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_system_kpzd4w3c_.dbf
    141. datafile 16 switched to datafile copy
    142. input datafile copy RECID=11 STAMP=1120603375 file name=/u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_system_kpzd5o4k_.dbf
    143. datafile 5 switched to datafile copy
    144. input datafile copy RECID=12 STAMP=1120603375 file name=/u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_undotbs1_kpzd6g5l_.dbf
    145. datafile 18 switched to datafile copy
    146. input datafile copy RECID=13 STAMP=1120603375 file name=/u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_undotbs1_kpzd6k6l_.dbf
    147. datafile 19 switched to datafile copy
    148. input datafile copy RECID=14 STAMP=1120603375 file name=/u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_undo_2_kpzd707w_.dbf
    149. datafile 3 switched to datafile copy
    150. input datafile copy RECID=15 STAMP=1120603375 file name=/u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_sysaux_kpzd4w3r_.dbf
    151. datafile 17 switched to datafile copy
    152. input datafile copy RECID=16 STAMP=1120603375 file name=/u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_sysaux_kpzd707v_.dbf
    153. contents of Memory Script:
    154. {
    155. # set requested point in time
    156. set until time "to_date('11/09/2022 02:10:29','MM/DD/YYYY HH24:MI:SS')";
    157. # online the datafiles restored or switched
    158. sql clone "alter database datafile 1 online";
    159. sql clone 'EBSDB' "alter database datafile
    160. 16 online";
    161. sql clone "alter database datafile 5 online";
    162. sql clone 'EBSDB' "alter database datafile
    163. 18 online";
    164. sql clone 'EBSDB' "alter database datafile
    165. 19 online";
    166. sql clone "alter database datafile 3 online";
    167. sql clone 'EBSDB' "alter database datafile
    168. 17 online";
    169. sql clone 'EBSDB' "alter database datafile
    170. 63 online";
    171. # recover and open resetlogs
    172. recover clone database tablespace "EBSDB":"TBSTEST", "SYSTEM", "EBSDB":"SYSTEM", "UNDOTBS1", "EBSDB":"UNDOTBS1", "EBSDB":"UNDO_2", "SYSAUX", "EBSDB":"SYSAUX" delete archivelog;
    173. alter clone database open resetlogs;
    174. }
    175. executing Memory Script
    176. executing command: SET until clause
    177. sql statement: alter database datafile 1 online
    178. sql statement: alter database datafile 16 online
    179. sql statement: alter database datafile 5 online
    180. sql statement: alter database datafile 18 online
    181. sql statement: alter database datafile 19 online
    182. sql statement: alter database datafile 3 online
    183. sql statement: alter database datafile 17 online
    184. sql statement: alter database datafile 63 online
    185. Starting recover at 2022/11/12 22:42:55
    186. using channel ORA_AUX_DISK_1
    187. starting media recovery
    188. archived log for thread 1 with sequence 87 is already on disk as file /u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch1_87_1120132767.dbf
    189. archived log for thread 1 with sequence 88 is already on disk as file /u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch1_88_1120132767.dbf
    190. archived log file name=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch1_87_1120132767.dbf thread=1 sequence=87
    191. archived log file name=/u01/app/oracle/product/19.0.0/dbhome_1/dbs/arch1_88_1120132767.dbf thread=1 sequence=88
    192. media recovery complete, elapsed time: 00:00:01
    193. Finished recover at 2022/11/12 22:42:57
    194. database opened
    195. contents of Memory Script:
    196. {
    197. sql clone 'alter pluggable database EBSDB open';
    198. }
    199. executing Memory Script
    200. sql statement: alter pluggable database EBSDB open
    201. contents of Memory Script:
    202. {
    203. # make read only the tablespace that will be exported
    204. sql clone 'EBSDB' 'alter tablespace
    205. TBSTEST read only';
    206. # create directory for datapump import
    207. sql 'EBSDB' "create or replace directory
    208. TSPITR_DIROBJ_DPDIR as ''
    209. /u01/app/oracle/auxinstance''";
    210. # create directory for datapump export
    211. sql clone 'EBSDB' "create or replace directory
    212. TSPITR_DIROBJ_DPDIR as ''
    213. /u01/app/oracle/auxinstance''";
    214. }
    215. executing Memory Script
    216. sql statement: alter tablespace TBSTEST read only
    217. sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/app/oracle/auxinstance''
    218. sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/app/oracle/auxinstance''
    219. ###############################################从辅助实例导出元数据
    220. Performing export of metadata...
    221. EXPDP> Starting "SYS"."TSPITR_EXP_Csgj_jizC":
    222. EXPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
    223. EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
    224. EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
    225. EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
    226. EXPDP> Master table "SYS"."TSPITR_EXP_Csgj_jizC" successfully loaded/unloaded
    227. EXPDP> ******************************************************************************
    228. EXPDP> Dump file set for SYS.TSPITR_EXP_Csgj_jizC is:
    229. EXPDP> /u01/app/oracle/auxinstance/tspitr_Csgj_71324.dmp
    230. EXPDP> ******************************************************************************
    231. EXPDP> Datafiles required for transportable tablespace TBSTEST:
    232. EXPDP> /u01/app/oracle/oradata/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_tbstest_kpzcnwbw_.dbf
    233. EXPDP> Job "SYS"."TSPITR_EXP_Csgj_jizC" successfully completed at Sat Nov 12 22:43:41 2022 elapsed 0 00:00:28
    234. Export completed
    235. contents of Memory Script:
    236. {
    237. # shutdown clone before import
    238. shutdown clone abort
    239. # drop target tablespaces before importing them back
    240. sql 'EBSDB' 'drop tablespace
    241. TBSTEST including contents keep datafiles cascade constraints';
    242. }
    243. executing Memory Script
    244. Oracle instance shut down
    245. ###############################################目标数据库删除原来的表空间
    246. sql statement: drop tablespace TBSTEST including contents keep datafiles cascade constraints
    247. ###############################################目标数据库导入元数据
    248. Performing import of metadata...
    249. IMPDP> Master table "SYS"."TSPITR_IMP_Csgj_uqxb" successfully loaded/unloaded
    250. IMPDP> Starting "SYS"."TSPITR_IMP_Csgj_uqxb":
    251. IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
    252. IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
    253. IMPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
    254. IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
    255. IMPDP> Job "SYS"."TSPITR_IMP_Csgj_uqxb" successfully completed at Sat Nov 12 22:43:53 2022 elapsed 0 00:00:03
    256. Import completed
    257. ###############################################目标数据库offline恢复表空间
    258. contents of Memory Script:
    259. {
    260. # make read write and offline the imported tablespaces
    261. sql 'EBSDB' 'alter tablespace
    262. TBSTEST read write';
    263. sql 'EBSDB' 'alter tablespace
    264. TBSTEST offline';
    265. # enable autobackups after TSPITR is finished
    266. sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
    267. }
    268. executing Memory Script
    269. sql statement: alter tablespace TBSTEST read write
    270. sql statement: alter tablespace TBSTEST offline
    271. sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
    272. ###############################################清理辅助实例
    273. Removing automatic instance
    274. Automatic instance removed
    275. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_temp_kpzd7pxy_.tmp deleted
    276. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_temp_kpzd7nvx_.tmp deleted
    277. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/onlinelog/o1_mf_3_kpzd7kpw_.log deleted
    278. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/onlinelog/o1_mf_2_kpzd7knq_.log deleted
    279. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/onlinelog/o1_mf_1_kpzd7kmd_.log deleted
    280. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_sysaux_kpzd707v_.dbf deleted
    281. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_sysaux_kpzd4w3r_.dbf deleted
    282. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_undo_2_kpzd707w_.dbf deleted
    283. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_undotbs1_kpzd6k6l_.dbf deleted
    284. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_undotbs1_kpzd6g5l_.dbf deleted
    285. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/ECDB7CD71FEB9A44E053DC01A8C0E647/datafile/o1_mf_system_kpzd5o4k_.dbf deleted
    286. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/datafile/o1_mf_system_kpzd4w3c_.dbf deleted
    287. auxiliary instance file /u01/app/oracle/auxinstance/RACPDG/controlfile/o1_mf_kpzd4p8l_.ctl deleted
    288. auxiliary instance file tspitr_Csgj_71324.dmp deleted
    289. Finished recover at 2022/11/12 22:43:55
    290. RMAN>

    TSPITR恢复完成之后验证数据

    1. ---online表空间tbstest,验证数据
    2. SQL> alter tablespace tbstest online;
    3. Tablespace altered.
    4. ​---误删除的数据恢复到之前的时间点
    5. SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
    6. Session altered.
    7. SQL> select * from test;
    8. ID INSERT_DATE
    9. ---------- -------------------
    10. 1 2022-11-09 02:08:03
    11. 2 2022-11-09 02:10:22

  • 相关阅读:
    JavaWeb学习(4)注解案例:简单的测试框架
    软考高项-合同管理
    241.为运算表达式设计优先级(分治算法)
    【安卓开发】安卓工程介绍及启动过程
    Vue:组件缓存
    全新代购商城源码,迅速实现财富梦想!
    ORA-01547、ORA-01194、ORA-01110
    Go语言map底层分析
    求最大公约数的几种常见的方法 【详解】
    C++——cv::Rect数据结构详解
  • 原文地址:https://blog.csdn.net/sinat_36757755/article/details/127827092