[20170623]利用传输表空间恢复部分数据.txt

--//昨天我测试使用传输表空间+dblink,上午补充测试发现表空间设置只读才能执行impdp导入原数据,这个也很好理解.
--//这样的操作模式仅仅减少expdp生成原数据的过程.

--//我想一下,rman也支持建立传输表空间的命令.我仔细看了以前的笔记,发现这样最大的有点不用设置只读,实际上它是通过建立辅组实
--//例来建立传输文件,理论讲可以恢复到特定的scn,这样可以利用它解决一些误操作的问题,还是通过例子来说明问题.

1.环境:
--//前面的测试有点乱,我使用冷备份恢复数据库.

SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

--//先做1次全备份.
SCOTT@book> alter system archive log current ;
System altered.

RMAN> backup database format '/home/oracle/backup/full_20170623_%U.bak';
Starting backup at 2017-06-23 10:00:21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=256 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=3 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=13 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/mnt/ramdisk/book/sysaux01.dbf
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
channel ORA_DISK_1: starting piece 1 at 2017-06-23 10:00:23
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00003 name=/mnt/ramdisk/book/undotbs01.dbf
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_2: starting piece 1 at 2017-06-23 10:00:23
channel ORA_DISK_3: starting full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
input datafile file number=00001 name=/mnt/ramdisk/book/system01.dbf
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
channel ORA_DISK_3: starting piece 1 at 2017-06-23 10:00:23
channel ORA_DISK_2: finished piece 1 at 2017-06-23 10:00:24
piece handle=/home/oracle/backup/full_20170623_f8s7gn1n_1_1.bak tag=TAG20170623T100023 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: finished piece 1 at 2017-06-23 10:00:30
piece handle=/home/oracle/backup/full_20170623_f7s7gn1n_1_1.bak tag=TAG20170623T100023 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_3: finished piece 1 at 2017-06-23 10:00:30
piece handle=/home/oracle/backup/full_20170623_f9s7gn1n_1_1.bak tag=TAG20170623T100023 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:07
Finished backup at 2017-06-23 10:00:30
Starting Control File and SPFILE Autobackup at 2017-06-23 10:00:30
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_06_23/o1_mf_s_947412030_dnrxkyll_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-06-23 10:00:31

RMAN> backup archivelog all  format '/home/oracle/backup/archive_20170623_%U';
Starting backup at 2017-06-23 10:01:43
current log archived
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
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=695 RECID=1235 STAMP=947411681
input archived log thread=1 sequence=696 RECID=1236 STAMP=947411976
channel ORA_DISK_1: starting piece 1 at 2017-06-23 10:01:43
channel ORA_DISK_2: starting archived log backup set
channel ORA_DISK_2: specifying archived log(s) in backup set
input archived log thread=1 sequence=697 RECID=1237 STAMP=947412066
input archived log thread=1 sequence=698 RECID=1238 STAMP=947412078
channel ORA_DISK_2: starting piece 1 at 2017-06-23 10:01:43
channel ORA_DISK_3: starting archived log backup set
channel ORA_DISK_3: specifying archived log(s) in backup set
input archived log thread=1 sequence=699 RECID=1239 STAMP=947412103
channel ORA_DISK_3: starting piece 1 at 2017-06-23 10:01:43
channel ORA_DISK_2: finished piece 1 at 2017-06-23 10:01:43
piece handle=/home/oracle/backup/archive_20170623_fcs7gn47_1_1 tag=TAG20170623T100143 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:00
channel ORA_DISK_1: finished piece 1 at 2017-06-23 10:01:44
piece handle=/home/oracle/backup/archive_20170623_fbs7gn47_1_1 tag=TAG20170623T100143 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_3: finished piece 1 at 2017-06-23 10:01:44
piece handle=/home/oracle/backup/archive_20170623_fds7gn47_1_1 tag=TAG20170623T100143 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-06-23 10:01:44
Starting Control File and SPFILE Autobackup at 2017-06-23 10:01:44
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_06_23/o1_mf_s_947412105_dnrxn912_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-06-23 10:01:46

2.建立测试环境:
SCOTT@book> create table t tablespace tea as select * from all_objects;
Table created.

SCOTT@book> alter system archive log current ;
System altered.

SCOTT@book> select count(*) from t ;
COUNT(*)
--------
   84760

SCOTT@book> set numw 12
SCOTT@book> select current_scn,sysdate from v$database ;
 CURRENT_SCN SYSDATE
------------ -------------------
 13276934697 2017-06-23 10:08:18

--//假设做了一次误操作.
SCOTT@book> delete from t where owner='SYSTEM';
568 rows deleted.

SCOTT@book> commit ;
Commit complete.

SCOTT@book> alter system archive log current ;
System altered.
--//这里做一点点说明,我第一次测试没有做日志切换,以及下面的备份,在执行后面transport tablespace tea时不成功,我估计切换就ok了.
--//某种程度我认为恢复不会扫描在线日志.

--//再建立archivelog的备份.
RMAN> backup archivelog all  not  backed up 1 times format '/home/oracle/backup/archivex_20170623_%U';
Starting backup at 2017-06-23 10:12:24
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=13 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=35 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=47 device type=DISK
skipping archived logs of thread 1 from sequence 695 to 699; already backed up
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=700 RECID=1240 STAMP=947412464
channel ORA_DISK_1: starting piece 1 at 2017-06-23 10:12:27
channel ORA_DISK_2: starting archived log backup set
channel ORA_DISK_2: specifying archived log(s) in backup set
input archived log thread=1 sequence=701 RECID=1241 STAMP=947412611
channel ORA_DISK_2: starting piece 1 at 2017-06-23 10:12:27
channel ORA_DISK_3: starting archived log backup set
channel ORA_DISK_3: specifying archived log(s) in backup set
input archived log thread=1 sequence=702 RECID=1242 STAMP=947412746
channel ORA_DISK_3: starting piece 1 at 2017-06-23 10:12:27
channel ORA_DISK_2: finished piece 1 at 2017-06-23 10:12:27
piece handle=/home/oracle/backup/archivex_20170623_fgs7gnob_1_1 tag=TAG20170623T101227 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:00
channel ORA_DISK_1: finished piece 1 at 2017-06-23 10:12:28
piece handle=/home/oracle/backup/archivex_20170623_ffs7gnob_1_1 tag=TAG20170623T101227 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_3: finished piece 1 at 2017-06-23 10:12:28
piece handle=/home/oracle/backup/archivex_20170623_fhs7gnob_1_1 tag=TAG20170623T101227 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-06-23 10:12:28
Starting Control File and SPFILE Autobackup at 2017-06-23 10:12:28
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_06_23/o1_mf_s_947412749_dnry8f1x_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2017-06-23 10:12:30

3.现在使用rman的transport命令看看.
$ mkdir /home/oracle/aux

RMAN> transport tablespace tea tablespace destination '/home/oracle/aux' auxiliary destination '/home/oracle/aux' until scn 13276934697;

using target database control file instead of recovery catalog
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='DCzc'

initialization parameters used for automatic instance:
db_name=BOOK
db_unique_name=DCzc_tspitr_BOOK
compatible=11.2.0.4.0
db_block_size=8192
db_files=200
sga_target=1G
processes=80
db_create_file_dest=/home/oracle/aux
log_archive_dest_1='location=/home/oracle/aux'
#No auxiliary parameter file used

starting up automatic instance BOOK
Oracle instance started
Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                285213576 bytes
Database Buffers             771751936 bytes
Redo Buffers                   9711616 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  scn 13276934697;
# 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';
}
executing Memory Script

executing command: SET until clause

Starting restore at 2017-06-23 10:15:47
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=127 device type=DISK
allocated channel: ORA_AUX_DISK_2
channel ORA_AUX_DISK_2: SID=133 device type=DISK
allocated channel: ORA_AUX_DISK_3
channel ORA_AUX_DISK_3: SID=139 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/app/oracle/fast_recovery_area/BOOK/autobackup/2017_06_23/o1_mf_s_947412105_dnrxn912_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2017_06_23/o1_mf_s_947412105_dnrxn912_.bkp tag=TAG20170623T100145
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/aux/BOOK/controlfile/o1_mf_dnrygn8d_.ctl
Finished restore at 2017-06-23 10:15:49

sql statement: alter database mount clone database

sql statement: alter system archive log current

contents of Memory Script:
{
# set requested point in time
set until  scn 13276934697;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  2 to new;
set newname for clone tempfile  1 to new;
set newname for datafile  6 to
 "/home/oracle/aux/tea01.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 3, 2, 6;
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

renamed tempfile 1 to /home/oracle/aux/BOOK/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 2017-06-23 10:15:53
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3

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 00003 to /home/oracle/aux/BOOK/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /home/oracle/aux/tea01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/backup/full_20170623_f8s7gn1n_1_1.bak
channel ORA_AUX_DISK_2: starting datafile backup set restore
channel ORA_AUX_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_2: restoring datafile 00001 to /home/oracle/aux/BOOK/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_2: reading from backup piece /home/oracle/backup/full_20170623_f9s7gn1n_1_1.bak
channel ORA_AUX_DISK_3: starting datafile backup set restore
channel ORA_AUX_DISK_3: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_3: restoring datafile 00002 to /home/oracle/aux/BOOK/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_3: reading from backup piece /home/oracle/backup/full_20170623_f7s7gn1n_1_1.bak
channel ORA_AUX_DISK_1: piece handle=/home/oracle/backup/full_20170623_f8s7gn1n_1_1.bak tag=TAG20170623T100023
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_2: piece handle=/home/oracle/backup/full_20170623_f9s7gn1n_1_1.bak tag=TAG20170623T100023
channel ORA_AUX_DISK_2: restored backup piece 1
channel ORA_AUX_DISK_2: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_3: piece handle=/home/oracle/backup/full_20170623_f7s7gn1n_1_1.bak tag=TAG20170623T100023
channel ORA_AUX_DISK_3: restored backup piece 1
channel ORA_AUX_DISK_3: restore complete, elapsed time: 00:00:15
Finished restore at 2017-06-23 10:16:09

datafile 1 switched to datafile copy
input datafile copy RECID=17 STAMP=947412969 file name=/home/oracle/aux/BOOK/datafile/o1_mf_system_dnrygt6f_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=18 STAMP=947412969 file name=/home/oracle/aux/BOOK/datafile/o1_mf_undotbs1_dnrygt64_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=19 STAMP=947412969 file name=/home/oracle/aux/BOOK/datafile/o1_mf_sysaux_dnrygt6n_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=20 STAMP=947412969 file name=/home/oracle/aux/tea01.dbf

contents of Memory Script:
{
# set requested point in time
set until  scn 13276934697;
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone "alter database datafile  3 online";
sql clone "alter database datafile  2 online";
sql clone "alter database datafile  6 online";
# recover and open resetlogs
recover clone database tablespace  "TEA", "SYSTEM", "UNDOTBS1", "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  3 online
sql statement: alter database datafile  2 online
sql statement: alter database datafile  6 online

Starting recover at 2017-06-23 10:16:09
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3

starting media recovery

archived log for thread 1 with sequence 697 is already on disk as file /u01/app/oracle/archivelog/book/1_697_896605872.dbf
archived log for thread 1 with sequence 698 is already on disk as file /u01/app/oracle/archivelog/book/1_698_896605872.dbf
archived log for thread 1 with sequence 699 is already on disk as file /u01/app/oracle/archivelog/book/1_699_896605872.dbf
archived log for thread 1 with sequence 700 is already on disk as file /u01/app/oracle/archivelog/book/1_700_896605872.dbf
archived log for thread 1 with sequence 701 is already on disk as file /u01/app/oracle/archivelog/book/1_701_896605872.dbf
--//如果归档在,实际上不会restore归档文件.而且要使用到seq=701,我个人估计如果seq=701没有归档(还在现在日志),这里会报错.
--//估计这是我第一次为什么不行的原因.
archived log file name=/u01/app/oracle/archivelog/book/1_697_896605872.dbf thread=1 sequence=697
archived log file name=/u01/app/oracle/archivelog/book/1_698_896605872.dbf thread=1 sequence=698
archived log file name=/u01/app/oracle/archivelog/book/1_699_896605872.dbf thread=1 sequence=699
archived log file name=/u01/app/oracle/archivelog/book/1_700_896605872.dbf thread=1 sequence=700
archived log file name=/u01/app/oracle/archivelog/book/1_701_896605872.dbf thread=1 sequence=701
media recovery complete, elapsed time: 00:00:01
Finished recover at 2017-06-23 10:16:11

database opened

contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace  TEA read only';
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''
/home/oracle/aux''";
}
executing Memory Script

sql statement: alter tablespace  TEA read only

sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/home/oracle/aux''

Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_DCzc":
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Master table "SYS"."TSPITR_EXP_DCzc" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_DCzc is:
   EXPDP>   /home/oracle/aux/dmpfile.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace TEA:
   EXPDP>   /home/oracle/aux/tea01.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_DCzc" successfully completed at Fri Jun 23 10:16:53 2017 elapsed 0 00:00:36
Export completed

/*
   The following command may be used to import the tablespaces.
   Substitute values for <logon> and <directory>.
   impdp <logon> directory=<directory> dumpfile= 'dmpfile.dmp' transport_datafiles= /home/oracle/aux/tea01.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/home/oracle/aux/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS  '/home/oracle/aux';
/* PL/SQL Script to import the exported tablespaces */
DECLARE
  -- the datafiles
  tbs_files     dbms_streams_tablespace_adm.file_set;
  cvt_files     dbms_streams_tablespace_adm.file_set;
  -- the dumpfile to import
  dump_file     dbms_streams_tablespace_adm.file;
  dp_job_name   VARCHAR2(30) := NULL;
  -- names of tablespaces that were imported
  ts_names       dbms_streams_tablespace_adm.tablespace_set;
BEGIN
  -- dump file name and location
  dump_file.file_name :=  'dmpfile.dmp';
  dump_file.directory_object := 'STREAMS$DIROBJ$DPDIR';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'tea01.dbf';
  tbs_files( 1).directory_object :=  'STREAMS$DIROBJ$1';
  -- import tablespaces
  dbms_streams_tablespace_adm.attach_tablespaces(
    datapump_job_name      => dp_job_name,
    dump_file              => dump_file,
    tablespace_files       => tbs_files,
    converted_files        => cvt_files,
    tablespace_names       => ts_names);
  -- output names of imported tablespaces
  IF ts_names IS NOT NULL AND ts_names.first IS NOT NULL THEN
    FOR i IN ts_names.first .. ts_names.last LOOP
      dbms_output.put_line('imported tablespace '|| ts_names(i));
    END LOOP;
  END IF;
END;
/
-- dropping directory objects
DROP DIRECTORY STREAMS$DIROBJ$1;
DROP DIRECTORY STREAMS$DIROBJ$DPDIR;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------
Removing automatic instance
shutting down automatic instance
database closed
database dismounted
Oracle instance shut down
Automatic instance removed
auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_temp_dnryhd16_.tmp deleted
auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_3_dnryhcpv_.log deleted
auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_2_dnryhclr_.log deleted
auxiliary instance file /home/oracle/aux/BOOK/onlinelog/o1_mf_1_dnryhcd4_.log deleted
auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_sysaux_dnrygt6n_.dbf deleted
auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_undotbs1_dnrygt64_.dbf deleted
auxiliary instance file /home/oracle/aux/BOOK/datafile/o1_mf_system_dnrygt6f_.dbf deleted
auxiliary instance file /home/oracle/aux/BOOK/controlfile/o1_mf_dnrygn8d_.ctl deleted

--//说明实际上rman下transport命令就是通过辅组实例+数据库备份来恢复到特定时间点或者scn.
--//它恢复数据文件1,2,3,6(tea的表空间数据文件).所以一定要有一定的磁盘空间做这样的事情.

--//看看生成的文件:

$ ls -l /home/oracle/aux/
total 41124
drwxr-x--- 5 oracle oinstall     4096 2017-06-23 10:15:53 BOOK
-rw-r----- 1 oracle oinstall   102400 2017-06-23 10:16:53 dmpfile.dmp
-rw-r--r-- 1 oracle oinstall     2051 2017-06-23 10:16:56 impscrpt.sql
-rw-r----- 1 oracle oinstall 41951232 2017-06-23 10:16:14 tea01.dbf

--//tea01.dbf就是传输表空间的数据文件.dmpfile.dmp就是源数据,而impscrpt.sql就是如何导入的脚本.

4.导入当前数据库.
--//直接导入肯定不行,表名以及表空间冲突,必须重新映射.
--//直接拷贝dmpfile.dmp到缺省的directory目录.这样参数可以不指定directory.自己有点懒.

$ cp /home/oracle/aux/dmpfile.dmp /u01/app/oracle/admin/book/dpdump/

--//建立用户sss,简单一点直接给dba权限.
SCOTT@book> grant dba to sss IDENTIFIED BY sss;
Grant succeeded.

impdp system/oracle dumpfile=dmpfile.dmp transport_datafiles=/home/oracle/aux/tea01.dbf REMAP_TABLESPACE=TEA:SUGAR
REMAP_SCHEMA=scott:sss logfile=impdp.log

$ impdp system/oracle dumpfile=dmpfile.dmp transport_datafiles=/home/oracle/aux/tea01.dbf REMAP_TABLESPACE=TEA:SUGAR REMAP_SCHEMA=scott:sss logfile=impdp.log
Import: Release 11.2.0.4.0 - Production on Fri Jun 23 10:37:48 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/a* dumpfile=dmpfile.dmp transport_datafiles=/home/oracle/aux/tea01.dbf REMAP_TABLESPACE=TEA:SUGAR REMAP_SCHEMA=scott:sss logfile=impdp.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Fri Jun 23 10:37:52 2017 elapsed 0 00:00:03
--OK,大告成功,^_^.

5.检查看看.
SCOTT@book> select count(*) from sss.t;
    COUNT(*)
------------
       84760

SCOTT@book> select count(*) from t;
    COUNT(*)
------------
       84192

--//84760-84192=568,与前面删除的记录相符合.而且这样还有1个好处,rowid两个表是一样的.有利于对比恢复.
--//当然我这里做的是delete.

SCOTT@book> select rowid,object_name from t where rownum=1;
ROWID              OBJECT_NAME
------------------ --------------------
AAAWEEAAGAAAACBAAA ICOL$

SCOTT@book> select rowid,object_name from sss.t where rownum=1;
ROWID              OBJECT_NAME
------------------ --------------------
AAAWEEAAGAAAACBAAA ICOL$

--//这里两个表的rowid一样,以后别人讲rowid一样,不一定指向相同的记录以及对象.可能吗?大家应该知道如何回答了吧.
--//当然还有1种情况是cluster table.

SCOTT@book> select count(*) from sss.t where rowid not in ( select rowid from scott.t );
    COUNT(*)
------------
         568
--//可以发现插入就是以上这些记录.

总结:
1.理解rman的transport tablespace的原理是通过辅组实例来恢复的,实际上就是specified point-in-time,可以恢复特定的scny以及时
  间点.
2.而且rman的transport tablespace实际上就是封装许多rman命令来实现这个功能,这样的好处是减少差错.
3.我在测试中第1次没有成功,我估计问题在于要恢复的信息还是当前日志,必须把这些信息归档,也就是执行如下:
alter system archive log current ;

4.这样恢复需要一定的磁盘空间,而且建立辅组实例需要数据文件1,2,3以及需要的恢复的表空间,必须事先评估磁盘空间是否充足.
5.当我做完测试,第1个感觉这样简单,如果恢复的表空间不是很大,磁盘空间充足的情况下.这种方式不失简单快捷.只要有备份.^_^
  你不需要建立spfile文件,restore 控制文件.就在本机执行如下命令.

transport tablespace tea tablespace destination '/home/oracle/aux' auxiliary destination '/home/oracle/aux' until scn 13276934697;

6.当然对于前面的问题,最快的就是利用undo的select * from t as of scn...操作.我仅仅是给一些已经相隔很久时间的情况,提供1种解
  决方式.

[20170623]利用传输表空间恢复部分数据.txt的更多相关文章

  1. [20170623]利用传输表空间恢复数据库2.txt

    [20170623]利用传输表空间恢复数据库2.txt --//继续上午的测试,测试truncate,是否可行,理论讲应该没有问题.我主要的目的测试是否要切换日志.--//参考链接 : http:// ...

  2. [20170622]传输表空间与dblink.txt

    [20170622]传输表空间与dblink.txt --//测试看看使用dblink+传输表空间的情况.写的情况相对复杂一点,具体看测试: 1.环境:--//2个数据库版本一致.实际上在1台主机上. ...

  3. Oracle传输表空间介绍

    传输表空间通过拷贝数据文件的方式,实现可跨平台的数据迁移,效率远超expdp/impdp, exp/imp等工具.还可以应用跨平台&数据库版本迁移表数据.归档历史数据和实现表空间级时间点数据恢 ...

  4. mysql5.6之 传输表空间迁移表或恢复误删除的表

    一,简单说明: 1),传输表空间的限制:  1,mysql 版本 5.6.6 及其以上,并且版本建议源和目标版本建议都是GA版并且大版本一样  2,表引擎为innodb并且开启独立表空间  innod ...

  5. 数据泵 TTS(传输表空间技术)

    1.源库准备环境 --创建被传输的表空间create tablespace tts logging datafile '/home/oracle/app/oradata/orcl/tts01.dbf' ...

  6. 使用MySQL传输表空间迁移数据

    对于大表的迁移,如果使用mysqldump进行导出,然后重新导入到其它环境,速度是非常缓慢的.如果使用传输表空间,则可以解决这个问题. 测试使用传输表空间迁移表,基础环境如下:   源库 目标库 IP ...

  7. 转 Oracle Transportable TableSpace(TTS) 传输表空间 说明

    ############1   迁移数据库的集中方法 三.相关技术 迁移方式 优势 不足1 Export and import • 对数据库版本,以及系统平台没有要求 • 不支持并发,速度慢• 停机时 ...

  8. 【TTS】传输表空间AIX asm -> linux asm

    [TTS]传输表空间AIX asm -> linux asm 一.1  BLOG文档结构图       一.2  前言部分   一.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌 ...

  9. 【TTS】传输表空间Linux asm -> AIX asm

    [TTS]传输表空间Linux asm -> AIX asm 一.1  BLOG文档结构图       一.2  前言部分   一.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌 ...

随机推荐

  1. [P4921] 情侣?给我烧了!

    回顾一下错排公式 错排问题: 设n位错排数为D[n].考虑元素1的位置,设置为k(有n-1中 ):在考虑元素k的位置, 若为1,则转换为n-2位的错排:否则,视元素k为元素1(不能放在位置1),转换为 ...

  2. pycharm中可以运行脚本但是不能debug脚本

    以前用的时候好好地,但是最近上班突然脚本就不能debug了,debug直接报错,如下所示 上网查过该有的原因: 1.在pycharm中两个地方设置成utf-8,页面右下角和File>settin ...

  3. java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.bjsxt.mapper.PeopleMapper

    报错信息: Type Exception Report Description The server encountered an unexpected condition that prevente ...

  4. 213. Orchard学习 二 3、001.IOrchardHost 与Autofac

    继前篇,在Orchard Application_Start() -> HostInitialization() 里,调用 OrchardStarter.CreateHost创建IOrchard ...

  5. selenium+Python(select定位)

    1.Select元素 1.打开百度-设置-搜索设置界面,如下图所示 2.箭头所指位置,就是 select 选项框,打开页面元素定位,下方红色框框区域,可以看到 select 标签属性: <sel ...

  6. Ubuntu/CentOS 系统上安装与配置Nginx

    一.在线安装: Ubuntu:sudo apt-get install nginx CentOS: sudo yum install nginx 二.安装后的位置: 1.服务地址:/etc/init. ...

  7. 理解express中的中间件

    express是轻量灵活的node.js Web应用框架”.它可以帮助你快速搭建web应用.express是一个自身功能极简,完全是由**路由**和**中间件**构成的一个web开发框架,本质上说,一 ...

  8. 读vue-0.6-text-parser.js源码

    提取字符串中的表达式 var BINDING_RE = /\{\{(.+?)\}\}/; function parse(text) { // 找不到返回null if (!BINDING_RE.tes ...

  9. iOS开发必会的坐标系探究

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由落影发表于云+社区专栏 前言 app在渲染视图时,需要在坐标系中指定绘制区域. 这个概念看似乎简单,事实并非如此. When an a ...

  10. 【jQuery源码】整体架构

    jQuery源码可以精简为以下内容: 方框上面的代码根据Jq注释我们可以知道是对AMD规范的支持. jQuery整体上被包裹在一个匿名函数中,这个匿名函数再作为另一个匿名函数的参数被传入,形参fact ...