通過RMAN-transport獲取傳輸表空間檔案
可傳輸表空間可用於快速傳輸應用資料,但需要設定表空間為只讀。其實,ORACLE支援通過從備份中獲取時間點恢復的表空間,支援表空間在讀寫狀態下,傳輸到目標資料庫。
參考文件:
Oracle Database Backup and Recovery Advanced User's Guide10g Release 2 (10.2),14 Creating Transportable Tablespace Sets from Backup with RMAN
測試如下:
0,版本
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Linux: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
1,建立全庫備份
RMAN> backup database plus archivelog;
2,建立表空間
SQL> create tablespace b_tbs datafile '/u01/app/oracle/oradata/ttt/b_tbs01.dbf' size 10m;
Tablespace created.
SQL> create table mh.test2 tablespace b_tbs as select * from dba_objects
Table created.
SQL> insert into mh.test2 select * from mh.test2;
9429 rows created.
==>插入未提交,對應表空間處於可讀寫狀態,甚至存在未提交事務
3,使用RMAN從備份檔案獲取傳輸表空間檔案
RMAN> transport tablespace b_tbs
2> tablespace destination '/tmp/tts/df'
3> auxiliary destination '/tmp/tts/tmp'
4> ;
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 UNDO_TBS
Creating automatic instance, with SID='bwwg'
initialization parameters used for automatic instance:
db_name=TTT
compatible=10.2.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TTT_bwwg
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/tmp/tts/tmp
control_files=/tmp/tts/tmp/cntrl_tspitr_TTT_bwwg.f
starting up automatic instance TTT
Oracle instance started
Total System Global Area 205520896 bytes
Fixed Size 1260888 bytes
Variable Size 146801320 bytes
Database Buffers 50331648 bytes
Redo Buffers 7127040 bytes
Automatic instance created
Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of tranport tablespace command at 05/21/2013 16:22:34
RMAN-20202: tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "B_TBS"
==>備份的控制檔案中不包含新建立的表空間資訊
4,重新進行全庫備份
RMAN> backup database plus archivelog;
5,使用RMAN從備份檔案獲取傳輸表空間檔案
RMAN> transport tablespace b_tbs
2> tablespace destination '/tmp/tts/df'
3> auxiliary destination '/tmp/tts/tmp'
4> ;
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 UNDO_TBS
Creating automatic instance, with SID='EuFr'
initialization parameters used for automatic instance:
db_name=TTT
compatible=10.2.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_TTT_EuFr
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/tmp/tts/tmp
control_files=/tmp/tts/tmp/cntrl_tspitr_TTT_EuFr.f
starting up automatic instance TTT
Oracle instance started
Total System Global Area 205520896 bytes
Fixed Size 1260888 bytes
Variable Size 146801320 bytes
Database Buffers 50331648 bytes
Redo Buffers 7127040 bytes
Automatic instance created
contents of Memory Script.:
{
# set the until clause
set until scn 197002;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script
executing command: SET until clause
Starting restore at 21-MAY-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=37 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/product/10.2.0/db_1/dbs/c-1768998978-20130521-01
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1768998978-20130521-01 tag=TAG20130521T161605
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/tmp/tts/tmp/cntrl_tspitr_TTT_EuFr.f
Finished restore at 21-MAY-13
sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
released channel: ORA_DISK_1
released channel: ORA_AUX_DISK_1
contents of Memory Script.:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until scn 197002;
# set an omf destination filename for restore
set newname for clone datafile 1 to new;
# set an omf destination filename for restore
set newname for clone datafile 2 to new;
# set an omf destination filename for restore
set newname for clone datafile 3 to new;
# set an omf destination tempfile
set newname for clone tempfile 1 to new;
# set a destination filename for restore
set newname for datafile 5 to "/tmp/tts/df/b_tbs01.dbf"; ==>需要傳輸的表空間
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile 1, 2, 3, 5;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile 1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile 2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile 3 online";
#online the datafiles restored or flipped
sql clone "alter database datafile 5 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace "B_TBS", "SYSTEM", "UNDO_TBS", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
# datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
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 temporary file 1 to /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_tempts1_%u_.tmp in control file
Starting restore at 21-MAY-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=39 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_undo_tbs_%u_.dbf
restoring datafile 00003 to /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_sysaux_%u_.dbf
restoring datafile 00005 to /tmp/tts/df/b_tbs01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/backup/ttt/0eoa6v5s_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/backup/ttt/0eoa6v5s_1_1 tag=TAG20130521T162428
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:08
Finished restore at 21-MAY-13
datafile 1 switched to datafile copy
input datafile copy recid=8 stamp=816020933 filename=/tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_system_8spcy5ym_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=9 stamp=816020933 filename=/tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_undo_tbs_8spcy606_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=10 stamp=816020933 filename=/tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_sysaux_8spcy5z1_.dbf
datafile 5 switched to datafile copy
input datafile copy recid=11 stamp=816020933 filename=/tmp/tts/df/b_tbs01.dbf
sql statement: alter database datafile 1 online
sql statement: alter database datafile 2 online
sql statement: alter database datafile 3 online
sql statement: alter database datafile 5 online
Starting recover at 21-MAY-13
using channel ORA_AUX_DISK_1
starting media recovery
archive log thread 1 sequence 38 is already on disk as file /u01/app/oracle/archive/ttt/1_38_815408962.dbf
archive log thread 1 sequence 39 is already on disk as file /u01/app/oracle/archive/ttt/1_39_815408962.dbf
archive log filename=/u01/app/oracle/archive/ttt/1_38_815408962.dbf thread=1 sequence=38
archive log filename=/u01/app/oracle/archive/ttt/1_39_815408962.dbf thread=1 sequence=39
media recovery complete, elapsed time: 00:00:03
Finished recover at 21-MAY-13
database opened
contents of Memory Script.:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace B_TBS read only"; ==>READ ONLY
# create directory for datapump export
sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''/tmp/tts/df''";
# export the tablespaces in the recovery set
host 'expdp userid=\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/product/10.2.0/db_1/bin/oracle\)\(ARGV0=oracleEuFr\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=EuFr^'\)\)\(CONNECT_DATA=\(SID=EuFr\)\)\) as sysdba\"
transport_tablespaces=B_TBS
dumpfile= dmpfile.dmp
directory= STREAMS_DIROBJ_DPDIR
logfile=explog.log';
}
executing Memory Script
sql statement: alter tablespace B_TBS read only
sql statement: create or replace directory STREAMS_DIROBJ_DPDIR as ''/tmp/tts/df''
Export: Release 10.2.0.3.0 - Production on Tuesday, 21 May, 2013 16:29:47
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01": userid="/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/u01/app/oracle/product/10.2.0/db_1/bin/oracle)(ARGV0=oracleEuFr)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=EuFr))(CONNECT_DATA=(SID=EuFr))) AS SYSDBA" transport_tablespaces= B_TBS dumpfile=dmpfile.dmp directory=STREAMS_DIROBJ_DPDIR logfile=explog.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TRANSPORTABLE_01 is:
/tmp/tts/df/dmpfile.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 16:30:00
host command complete
/*
The following command may be used to import the tablespaces.
Substitute values for
impdp
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script. for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS '/tmp/tts/df/';
CREATE DIRECTORY STREAMS$DIROBJ$DPDIR AS '/tmp/tts/df';
/* 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 := 'b_tbs01.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
Oracle instance shut down
Automatic instance removed
auxiliary instance file /tmp/tts/tmp/cntrl_tspitr_TTT_EuFr.f deleted
auxiliary instance file /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_system_8spcy5ym_.dbf deleted
auxiliary instance file /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_undo_tbs_8spcy606_.dbf deleted
auxiliary instance file /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_sysaux_8spcy5z1_.dbf deleted
auxiliary instance file /tmp/tts/tmp/TSPITR_TTT_EUFR/datafile/o1_mf_tempts1_8spd3olh_.tmp deleted
auxiliary instance file /tmp/tts/tmp/TSPITR_TTT_EUFR/onlinelog/o1_mf_1_8spd2bf8_.log deleted
auxiliary instance file /tmp/tts/tmp/TSPITR_TTT_EUFR/onlinelog/o1_mf_2_8spd2yf7_.log deleted
auxiliary instance file /tmp/tts/tmp/TSPITR_TTT_EUFR/onlinelog/o1_mf_3_8spd3f1b_.log deleted
[oracle@test tts]$ find .
.
./df
./df/explog.log
./df/b_tbs01.dbf
./df/impscrpt.sql
./df/dmpfile.dmp
./tmp
./tmp/TSPITR_TTT_EUFR
./tmp/TSPITR_TTT_EUFR/onlinelog
./tmp/TSPITR_TTT_EUFR/datafile
[oracle@test tts]$ cd df
[oracle@test df]$ ls -lrt
total 10352
-rw-r----- 1 oracle oinstall 10493952 May 21 16:29 b_tbs01.dbf
-rw-r--r-- 1 oracle oinstall 1165 May 21 16:30 explog.log
-rw-r----- 1 oracle oinstall 77824 May 21 16:30 dmpfile.dmp
-rw-r--r-- 1 oracle oinstall 2040 May 21 16:30 impscrpt.sql
6,匯入目標庫
參考impscrpt.sql中的說明,使用命令列方式匯入:
impdp
6.1在目標庫建立目錄:
SQL> create directory tts_dir as '/tmp/tts/df';
Directory created.
6.2匯入
impdp system/oracle directory=tts_dir dumpfile=dmpfile.dmp transport_datafiles=/tmp/tts/df/b_tbs01.dbf
[oracle@test ~]$ impdp system/oracle directory=tts_dir dumpfile=dmpfile.dmp transport_datafiles=b_tbs01.dbf
Import: Release 10.2.0.3.0 - Production on Tuesday, 21 May, 2013 16:48:53
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01": system/******** directory=tts_dir dumpfile=dmpfile.dmp transport_datafiles=b_tbs01.dbf
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
ORA-39123: Data Pump transportable tablespace job aborted
ORA-29342: user MH does not exist in the database
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" stopped due to fatal error at 16:49:00
==>使用者不存在,導致匯入失敗
6.3再次匯入
impdp system/oracle directory=tts_dir dumpfile=dmpfile.dmp transport_datafiles=/tmp/tts/df/b_tbs01.dbf remap_schema=mh:system
6.4驗證
SQL> select count(*) from system.test2;
COUNT(*)
----------
9429
6.5修改表空間為讀寫狀態
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
UNDOTBS1 ONLINE
SYSAUX ONLINE
TEMP ONLINE
USERS ONLINE
MGMT_TABLESPACE ONLINE
MGMT_ECM_DEPOT_TS ONLINE
RCTS ONLINE
TBS4 READ ONLY
B_TBS READ ONLY
SQL> alter tablespace b_tbs read write;
Tablespace altered.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-762379/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle小知識點12--傳輸表空間通過rmanOracle
- MySQL 傳輸表空間MySql
- Oracle 表空間傳輸Oracle
- oracle表空間傳輸Oracle
- Oracle傳輸表空間Oracle
- MySQL表空間傳輸MySql
- oracle小知識點11--傳輸表空間通過impdp/expdpOracle
- vue+axio通過獲取dom元素上傳檔案Vue
- mysql之 表空間傳輸MySql
- 傳輸表空間操作-OracleOracle
- Oracle傳輸表空間(TTS)OracleTTS
- Oracle 傳輸表空間-RmanOracle
- 總結-表空間傳輸
- 跨平臺表空間遷移(傳輸表空間)
- 通過web url獲取檔案資訊Web
- 通過反射獲取上傳檔案方法引數中的檔名反射
- mssql 獲取表空間大小SQL
- 【傳輸表空間】使用 EXPDP/IMPDP工具的傳輸表空間完成資料遷移
- 基於可傳輸表空間的表空間遷移
- Oracle傳輸表空間學習Oracle
- Oracle 傳輸表空間-EXPDP/IMPDPOracle
- Oracle 傳輸表空間-EXP/IMPOracle
- 傳輸表空間自包含理解
- Oracle表空間傳輸詳解Oracle
- 【傳輸表空間】使用 EXPDP/IMPDP工具的傳輸表空間完成資料遷移[轉]
- 通過xtts遷移單例項檔案系統表空間到RAC ASM儲存表空間TTS單例ASM
- oracle 傳輸表空間一例Oracle
- Oracle可傳輸表空間測試Oracle
- 5.7 mysql的可傳輸表空間MySql
- 表空間傳輸讀書筆記筆記
- 『Android』 獲取檔案系統剩餘空間Android
- 【TABLESPACE】通過重建控制檔案調整表空間資料檔案位置及名稱
- 大檔案表空間
- 移動資料檔案、系統表空間檔案、臨時表空間檔案
- 【XTTS】Oracle傳輸表空間xtts增量方式TTSOracle
- 傳輸表空間(從Linux到Windows)LinuxWindows
- oracle可傳輸表空間TTS小結OracleTTS
- 傳輸表空間及問題處理