[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种解
决方式.