[20170623]利用傳輸表空間恢復部分資料.txt
[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種解
決方式.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2141166/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20170623]利用傳輸表空間恢復資料庫2.txt資料庫
- rman恢復資料檔案 恢復表空間
- 【傳輸表空間】使用 EXPDP/IMPDP工具的傳輸表空間完成資料遷移
- 【傳輸表空間】使用 EXPDP/IMPDP工具的傳輸表空間完成資料遷移[轉]
- 利用可恢復空間分配技術自動分配表空間
- (Les16 執行資料庫恢復)-表空間恢復資料庫
- 表空間級資料庫備份恢復資料庫
- 12c 資料泵傳輸表空間
- 資料泵 TTS(傳輸表空間技術)TTS
- [20150408]只讀表空間以及資料庫恢復.txt資料庫
- MySQL 傳輸表空間MySql
- Oracle 表空間傳輸Oracle
- oracle表空間傳輸Oracle
- Oracle傳輸表空間Oracle
- MySQL表空間傳輸MySql
- 【Oracle】rman 恢復只讀表空間資料庫Oracle資料庫
- 【資料遷移】使用傳輸表空間遷移資料
- [20170627]使用TSPITR恢復表空間.txt
- 海量資料遷移之傳輸表空間(一)
- 利用oracle 傳輸表空間來實現歷史資料分離的方案Oracle
- 使用Oracle可傳輸表空間的特性複製資料(7)實戰RMAN備份傳輸表空間Oracle
- Oracle RMAN 表空間恢復Oracle
- mysql 無備份恢復drop資料-共享表空間MySql
- 撤消表空間資料檔案丟失的恢復.
- 記一次undo表空間資料塊恢復
- mysql之 表空間傳輸MySql
- 傳輸表空間操作-OracleOracle
- Oracle傳輸表空間(TTS)OracleTTS
- Oracle 傳輸表空間-RmanOracle
- 總結-表空間傳輸
- [20150408]只讀表空間以及資料庫恢復2.txt資料庫
- 【實驗】利用可傳輸表空間技術實現資料的高效遷移
- 用傳輸表空間跨平臺遷移資料
- RMAN跨平臺傳輸資料庫和表空間資料庫
- [20170520]利用undo表空間保護資料.txt
- 跨平臺表空間遷移(傳輸表空間)
- 【管理篇備份恢復】rman恢復測試(一) 表空間資料檔案
- 【Oracle 恢復表空間】 實驗Oracle