之前的文档:Oracle 异机恢复 - 仅仅恢复业务表空间_rman-06067: recover database required with a backu-CSDN博客
参考文档:
How to Recover From a DROP / TRUNCATE / DELETE TABLE with RMAN (Doc ID 223543.1)
d. Restore of the necessary tablespaces, RESTORE TABLESPACE:
https://docs.oracle.com/en/database/oracle/oracle-database/19/rcmrf/RECOVER.html
Example 3-3 Performing DBPITR with a Backup Control File and Recovery Catalog
本测试,只恢复部分表空间,system、sysaux、undotbs、业务TBS。
和之前的测试,不同的地方,之前的测试,restore所需的表空间,在recover之前,使用重建控制文件的方式,将控制文件中不需要的表空间文件排除掉。
现在的测试方式,restore所需的表空间,在recover之前,不需要重建控制文件,在recover的时候,使用recover database skip forever tablespace XXX ,排除掉不需要recover的database,然后开库。
测试过程
1 restore ctl
2 restore 必须的表空间,指定了until time
3 不需要重新创建控制文件,在recover的时候脚本中排除掉不需要recover的表空间 ,指定until time进行recover
4 禁用触发器,加TEMP表空间
5 expdp
-- 模拟drop 用户
SYS@test SQL> select sysdate from dual;
SYSDATE
-------------------
2025-12-04 13:16:56
SYS@test SQL> select count(*) from "U251203"."T_251203" ;
COUNT(*)
----------
74525
SYS@test SQL> drop user u251203 cascade;
User dropped.
SYS@test SQL> select count(*) from "U251203"."T_251203" ;
select count(*) from "U251203"."T_251203"
*
ERROR at line 1:
ORA-00942: table or view does not exist
SYS@test SQL>
-- 恢复控制文件
[oracle@19ctest ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Thu Dec 4 13:19:06 2025
Version 19.29.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: TEST (not mounted)
RMAN> restore controlfile from '/arch/test/TEST/autobackup/2025_12_03/o1_mf_s_1218896567_nlzosq8g_.bkp';
restore controlfile from '/arch/test/TEST/autobackup/2025_12_03/o1_mf_s_1218896567_nlzosq8g_.bkp';
Starting restore at 04-DEC-25
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oradata/test/control01.ctl
output file name=/oradata/test/control02.ctl
Finished restore at 04-DEC-25
RMAN>
-- restore
run{
set until time "to_date('2025-12-04 13:16:56','yyyy-mm-dd hh24:mi:ss')";
restore tablespace system,sysaux,undotbs1,tbs_251203 ;
}
RMAN> run{
run{
2> set until time "to_date('2025-12-04 13:16:56','yyyy-mm-dd hh24:mi:ss')";
set until time "to_date('2025-12-04 13:16:56','yyyy-mm-dd hh24:mi:ss')";
3> restore tablespace system,sysaux,undotbs1,tbs_251203 ;
restore tablespace system,sysaux,undotbs1,tbs_251203 ;
4> }
}
executing command: SET until clause
Starting restore at 2025-12-04 13:22:43
Starting implicit crosscheck backup at 2025-12-04 13:22:43
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 device type=DISK
Crosschecked 37 objects
Finished implicit crosscheck backup at 2025-12-04 13:22:44
Starting implicit crosscheck copy at 2025-12-04 13:22:44
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2025-12-04 13:22:44
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /arch/test/TEST/autobackup/2025_12_03/o1_mf_s_1218896567_nlzosq8g_.bkp
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 00001 to /oradata/test/data_D-TEST_TS-SYSTEM_FNO-1
channel ORA_DISK_1: restoring datafile 00004 to /oradata/test/data_D-TEST_TS-UNDOTBS1_FNO-4
channel ORA_DISK_1: reading from backup piece /arch/backup/test/TEST_full_138_1218896013.bak
channel ORA_DISK_1: piece handle=/arch/backup/test/TEST_full_138_1218896013.bak tag=TAG20251203T141333
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:11:25
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 /oradata/test/data_D-TEST_TS-SYSAUX_FNO-3
channel ORA_DISK_1: reading from backup piece /arch/backup/test/TEST_full_139_1218896478.bak
channel ORA_DISK_1: piece handle=/arch/backup/test/TEST_full_139_1218896478.bak tag=TAG20251203T141333
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
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 00016 to /oradata/test/tbs251203.dbf
channel ORA_DISK_1: reading from backup piece /arch/backup/test/TEST_full_140_1218896525.bak
channel ORA_DISK_1: piece handle=/arch/backup/test/TEST_full_140_1218896525.bak tag=TAG20251203T141333
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 2025-12-04 13:34:57
RMAN>
-- report schema,查看所有表空间
RMAN> report schema;
report schema;
RMAN-06139: warning: control file is not current for REPORT SCHEMA
Report of database schema for database with db_unique_name TEST
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 13089 SYSTEM *** /oradata/test/data_D-TEST_TS-SYSTEM_FNO-1
2 0 TBS_HMW *** /oradata/test/data_D-TEST_TS-TBS_HMW_FNO-2
3 1760 SYSAUX *** /oradata/test/data_D-TEST_TS-SYSAUX_FNO-3
4 4044 UNDOTBS1 *** /oradata/test/data_D-TEST_TS-UNDOTBS1_FNO-4
5 0 LOB_TBS *** /oradata/test/data_D-TEST_TS-LOB_TBS_FNO-5
7 0 USERS *** /oradata/test/data_D-TEST_TS-USERS_FNO-7
8 0 TEST_NEEDBACKUP *** /oradata/test/data_D-TEST_TS-TEST_NEEDBACKUP_FNO-8
9 0 TBS_BIG *** /oradata/test/data_D-TEST_TS-TBS_BIG_FNO-9
10 0 TBS_SMALL *** /oradata/test/data_D-TEST_TS-TBS_SMALL_FNO-10
11 0 GGS_TBS *** /oradata/test/data_D-TEST_TS-GGS_TBS_FNO-11
12 0 SOE *** /oradata/test/data_D-TEST_TS-SOE_FNO-12
13 0 TBS_TIBERO *** /oradata/test/TBS_TIBERO01.dbf
14 0 FY_REC_DATA *** /tmp/FY_REC_DATA.DAT
15 20 FY_RST_DATA *** /tmp/FY_RST_DATA.DAT
16 100 TBS_251203 *** /oradata/test/tbs251203.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 20 TEMP 32767 /oradata/test/temp01.dbf
RMAN>
-- recover ,skip掉无关的表空间
run
{
set until time "to_date('2025-12-04 13:16:56','yyyy-mm-dd hh24:mi:ss')";
recover database skip forever tablespace TBS_HMW,LOB_TBS,USERS,TEST_NEEDBACKUP,TBS_BIG,TBS_SMALL,GGS_TBS,SOE,TBS_TIBERO,FY_REC_DATA,FY_RST_DATA;
}
RMAN> run
run
2> {
{
3> set until time "to_date('2025-12-04 13:16:56','yyyy-mm-dd hh24:mi:ss')";
set until time "to_date('2025-12-04 13:16:56','yyyy-mm-dd hh24:mi:ss')";
4> recover database skip forever tablespace TBS_HMW,LOB_TBS,USERS,TEST_NEEDBACKUP,TBS_BIG,TBS_SMALL,GGS_TBS,SOE,TBS_TIBERO,FY_REC_DATA,FY_RST_DATA;
recover database skip forever tablespace TBS_HMW,LOB_TBS,USERS,TEST_NEEDBACKUP,TBS_BIG,TBS_SMALL,GGS_TBS,SOE,TBS_TIBERO,FY_REC_DATA,FY_RST_DATA;
5> }
}
executing command: SET until clause
Starting recover at 2025-12-04 13:40:58
using channel ORA_DISK_1
Executing: alter database datafile 2, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15 offline drop
starting media recovery
archived log for thread 1 with sequence 95 is already on disk as file /arch/test/1_95_1150771961.dbf
archived log file name=/arch/test/1_95_1150771961.dbf thread=1 sequence=95
unable to find archived log
archived log thread=1 sequence=96
RMAN Command Id : 2025-12-04T13:21:19
RMAN Command Id : 2025-12-04T13:21:19
RMAN Command Id : 2025-12-04T13:21:19
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/04/2025 13:40:59
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 96 and starting SCN of 48529328
RMAN Client Diagnostic Trace file : /u01/app/oracle/diag/clients/user_oracle/RMAN_3615665928_110/trace/ora_rman_3498_2.trc
RMAN Server Diagnostic Trace file : /u01/app/oracle/diag/rdbms/test/test/trace/test_ora_3519.trc
RMAN>
-- 直接打开库
SYS@test SQL> conn / as sysdba
Connected.
Session altered.
SYS@test SQL> !date
Thu Dec 4 13:41:53 CST 2025
SYS@test SQL> alter database open resetlogs;
Database altered.
SYS@test SQL> !date
Thu Dec 4 13:42:14 CST 2025
SYS@test SQL>
--
13:58:19 SYS@test SQL> select tablespace_name,online_status from dba_data_files where online_status in('SYSTEM','ONLINE');
TABLESPACE_NAME ONLINE_
------------------------------ -------
SYSTEM SYSTEM
SYSAUX ONLINE
UNDOTBS1 ONLINE
TBS_251203 ONLINE
13:58:21 SYS@test SQL>
13:58:21 SYS@test SQL> select tablespace_name,online_status from dba_data_files where online_status not in('SYSTEM','ONLINE');
TABLESPACE_NAME ONLINE_
------------------------------ -------
LOB_TBS OFFLINE
USERS OFFLINE
TBS_HMW OFFLINE
TEST_NEEDBACKUP OFFLINE
TBS_BIG OFFLINE
TBS_SMALL OFFLINE
GGS_TBS OFFLINE
SOE OFFLINE
TBS_TIBERO OFFLINE
FY_REC_DATA OFFLINE
FY_RST_DATA OFFLINE
11 rows selected.
13:59:03 SYS@test SQL>
-- 禁掉触发器,expdp ,实际上,从上面的report schema看, temp表空间已经有了(之前重建控制文件的方式,temp表空间没有的,需要处理下temp表空间)
SYS@test SQL> alter trigger SYS.GGS_DDL_TRIGGER_BEFORE disable;
Trigger altered.
SYS@test SQL> alter tablespace TEMP add tempfile '/oradata/test/temp01.dbf' size 100M autoextend on;
alter tablespace TEMP add tempfile '/oradata/test/temp01.dbf' size 100M autoextend on
*
ERROR at line 1:
ORA-01537: cannot add file '/oradata/test/temp01.dbf' - file already part of
database
SYS@test SQL> !
[oracle@19ctest ~]$ expdp \'/ as sysdba\' directory=DUMP dumpfile=dmp20251203.dmp schemas=u251203
Export: Release 19.0.0.0.0 - Production on Thu Dec 4 13:43:45 2025
Version 19.29.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
FLASHBACK automatically enabled to preserve database integrity.
Starting "SYS"."SYS_EXPORT_SCHEMA_01": "/******** AS SYSDBA" directory=DUMP dumpfile=dmp20251203.dmp schemas=u251203
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
. . exported "U251203"."T_251203" 9.464 MB 74525 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
/u01/dump/dmp20251203.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Dec 4 13:44:06 2025 elapsed 0 00:00:20
[oracle@19ctest ~]$
END