实验表空间时间点恢复(TSPITR)

--实验表空间时间点恢复(TSPITR)


--10g,11g,12c cdb中操作相同
--12c pdb需要在recover子句中指定pdb名


在什么情况下适用:
  • 错误执行TRUNCATE TABLE;
  • 错误执行DROP TABLE;
  • 撤销只影响部分数据库的DML语句结果;
在什么情况下不适用:
  • 表空间被删除;
  • 表空间被重命名;
  • system,undo,sysaux不适用;
  • 系统默认表空间也不适用,需要alter database default tablespace xxx;

**注意事项:
TSPITR需要对整个数据库进行不完全恢复,时间会非常长,可以使用skip tablespace<>跳过不需要恢复的表空间;
或者在12c中执行表时间点恢复技术,recover table。

--实验:执行全自动执行的TSPITR
--步骤:
1.确认备份,需要的归档数据存在。
2.在RMAN中使用辅助路径选项指定辅助目标。


--实验1.在12cpdb中实验TSPITR

SQL> select banner from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
PL/SQL Release 12.1.0.2.0 - Production
CORE	12.1.0.2.0	Production
TNS for Linux: Version 12.1.0.2.0 - Production
NLSRTL Version 12.1.0.2.0 - Production

SQL> alter session set container=pdbwyzc
  2  ;

Session altered.

SQL> select tablespace_name from dba_tables where table_name='EMP';
select tablespace_name from dba_tables where table_name='EMP'
                            *
ERROR at line 1:
ORA-01219: database or pluggable database not open: queries allowed on fixed
tables or views only


SQL> alter database open;

Database altered.

SQL> select tablespace_name from dba_tables where table_name='EMP';

TABLESPACE_NAME
------------------------------
USERS

SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,'YY
-------------------
2017-01-13 19:28:50

SQL> drop table scott.emp purge;

Table dropped.


[oracle@luo ~]$ rlwrap rman target /

Recovery Manager: Release 12.1.0.2.0 - Production on Fri Jan 13 19:40:00 2017

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

connected to target database: WYZC (DBID=3417564758)

RMAN> recover tablespace PDBWYZC:USERS
2> until time "to_date('2017-01-13 19:28:50','yyyy-mm-dd hh24:mi:ss')"
3> auxiliary destination '/tmp/';

Starting recover at 13-JAN-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=51 device type=DISK
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified Point-in-Time

List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1

Creating automatic instance, with SID='onbv'

initialization parameters used for automatic instance:
db_name=WYZC
db_unique_name=onbv_pitr_PDBWYZC_WYZC
compatible=12.1.0.2.0
db_block_size=8192
db_files=200
diagnostic_dest=/u01/oracle
_system_trig_enabled=FALSE
sga_target=1232M
processes=200
db_create_file_dest=/tmp/
log_archive_dest_1='location=/tmp/'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used


starting up automatic instance WYZC

Oracle instance started

Total System Global Area    1291845632 bytes

Fixed Size                     2924016 bytes
Variable Size                352322064 bytes
Database Buffers             922746880 bytes
Redo Buffers                  13852672 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2017-01-13 19:28:50','yyyy-mm-dd hh24:mi:ss')";
# restore the controlfile
restore clone controlfile;
 
# mount the controlfile
sql clone 'alter database mount clone database';
 
# archive current online log 
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script

executing command: SET until clause

Starting restore at 13-JAN-17
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=22 device type=DISK

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/oracle/recovery_area/WYZC/autobackup/2017_01_13/o1_mf_s_933189901_d7kg8hg8_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/oracle/recovery_area/WYZC/autobackup/2017_01_13/o1_mf_s_933189901_d7kg8hg8_.bkp tag=TAG20170113T192501
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/tmp/WYZC/controlfile/o1_mf_d7kh5noc_.ctl
Finished restore at 13-JAN-17

sql statement: alter database mount clone database

sql statement: alter system archive log current

sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2017-01-13 19:28:50','yyyy-mm-dd hh24:mi:ss')";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  4 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  8 to new;
set newname for clone datafile  9 to new;
set newname for clone tempfile  1 to new;
set newname for clone tempfile  3 to new;
set newname for datafile  10 to 
 "/u01/oracle/oradata/wyzc/pdbwyzc/SAMPLE_SCHEMA_users01.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 4, 3, 8, 9, 10;
 
switch clone datafile all;
}
executing Memory Script

executing command: SET until clause

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /tmp/WYZC/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /tmp/WYZC/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 13-JAN-17
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /tmp/WYZC/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00009 to /tmp/WYZC/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/oracle/oradata/wyzc/pdbwyzc/SAMPLE_SCHEMA_users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/oracle/recovery_area/WYZC/1C2F27358BAD7564E0530C9DA8C0C33C/backupset/2017_01_13/o1_mf_nnndf_TAG20170113T192248_d7kg48fy_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/oracle/recovery_area/WYZC/1C2F27358BAD7564E0530C9DA8C0C33C/backupset/2017_01_13/o1_mf_nnndf_TAG20170113T192248_d7kg48fy_.bkp tag=TAG20170113T192248
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /tmp/WYZC/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /tmp/WYZC/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/oracle/recovery_area/WYZC/backupset/2017_01_13/o1_mf_nnndf_TAG20170113T192248_d7kg60cw_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/oracle/recovery_area/WYZC/backupset/2017_01_13/o1_mf_nnndf_TAG20170113T192248_d7kg60cw_.bkp tag=TAG20170113T192248
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /tmp/WYZC/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/oracle/recovery_area/WYZC/backupset/2017_01_13/o1_mf_nnndf_TAG20170113T192248_d7kg87o6_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/oracle/recovery_area/WYZC/backupset/2017_01_13/o1_mf_nnndf_TAG20170113T192248_d7kg87o6_.bkp tag=TAG20170113T192248
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 13-JAN-17

datafile 1 switched to datafile copy
input datafile copy RECID=12 STAMP=933190910 file name=/tmp/WYZC/datafile/o1_mf_system_d7kh6nmp_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=13 STAMP=933190910 file name=/tmp/WYZC/datafile/o1_mf_undotbs1_d7kh7qpg_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=14 STAMP=933190910 file name=/tmp/WYZC/datafile/o1_mf_sysaux_d7kh6nmo_.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=15 STAMP=933190910 file name=/tmp/WYZC/datafile/o1_mf_system_d7kh5vgg_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=16 STAMP=933190910 file name=/tmp/WYZC/datafile/o1_mf_sysaux_d7kh5vfz_.dbf

contents of Memory Script:
{
# set requested point in time
set until  time "to_date('2017-01-13 19:28:50','yyyy-mm-dd hh24:mi:ss')";
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  4 online";
sql clone "alter database datafile  3 online";
sql clone 'PDBWYZC' "alter database datafile 
 8 online";
sql clone 'PDBWYZC' "alter database datafile 
 9 online";
sql clone 'PDBWYZC' "alter database datafile 
 10 online";
# recover and open resetlogs
recover clone database tablespace  "PDBWYZC":"USERS", "SYSTEM", "UNDOTBS1", "SYSAUX", "PDBWYZC":"SYSTEM", "PDBWYZC":"SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script

executing command: SET until clause

sql statement: alter database datafile  1 online

sql statement: alter database datafile  4 online

sql statement: alter database datafile  3 online

sql statement: alter database datafile  8 online

sql statement: alter database datafile  9 online

sql statement: alter database datafile  10 online

Starting recover at 13-JAN-17
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 116 is already on disk as file /u01/oracle/recovery_area/WYZC/archivelog/2017_01_13/o1_mf_1_116_d7kg8crj_.arc
archived log for thread 1 with sequence 117 is already on disk as file /u01/oracle/recovery_area/WYZC/archivelog/2017_01_13/o1_mf_1_117_d7kgr78v_.arc
archived log file name=/u01/oracle/recovery_area/WYZC/archivelog/2017_01_13/o1_mf_1_116_d7kg8crj_.arc thread=1 sequence=116
archived log file name=/u01/oracle/recovery_area/WYZC/archivelog/2017_01_13/o1_mf_1_117_d7kgr78v_.arc thread=1 sequence=117
media recovery complete, elapsed time: 00:00:01
Finished recover at 13-JAN-17

database opened

contents of Memory Script:
{
sql clone 'alter pluggable database  PDBWYZC open';
}
executing Memory Script

sql statement: alter pluggable database  PDBWYZC open

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'PDBWYZC' 'alter tablespace 
 USERS read only';
# create directory for datapump import
sql 'PDBWYZC' "create or replace directory 
TSPITR_DIROBJ_DPDIR as ''
/tmp/''";
# create directory for datapump export
sql clone 'PDBWYZC' "create or replace directory 
TSPITR_DIROBJ_DPDIR as ''
/tmp/''";
}
executing Memory Script

sql statement: alter tablespace  USERS read only

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/tmp/''

sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/tmp/''

Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_onbv_vbts":  
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/REF_CONSTRAINT
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Master table "SYS"."TSPITR_EXP_onbv_vbts" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_onbv_vbts is:
   EXPDP>   /tmp/tspitr_onbv_73289.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace USERS:
   EXPDP>   /u01/oracle/oradata/wyzc/pdbwyzc/SAMPLE_SCHEMA_users01.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_onbv_vbts" successfully completed at Fri Jan 13 19:44:56 2017 elapsed 0 00:02:05
Export completed


contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
# drop target tablespaces before importing them back
sql 'PDBWYZC' 'drop tablespace 
 USERS including contents keep datafiles cascade constraints';
}
executing Memory Script

Oracle instance shut down

sql statement: drop tablespace  USERS including contents keep datafiles cascade constraints

Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_onbv_opmx" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_onbv_opmx":  
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX/INDEX
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/REF_CONSTRAINT
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   IMPDP> Job "SYS"."TSPITR_IMP_onbv_opmx" successfully completed at Fri Jan 13 19:45:55 2017 elapsed 0 00:00:42
Import completed


contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'PDBWYZC' 'alter tablespace 
 USERS read write';
sql 'PDBWYZC' 'alter tablespace 
 USERS offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script

sql statement: alter tablespace  USERS read write

sql statement: alter tablespace  USERS offline

sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;

Removing automatic instance
Automatic instance removed
auxiliary instance file /tmp/WYZC/datafile/o1_mf_temp_d7kh8lob_.tmp deleted
auxiliary instance file /tmp/WYZC/datafile/o1_mf_temp_d7kh8c4p_.tmp deleted
auxiliary instance file /tmp/WYZC/onlinelog/o1_mf_3_d7kh87gm_.log deleted
auxiliary instance file /tmp/WYZC/onlinelog/o1_mf_2_d7kh86pl_.log deleted
auxiliary instance file /tmp/WYZC/onlinelog/o1_mf_1_d7kh85sy_.log deleted
auxiliary instance file /tmp/WYZC/datafile/o1_mf_sysaux_d7kh5vfz_.dbf deleted
auxiliary instance file /tmp/WYZC/datafile/o1_mf_system_d7kh5vgg_.dbf deleted
auxiliary instance file /tmp/WYZC/datafile/o1_mf_sysaux_d7kh6nmo_.dbf deleted
auxiliary instance file /tmp/WYZC/datafile/o1_mf_undotbs1_d7kh7qpg_.dbf deleted
auxiliary instance file /tmp/WYZC/datafile/o1_mf_system_d7kh6nmp_.dbf deleted
auxiliary instance file /tmp/WYZC/controlfile/o1_mf_d7kh5noc_.ctl deleted
auxiliary instance file tspitr_onbv_73289.dmp deleted
Finished recover at 13-JAN-17

RMAN> exit

--验证恢复成功
SQL> alter tablespace users online;  --由于恢复后没有online需要手动online

Tablespace altered.

SQL> select count(*) from scott.emp;

  COUNT(*)
----------
	14
	


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值