[20170623]利用傳輸表空間恢復部分數據.txt

来源:http://www.cnblogs.com/lfree/archive/2017/06/23/7068974.html
-Advertisement-
Play Games

[20170623]利用傳輸表空間恢復部分數據.txt--//昨天我測試使用傳輸表空間+dblink,上午補充測試發現表空間設置只讀才能執行impdp導入原數據,這個也很好理解.--//這樣的操作模式僅僅減少expdp生成原數據的過程.--//我想一下,rman也支持建立傳輸表空間的命令.我仔細看了 ...


[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種解
  決方式.


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...