0
点赞
收藏
分享

微信扫一扫

基于时间点的不完全恢复—表空间恢复&表恢复

菜头粿子园 2022-09-27 阅读 153

实验课题:基于时间点的不完全恢复.
1、PITR概念
PITR Terminology
• Target time: The point in time or SCN that an object will be recovered to
• Recovery set: For tablespaces, the data files to be recovered
• Auxiliary set: Required data files that are not part of the recovery set. It typically includes:
– SYSTEM tablespace
– Undo segment tablespaces
– Temporary tablespace
• Auxiliary destination: Disk location to store files

Performing Point-in-Time Recovery
Perform database point-in-time (incomplete) recovery by doing the following:
1. Determine the target point of the restore: SCN, time, restore point, or log sequence number.
2. Set the NLS environment variables appropriately.
3. Mount the database.
4. Prepare and execute a RUN block, using the SET UNTIL, RESTORE, and RECOVER commands.
5. Open the database in READ ONLY mode and verify that the recovery point is correct.
6. Open the database by using RESETLOGS.

注意:恢复时间点要确认清楚.
2、DBPITR
基于时间点的数据库恢复.
RMAN> backup database plus archivelog;
说明:该语句备份数据文件、归档文件、控制文件、参数文件.
$ sqlplus / as sysdba
SQL> create table test (id number);
SQL> insert into test values(1);
SQL> commit;
SQL> select owner,OBJECT_NAME,TO_CHAR(CREATED,'yyyy-mm-dd hh24:mi:ss') from dba_objects where object_type='TABLE' order by 3;
SQL> select systimestamp from dual; (说明:确认表删除前具体时间)

SYSTIMESTAMP
---------------------------------------------------------------------------
25-MAR-22 03.13.10.459278 PM +08:00
SQL> drop table test;
$ export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
$ export NLS_LANG=american_america.utf8
$ sqlplus / as sysdba
SQL> shutdown immediate
SQL> startup mount
$ rman target /
RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
1 165.05M DISK 00:00:01 2022-03-25 14:58:25
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20220325T145824
Piece Name: +DATA/ORCLCDB/BACKUPSET/2022_03_25/annnf0_tag20220325t145824_0.282.1100271505

List of Archived Logs in backup set 1
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 25 4031583 2022-03-22 12:28:28 4096125 2022-03-25 14:58:22

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
2 Full 1.57G DISK 00:00:45 2022-03-25 14:59:11
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20220325T145825
Piece Name: +DATA/ORCLCDB/BACKUPSET/2022_03_25/nnndf0_tag20220325t145825_0.280.1100271507
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- ------------------- ----------- ------ ----
1 Full 4096147 2022-03-25 14:58:26 NO +DATA/ORCLCDB/DATAFILE/system.257.1082993319
3 Full 4096147 2022-03-25 14:58:26 NO +DATA/ORCLCDB/DATAFILE/sysaux.258.1082993363
4 Full 4096147 2022-03-25 14:58:26 NO +DATA/ORCLCDB/DATAFILE/undotbs1.259.1082993389
7 Full 4096147 2022-03-25 14:58:26 NO +DATA/ORCLCDB/DATAFILE/users.260.1082993391

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
3 Full 723.06M DISK 00:00:33 2022-03-25 14:59:54
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20220325T145825
Piece Name: +DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/BACKUPSET/2022_03_25/nnndf0_tag20220325t145825_0.283.1100271561
List of Datafiles in backup set 3
Container ID: 3, PDB Name: ORCLPDB
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- ------------------- ----------- ------ ----
9 Full 4096174 2022-03-25 14:59:21 NO +DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/system.276.1082994661
10 Full 4096174 2022-03-25 14:59:21 NO +DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/sysaux.277.1082994661
11 Full 4096174 2022-03-25 14:59:21 NO +DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/undotbs1.275.1082994661
12 Full 4096174 2022-03-25 14:59:21 NO +DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/users.279.1082994667

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
4 Full 828.22M DISK 00:00:34 2022-03-25 15:00:30
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20220325T145825
Piece Name: +DATA/ORCLCDB/CBB453E60EF1A77FE0537885A8C04607/BACKUPSET/2022_03_25/nnndf0_tag20220325t145825_0.285.1100271597
List of Datafiles in backup set 4
Container ID: 2, PDB Name: PDB$SEED
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- ------------------- ----------- ------ ----
5 Full 2551609 2021-09-11 15:50:24 NO +DATA/ORCLCDB/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.270.1082993933
6 Full 2551609 2021-09-11 15:50:24 NO +DATA/ORCLCDB/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.271.1082993933
8 Full 2551609 2021-09-11 15:50:24 NO +DATA/ORCLCDB/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.272.1082993933

BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
5 42.00K DISK 00:00:00 2022-03-25 15:00:31
BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20220325T150031
Piece Name: +DATA/ORCLCDB/BACKUPSET/2022_03_25/annnf0_tag20220325t150031_0.284.1100271631

List of Archived Logs in backup set 5
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 26 4096125 2022-03-25 14:58:22 4096291 2022-03-25 15:00:31

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
6 Full 17.95M DISK 00:00:01 2022-03-25 15:00:33
BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20220325T150032
Piece Name: +DATA/ORCLCDB/AUTOBACKUP/2022_03_25/s_1100271632.287.1100271633
SPFILE Included: Modification time: 2022-03-25 14:54:32
SPFILE db_unique_name: ORCLCDB
Control File Included: Ckp SCN: 4096308 Ckp time: 2022-03-25 15:00:32
RMAN> run{
set until time '2022-03-25 15:13:10';
restore database;
recover database;
}
RMAN> alter database open resetlogs;
$ sqlplus / as sysdba
SQL> select count(*) from test;

COUNT(*)
----------
0
总结:以上为DBPITR,将整个数据库恢复到过去某时间点.
3、TSPITR
基于时间点的表空间恢复.
3.1、基本概念
When to Use TSPITR
TSPITR can be used in the following situations:
• To recover data lost after an erroneous TRUNCATE TABLE statement
• To recover from logical corruption of a table
• To undo the effects of a batch job or DML statements that have affected only a part of the database
• To recover a logical schema to a different point from the rest of the physical database
• To recover a dropped tablespace
• Can be performed repeatedly to points-in-time before the tablespace was brought online without requiring a recovery catalog

Preparing for TSPITR
To prepare for TSPITR, perform the following steps:
• Determine the correct target time.
• Determine what is needed in the recovery set.
• Identify and preserve objects that will be lost after PITR.

Determining the Correct Target Time
• After you perform TSPITR and bring the tablespace online, you cannot use a backup from an earlier time (unless you are using a recovery catalog).
• Use the following methods to determine the correct target time:
– Flashback Query
– Flashback Transaction Query
– Flashback Version Query
• Simple alternative to TSPITR: Flashback data (if still available as undo)

Determining the Tablespaces for the Recovery Set
• If objects in the tablespace that you are recovering have relationships with objects in other tablespaces, you can:
– Add the tablespace that contains the related objects to the recovery set
– Suspend the relationship for the duration of TSPITR
– Remove the relationship
• Use the DBMS_TTS.TRANSPORT_SET_CHECK procedure to determine whether the tablespaces in the recovery set are self-contained.

DBMS_TTS.TRANSPORT_SET_CHECK ('USERS,EXAMPLE');
SELECT * FROM TRANSPORT_SET_VIOLATIONS;
3.2、操作过程
3.2.1、SYS用户
创建两个存在依赖关系的表空间.
SQL> show user
USER is "SYS"
SQL> create tablespace tsp_item datafile '/home/oracle/tsp_item01.dbf' size 10m;
SQL> create tablespace tsp_idx datafile '/home/oracle/tsp_idx01.dbf' size 10m;
SQL> create table emp (empid number,last_name varchar2(20)) tablespace tsp_item;
SQL> create index idx_emp_last_name on emp(last_name) tablespace tsp_idx;

说明:此处表和索引放在不同表空间.
SQL> exec dbms_tts.transport_set_check('TSP_ITEM'); (说明:过程dbms_tts.transport_set_check判断表空间是否存在依赖)
SQL> desc transport_set_violations;
Name Null? Type
----------------------- -------- ----------------
VIOLATIONS VARCHAR2(2000)
这里查询不出,主要是用的sys操作的.
SQL> select segment_name,segment_type,tablespace_name from user_segments;

SQL> insert into emp values(100,'abc');
SQL> commit;
SQL> drop table emp;
SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB MOUNTED
3.2.2、普通用户
3.2.2.1、模拟依赖表空间
SQL> create user c##liujun identified by liujun;
SQL> alter user c##liujun default tablespace tsp_item;
SQL> grant connect,resource,unlimited tablespace to c##liujun;
SQL> conn c##liujun/liujun
SQL> create table emp(empid number,last_name varchar2(20)) tablespace tsp_item;
SQL> create index idx_emp_last_name on emp(last_name) tablespace tsp_idx; (说明:表与索引放在不同的表空间)
SQL> begin
for i in 1..100 loop
insert into emp values(i,'test' || i);
end loop;
end;
/
SQL> select segment_name,segment_type,tablespace_name from user_segments;

SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME
-------------------- -------------------- ---------------
EMP TABLE TSP_ITEM
IDX_EMP_LAST_NAME INDEX TSP_IDX
SQL> conn / as sysdba
SQL> exec dbms_tts.transport_set_check('TSP_ITEM');
SQL> select * from transport_set_violations;

no rows selected

SQL> conn c##liujun/liujun
SQL> create table dept (deptid number,deptname varchar2(20)) tablespace tsp_idx;
SQL> alter table dept add constraint pk_dept_id primary key (deptid);
SQL> alter table emp add (deptid number references dept); (说明:表dept在表空间tsp_idx,表emp在表空间tsp_item.)
SQL> desc emp;
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
EMPID NUMBER
LAST_NAME VARCHAR2(20)
DEPTID NUMBER
SQL> insert into dept values(10,'sales');
SQL> insert into dept values(20,'make');
SQL> commit;
SQL> select segment_name,segment_type,tablespace_name from user_segments;

SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME
-------------------- -------------------- ---------------
DEPT TABLE TSP_IDX
EMP TABLE TSP_ITEM
IDX_EMP_LAST_NAME INDEX TSP_IDX
PK_DEPT_ID INDEX TSP_ITEM
说明:主键的创建,会自动生成同名索引,虽然该索引在表dept上,但并不跟表dept在同一个表空间,而是用户##liujun的默认表空间TSP_ITEM.
SQL> conn / as sysdba
SQL> exec dbms_tts.transport_set_check('TSP_ITEM'); 说明:使用dbms_tts.transport_set_check过程判断恢复集中的表空间是否为自包含.
SQL> select * from transport_set_violations;

VIOLATIONS
----------------------------------------------------------------------------------------------------
ORA-39908: Index C##LIUJUN.PK_DEPT_ID in tablespace TSP_ITEM enforces primary constraints of table
C##LIUJUN.DEPT in tablespace TSP_IDX.

SQL> exec dbms_tts.transport_set_check('TSP_ITEM,TSP_IDX');
SQL> select * from transport_set_violations;

no rows selected

Identifying Objects That Will Be Lost
• Objects created in the tablespace after the target recovery time are lost.
• Query TS_PITR_OBJECTS_TO_BE_DROPPED to determine which objects will be lost after TSPITR.
• Use Export before TSPITR and Import after TSPTIR to preserve and re-create the lost objects

Performing RMAN TSPITR
• Fully automated TSPITR:
– Specify an auxiliary destination.
– RMAN manages all aspects of TSPITR.
– This is the recommended method.
• Customized TSPITR with an automatic auxiliary instance:
– This is based on fully automated TSPITR.
– Customize the location of files.
– Specify initialization parameters.
– Specify channel configurations.
• TSPITR using your own auxiliary instance:
– Configure and manage the auxiliary instance


Performing Fully Automated TSPITR
1. Configure channels required for TSPITR on the target instance.
2. Specify the auxiliary destination by using the AUXILIARY DESTINATION option.
RMAN> CONNECT TARGET
RMAN> RECOVER TABLESPACE users, example
> UNTIL TIME '2018-06-29:08:00:00'
> AUXILIARY DESTINATION
> '/u01/app/oracle/oradata/aux';
3. Back up the recovered tablespaces and bring them online.
3.2.2.2、恢复
SQL> conn c##liujun/liujun
SQL> select systimestamp from dual;

SYSTIMESTAMP
---------------------------------------------------------------------------
25-MAR-22 04.45.02.494629 PM +08:00
SQL> select * from dept;
DEPTID DEPTNAME
---------- ------------------------------------------------------------
10 sales
20 make
SQL> select count(*) from emp;

COUNT(*)
----------
100
SQL> drop table emp purge;
SQL> drop table dept purge; (说明:此处需要将两张表都drop,破坏彻底依赖关系,只drop emp,而dept truncat,到时恢复报错ora-02429、ora-00604)
SQL> exit
[oracle@dbserver ~]$ rman target /
RMAN> recover tablespace tsp_item,tsp_idx
2> until time '2022-03-25 16:45:02'
3> auxiliary destination '/home/oracle';

Starting recover at 2022-03-25 16:59:09
using target database control file instead of recovery catalog
……
Finished recover at 2022-03-25 17:01:00

3.2.2.3、恢复验证
SQL> conn c##liujun/liujun
SQL> select table_name from tabs;

TABLE_NAME
--------------------------------------------------------------------------------
EMP
DEPT
SQL> conn / as sysdba
SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME STATUS
------------------------------ --------------------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
TSP_ITEM OFFLINE
TSP_IDX OFFLINE

7 rows selected.
SQL> alter tablespace tsp_item online;
SQL> alter tablespace tsp_idx online;
SQL> conn c##liujun/liujun
SQL> desc dept
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPTID NOT NULL NUMBER
DEPTNAME VARCHAR2(20)

SQL> desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NUMBER
LAST_NAME VARCHAR2(20)
DEPTID NUMBER
结论:两个表空间成功恢复,过程中emp、dept两张表的依赖关系要破坏彻底才能成功恢复.
4、PDB PITR
4.1、核心语法
RMAN> ALTER PLUGGABLE DATABASE pdb1 CLOSE;
RMAN> RUN {
SET UNTIL SCN = 1851648 ;
RESTORE pluggable DATABASE pdb1;
RECOVER pluggable DATABASE pdb1
AUXILIARY DESTINATION='/u01/app/oracle/oradata';
ALTER PLUGGABLE DATABASE pdb1 OPEN RESETLOGS;
}
4.2、实际操作
SQL> alter pluggable database all open;
SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
[oracle@dbserver ~]$ rman target /
RMAN> delete backup;
RMAN> backup database plus archivelog;
SQL> alter session set container=orclpdb;
SQL> select username,account_status from dba_users;
SQL> show user;
USER is "SYS"
SQL> create user liujun identified by liujun;
SQL> grant connect,resource,unlimited tablespace to liujun;
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/system.276.1082994661
+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/sysaux.277.1082994661
+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/undotbs1.275.1082994661
+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/users.279.1082994667
SQL> create tablespace tsp_test datafile '+DATA/ORCLCDB/CBB47E352F7AAEA7E0537885A8C03007/DATAFILE/tsp_test01.dbf' size 10m;
SQL> alter user liujun default tablespace tsp_test;
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
4115348
SQL> conn liujun/liujun@192.168.133.120:1521/orclpdb
SQL> create table bigtab tablespace tsp_test as select * from all_tables;
SQL> select table_name,tablespace_name from tabs;

TABLE_NAME TABLESPACE_NAME
-------------------- --------------------
BIGTAB TSP_TEST
创建连接串
ORCLPDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbserver)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orclpdb)
)
)
SQL> conn liujun/liujun@orclpdb
[oracle@dbserver admin]$ rman target sys/oracle_4U@orclpdb

Recovery Manager: Release 19.0.0.0.0 - Production on Fri Mar 25 17:49:49 2022
Version 19.12.0.0.0

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

connected to target database: ORCLCDB:ORCLPDB (DBID=3616071563)
RMAN> alter pluggable database orclpdb close;
RMAN> run{
2> set until scn=4115348;
3> restore pluggable database orclpdb;
4> recover pluggable database orclpdb
5> auxiliary destination='/home/oracle';
6> alter pluggable database orclpdb open resetlogs;
7> }

executing command: SET until clause

Starting restore at 2022-03-25 18:03:00
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 03/25/2022 18:03:00
RMAN-20020: database incarnation not set

RMAN> exit
[oracle@dbserver admin]$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Fri Mar 25 18:05:45 2022
Version 19.12.0.0.0

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

connected to target database: ORCLCDB (DBID=2854054806)

RMAN> run{
2> set until scn=4115348;
3> restore pluggable database orclpdb;
4> recover pluggable database orclpdb
5> auxiliary destination='/home/oracle';
6> alter pluggable database orclpdb open resetlogs;
7> }

executing command: SET until clause
……
Finished recover at 2022-03-25 18:06:18

注意:恢复需连到CDB.

5、PDB TSPITR
恢复pdb某表空间到过去某时间点.
5.1、核心语法
RMAN> RECOVER TABLESPACE pdb1:test_tbs
UNTIL SCN 832972
AUXILIARY DESTINATION '/tmp/CDB1/reco';
RMAN> ALTER TABLESPACE pdb1:test_tbs ONLINE;
5.2、实际操作
SQL> conn sys/oracle_4U@orclpdb as sysdba
SQL> select name from v$tablespace;

NAME
--------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
TSP_TEST

6 rows selected.
SQL> exit
[oracle@dbserver ~]$ rman target /
RMAN> delete backup;
RMAN> delete copy;
RMAN> backup database plus archivelog;
[oracle@dbserver ~]$ sqlplus / as sysdba
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
4124030
SQL> show pdbs;

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
SQL> alter session set container=orclpdb;
SQL> conn liujun/liujun@orclpdb
SQL> select table_name from tabs;

no rows selected
SQL> create table emp(empid number) tablespace tsp_test;
SQL> begin
2 for i in 1..100 loop
3 insert into emp values(i);
4 end loop;
5 end;
6 /
SQL> commit;
SQL> exit
[oracle@dbserver ~]$ rman target sys/oracle_4U@orclpdb

Recovery Manager: Release 19.0.0.0.0 - Production on Fri Mar 25 21:10:20 2022
Version 19.12.0.0.0

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

connected to target database: ORCLCDB:ORCLPDB (DBID=3616071563)

RMAN> recover tablespace tsp_test
2> until scn 4124030
3> auxiliary destination '/tmp';

Starting recover at 25-MAR-22
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 03/25/2022 21:12:51
RMAN-06457: UNTIL SCN (4124030) is ahead of last SCN in archived logs (4122738)

RMAN> exit
[oracle@dbserver ~]$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Fri Mar 25 21:13:01 2022
Version 19.12.0.0.0

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

connected to target database: ORCLCDB (DBID=2854054806)

RMAN> recover tablespace orclpdb:tsp_test
2> until scn 4124030
3> auxiliary destination '/tmp';

Starting recover at 25-MAR-22
using target database control file instead of recovery catalog
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=406 device type=DISK
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time

……
Finished recover at 25-MAR-22

注意:恢复需连到CDB
SQL> select tablespace_name,status from dba_tablespaces;

TABLESPACE_NAME STATUS
-------------------- --------------------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
TSP_TEST OFFLINE

6 rows selected.
SQL> alter tablespace tsp_test online;
SQL> conn liujun/liujun@orclpdb
SQL> select * from emp;
select * from emp
*
ERROR at line 1:
ORA-00942: table or view does not exist
结论:恢复到emp表不存在的时间点.
6、PDB TPITR
6.1、基本概念
oracle 19c 能实现恢复单表到某时间点.
Recovering Tables from Backups
When to recover tables and table partitions from RMAN backups:
• Small number of tables (no TSPITR)
• Not in a self-contained tablespace (no TSPITR)
• Purged tables (no Flashback drop)
• Beyond the available undo (no Flashback Table)
• After a structural DDL change (no Flashback Table)

Prerequisites and Limitations
To recover tables and table partitions from RMAN backups, the target database must be:
• In read/write mode
• In ARCHIVELOG mode
Limitations of recovery: No tables and table partitions from:
• The SYS schema
• The SYSTEM and SYSAUX tablespaces
• Standby databases

Specifying the Recovery Point in Time
Recover table and table partitions to the state they were in by specifying:
• UNTIL SCN integer: The system change number (SCN)
• UNTIL TIME 'date_string’: The time in the date format:
– Of the NLS_LANG and NLS_DATE_FORMAT environment variables, or
– Date constants, for example, SYSDATE - 5
• UNTIL SEQUENCE integer (THREAD integer): The log sequence number and thread number

Process Steps of Table Recovery
1. Perform the planning tasks and start an RMAN session with the CONNECT TARGET command.
2. Enter the RECOVER TABLE command.
3. RMAN determines the backup based on your specification.
4. RMAN creates an auxiliary instance by using the AUXILIARY DESTINATION clause, if specified.
5. RMAN recovers your tables or table partitions, up to the specified point in time, into this auxiliary instance.
6. RMAN creates a Data Pump export dump file that contains the recovered objects with the DUMP FILE=name and DATAPUMP DESTINATION=<OS path>.
7. RMAN imports the recovered objects into the target database unless you specified NOTABLEIMPORT.
8. RMAN optionally renames the recovered tables or table partitions with the REMAP TABLE and the REMAP TABLESPACE clauses. (Existing objects are not changed.)
Note: If you remap a table, the dependent objects are excluded from the import. You must re-create indexes and constraints.

6.2、操作过程
RMAN> delete backup;
RMAN> delete copy;
RMAN> backup database plus archivelog;
SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE
SQL> conn liujun/liujun@orclpdb;
SQL> select table_name from tabs;

no rows selected
SQL> create table emp (empid number);
SQL> insert into emp values (100);
SQL> commit;
SQL> conn / as sysdba
SQL> select current_scn from v$database;

CURRENT_SCN
-----------
11565805
SQL> conn liujun/liujun@orclpdb;
SQL> insert into emp values (200);
SQL> commit;
SQL> select count(*) from emp;

COUNT(*)
----------
2
现在需要恢复到SCN为11565805的时间点,到时记录只有一条.
[oracle@dbserver ~]$ rman target /
RMAN> recover table liujun.emp of pluggable database orclpdb
2> until scn 11565805
3> auxiliary destination '/tmp'
4> remap table liujun.emp:liujun.emp1;
Starting recover at 27-AUG-22
using channel ORA_DISK_1
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time
……
auxiliary instance file /tmp/ORCLCDB/controlfile/o1_mf_kjn4g7mh_.ctl deleted
auxiliary instance file tspitr_uDFm_51862.dmp deleted
Finished recover at 27-AUG-22

SQL> conn liujun/liujun@orclpdb;
SQL> select * from emp1;

EMPID
----------
100
结论:以上案例便是基于时间点的单表恢复.
参考网址:https://blog.51cto.com/lhrbest/2703025

举报

相关推荐

0 条评论