使用RMAN实现可传输的表空间

使用可传输的表空间,在拷贝数据文件时,需要将数据文件设置为只读,这对于24小时的系统来说,这是不可能的
使用RMAN,可以在不对主库造成任何影响的情况下,实现可传输的表空间。

该方法主要是通过建立一个auxiliary实例,进行一个TSPITR,然后在auxiliary上将表空间导出
参见:455593.1

rman target /   --源库

-------------------------------------------------------------------------

RMAN> run {
2> transport tablespace "TEST"
3> Tablespace destination '/oracle/oradata/AUX/tts'
4> Auxiliary destination '/oracle/oradata/AUX/tts'
5> Datapump directory data_pump_dir
6> dump file 'tts_test.dmp'
7> Import script. 'tts_test.imp'
8> Export log 'exp_tts_test.log'
9> UNTIL TIME "to_date('23 4 2009 12:00:00','DD MM YYYY hh24:mi:ss')";
10> }

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='zfnl'

initialization parameters used for automatic instance:
db_name=LOGMINER
compatible=10.2.0.1.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_LOGMINER_zfnl
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/oracle/oradata/AUX/tts
control_files=/oracle/oradata/AUX/tts/cntrl_tspitr_LOGMINER_zfnl.f


starting up automatic instance LOGMINER

Oracle instance started

Total System Global Area     201326592 bytes

Fixed Size                     1266584 bytes
Variable Size                146803816 bytes
Database Buffers              50331648 bytes
Redo Buffers                   2924544 bytes
Automatic instance created

contents of Memory Script.:
{
# set the until clause
set until  time "to_date('23 4 2009 12:00:00','DD MM YYYY hh24:mi:ss')";
# 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 23-APR-09
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 /oracle/flash_recovery_area/LOGMINER/autobackup/2009_04_07/o1_mf_s_683550244_4xojo530_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/oracle/flash_recovery_area/LOGMINER/autobackup/2009_04_07/o1_mf_s_683550244_4xojo530_.bkp tag=TAG20090407T110404
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/oracle/oradata/AUX/tts/cntrl_tspitr_LOGMINER_zfnl.f
Finished restore at 23-APR-09

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_AUX_DISK_1

contents of Memory Script.:
{
# generated tablespace point-in-time recovery script
# set the until clause
set until  time "to_date('23 4 2009 12:00:00','DD MM YYYY hh24:mi:ss')";
# 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
 "/oracle/oradata/AUX/tts/TEST.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  "TEST", "SYSTEM", "UNDOTBS1", "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 /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_temp_%u_.tmp in control file

Starting restore at 23-APR-09
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=40 devtype=DISK

channel ORA_AUX_DISK_1: restoring datafile 00005
input datafile copy recid=21 stamp=683548647 filename=/tmp/tmp.dbf
destination for restore of datafile 00005: /oracle/oradata/AUX/tts/TEST.dbf
channel ORA_AUX_DISK_1: copied datafile copy of datafile 00005
output filename=/oracle/oradata/AUX/tts/TEST.dbf recid=23 stamp=684936468
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 /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00003 to /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/flash_recovery_area/LOGMINER/backupset/2009_04_06/o1_mf_nnndf_TAG20090406T194141_4xmtmppl_.bkp
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/oracle/flash_recovery_area/LOGMINER/backupset/2009_04_06/o1_mf_nnndf_TAG20090406T194141_4xmtmppl_.bkp tag=TAG20090406T194141
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 23-APR-09

datafile 1 switched to datafile copy
input datafile copy recid=27 stamp=684936524 filename=/oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_system_4yztdop2_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=28 stamp=684936524 filename=/oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_undotbs1_4yztdosb_.dbf
datafile 3 switched to datafile copy
input datafile copy recid=29 stamp=684936524 filename=/oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_sysaux_4yztdowk_.dbf
datafile 5 switched to datafile copy
input datafile copy recid=30 stamp=684936524 filename=/oracle/oradata/AUX/tts/TEST.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 23-APR-09
using channel ORA_AUX_DISK_1

starting media recovery

archive log thread 1 sequence 5 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_06/o1_mf_1_5_4xmzz10j_.arc
archive log thread 1 sequence 6 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_07/o1_mf_1_6_4xog7ds3_.arc
archive log thread 1 sequence 7 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_7_4xv9swlt_.arc
archive log thread 1 sequence 8 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_8_4xvb45hn_.arc
archive log thread 1 sequence 9 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_9_4xvb4t37_.arc
archive log thread 1 sequence 10 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_10_4xvb58b5_.arc
archive log thread 1 sequence 11 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_11_4xvb5qlt_.arc
archive log thread 1 sequence 12 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_23/o1_mf_1_12_4yzqvjhs_.arc
archive log thread 1 sequence 13 is already on disk as file /oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_23/o1_mf_1_13_4yztdk93_.arc
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_06/o1_mf_1_5_4xmzz10j_.arc thread=1 sequence=5
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_07/o1_mf_1_6_4xog7ds3_.arc thread=1 sequence=6
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_7_4xv9swlt_.arc thread=1 sequence=7
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_8_4xvb45hn_.arc thread=1 sequence=8
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_9_4xvb4t37_.arc thread=1 sequence=9
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_10_4xvb58b5_.arc thread=1 sequence=10
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_09/o1_mf_1_11_4xvb5qlt_.arc thread=1 sequence=11
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_23/o1_mf_1_12_4yzqvjhs_.arc thread=1 sequence=12
archive log filename=/oracle/flash_recovery_area/LOGMINER/archivelog/2009_04_23/o1_mf_1_13_4yztdk93_.arc thread=1 sequence=13
media recovery complete, elapsed time: 00:01:40
Finished recover at 23-APR-09

database opened

contents of Memory Script.:
{
#mark read only the tablespace that will be exported
sql clone "alter tablespace TEST read only";
# export the tablespaces in the recovery set
host 'expdp userid=\"
/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/oracle/product/10.2.0/bin/oracle\)\(ARGV0=oraclezfnl\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=zfnl^'\)\)\(CONNECT_DATA=\(SID=zfnl\)\)\) as sysdba\" transport_tablespaces=
 TEST dumpfile=
tts_test.dmp directory=
data_pump_dir logfile=
exp_tts_test.log';
}
executing Memory Script

sql statement: alter tablespace TEST read only


Export: Release 10.2.0.4.0 - Production on Thursday, 23 April, 2009 12:11:08

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TRANSPORTABLE_01":  userid="
/********@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=/oracle/product/10.2.0/bin/oracle)(ARGV0=oraclezfnl)(ARGS=\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\))(ENVS=ORACLE_SID=zfnl))(CONNECT_DATA=(SID=zfnl))) AS SYSDBA" transport_tablespaces= TEST dumpfile=tts_test.dmp directory=data_pump_dir logfile=exp_tts_test.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
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:
  /oracle/oradata/AUX/tts_test.dmp
Job "SYS"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 12:11:38

host command complete
/*
   The following command may be used to import the tablespaces.
   Substitute values for and .
   impdp directory= dumpfile= 'tts_test.dmp' transport_datafiles= /oracle/oradata/AUX/tts/TEST.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script. for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/oracle/oradata/AUX/tts/';
/* 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 :=  'tts_test.dmp';
  dump_file.directory_object := 'data_pump_dir';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'TEST.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;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

Removing automatic instance
shutting down automatic instance
Oracle instance shut down
Automatic instance removed
auxiliary instance file /oracle/oradata/AUX/tts/cntrl_tspitr_LOGMINER_zfnl.f deleted
auxiliary instance file /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_system_4yztdop2_.dbf deleted
auxiliary instance file /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_undotbs1_4yztdosb_.dbf deleted
auxiliary instance file /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_sysaux_4yztdowk_.dbf deleted
auxiliary instance file /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/datafile/o1_mf_temp_4yztl12v_.tmp deleted
auxiliary instance file /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/onlinelog/o1_mf_1_4yztknnm_.log deleted
auxiliary instance file /oracle/oradata/AUX/tts/TSPITR_LOGMINER_ZFNL/onlinelog/o1_mf_3_4yztkpvg_.log deleted

-------------------------------------------------------------------------

[oracle@RMAN AUX]$ pwd
/oracle/oradata/AUX
[oracle@RMAN AUX]$ ls -l
total 104
-rw-r--r--  1 oracle dba  1361 Apr 23 12:11 exp_tts_test.log           --expdp的日志
drwxr-xr-x  3 oracle dba  4096 Apr 23 12:11 tts
-rw-r-----  1 oracle dba 81920 Apr 23 12:11 tts_test.dmp               --expdp的导出文件
[oracle@RMAN AUX]$ cd tts
[oracle@RMAN tts]$ ls -l
total 272748
-rw-r-----  1 oracle dba 278994944 Apr 23 12:11 TEST.dbf               --导出的表空间的数据文件
drwxr-x---  4 oracle dba      4096 Apr 23 12:07 TSPITR_LOGMINER_ZFNL   --在操作时临时创建的系统表空间,日志文件。操作完成后自动删除
-rw-r--r--  1 oracle dba      1959 Apr 23 12:11 tts_test.imp           --导入时使用的脚本
[oracle@RMAN tts]$ cat tts_test.imp
/*
   The following command may be used to import the tablespaces.
   Substitute values for and .
   impdp directory= dumpfile= 'tts_test.dmp' transport_datafiles= /oracle/oradata/AUX/tts/TEST.dbf
*/
--------------------------------------------------------------
-- Start of sample PL/SQL script. for importing the tablespaces
--------------------------------------------------------------
-- creating directory objects
CREATE DIRECTORY STREAMS$DIROBJ$1 AS  '/oracle/oradata/AUX/tts/';
/* 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 :=  'tts_test.dmp';
  dump_file.directory_object := 'data_pump_dir';
  -- forming list of datafiles for import
  tbs_files( 1).file_name :=  'TEST.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;
--------------------------------------------------------------
-- End of sample PL/SQL script
--------------------------------------------------------------

可用impdp或者脚本来导入表空间到其他数据库去

 

 

 

 


 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8242091/viewspace-591532/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8242091/viewspace-591532/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值