使用Oracle可傳輸表空間的特性複製資料(7)實戰RMAN備份傳輸表空間

junsansi發表於2008-01-15

一、檢查平臺是否支援

跳過(如有不明請詳見第三節示例)

二、檢查待傳輸表空間是否自包含

跳過(如有不明請詳見第三節示例)

三、檢查備份

跳過(如有不明請詳見"一步一步學RMAN"系列)

四、生成可傳輸集

E:\oracleScript\backup>set oracle_sid=jssweb

E:\oracleScript\backup>rman target /

連線到目標資料庫: JSSWEB (DBID=3402005373)

RMAN> transport tablespace jssweb

2> tablespace destination 'd:\backup\td'

3> auxiliary destination 'd:\backup\ad'

4> ;

看,不需要太複雜,就是這麼簡單。

使用目標資料庫控制檔案替代恢復目錄

RMAN-05026: 警告: 假定以下表空間集適用於指定的時間點

表空間列表要求具有 UNDO 段

表空間 SYSTEM

表空間 UNDOTBS1

使用 SID='gEDa' 建立自動例項

供自動例項使用的初始化引數:

db_name=JSSWEB

compatible=10.2.0.1.0

db_block_size=8192

db_files=200

db_unique_name=tspitr_JSSWEB_gEDa

large_pool_size=1M

shared_pool_size=110M

#No auxiliary parameter file used

db_create_file_dest=d:\backup\ad

control_files=d:\backup\ad/cntrl_tspitr_JSSWEB_gEDa.f

啟動自動例項 JSSWEB

...

...

記憶體指令碼的內容:

{

# set the until clause

set until  scn 1672677;

# 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;';

}

正在執行記憶體指令碼

正在執行命令: SET until clause

..

...

sql 語句: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;

釋放的通道: ORA_AUX_DISK_1

記憶體指令碼的內容:

{

# generated tablespace point-in-time recovery script

# set the until clause

set until  scn 1672677;

# set an omf destination filename for restore

set newname for clone datafile  1 to new;

...

...

# make the controlfile point at the restored datafiles, then recover them

recover clone database tablespace  "JSSWEB", "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";

}

正在執行記憶體指令碼

正在執行命令: SET until clause

正在執行命令: SET NEWNAME

...

...

介質恢復完成, 用時: 00:00:10

完成 recover 於 19-11月-07

資料庫已開啟

記憶體指令碼的內容:

{

#mark read only the tablespace that will be exported

sql clone "alter tablespace JSSWEB read only";

# create directory for datapump export

sql clone "create or replace directory STREAMS_DIROBJ_DPDIR as ''

d:\backup\td''";

# export the tablespaces in the recovery set

host 'expdp userid=\"/@(DESCRIPTION=(ADDRESS=(PROTOCOL=beq)(PROGRAM=oracle)(ARGV0=oraclegEDa)(ARGS=^

'(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))^')(ENVS=^'ORACLE_SID=gEDa^'))(CONNECT_DATA=(SID=g

EDa))) as sysdba\" transport_tablespaces=

 JSSWEB dumpfile=

dmpfile.dmp directory=

STREAMS_DIROBJ_DPDIR logfile=

explog.log';

}

正在執行記憶體指令碼

sql 語句: alter tablespace JSSWEB read only

...

...

主機命令完成

/*

   The following command may be used to import the tablespaces.

   Substitute values for  and .

   impdp  directory= dumpfile= 'dmpfile.dmp' transport_datafiles= d:\backup\td\JSS

WEB.DBF

*/

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

-- Start of sample PL/SQL script for importing the tablespaces

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

-- creating directory objects

CREATE DIRECTORY STREAMS$DIROBJ$1 AS  'd:\backup\td\';

...

...

DROP DIRECTORY STREAMS$DIROBJ$DPDIR;

刪除自動例項

關閉自動例項

Oracle 例項已關閉

自動例項已刪除

已刪除輔助例項檔案 D:\backup\ad\CNTRL_TSPITR_JSSWEB_GEDA.F

已刪除輔助例項檔案 D:\backup\ad\TSPITR_J\DATAFILE\O1_MF_SYSAUX_3N2GF31G_.DBF

已刪除輔助例項檔案 D:\backup\ad\TSPITR_J\DATAFILE\O1_MF_SYSTEM_3N2GF2YR_.DBF

已刪除輔助例項檔案 D:\backup\ad\TSPITR_J\DATAFILE\O1_MF_TEMP_3N2GH1H4_.TMP

已刪除輔助例項檔案 D:\backup\ad\TSPITR_J\DATAFILE\O1_MF_UNDOTBS1_3N2GF30H_.DBF

已刪除輔助例項檔案 D:\backup\ad\TSPITR_J\ONLINELOG\O1_MF_1_3N2GGXJM_.LOG

已刪除輔助例項檔案 D:\backup\ad\TSPITR_J\ONLINELOG\O1_MF_2_3N2GGY0Z_.LOG

已刪除輔助例項檔案 D:\backup\ad\TSPITR_J\ONLINELOG\O1_MF_3_3N2GGYNZ_.LOG

執行成功,檔案被生成在tablespace destination引數指定路徑下。

五、複製檔案到目標平臺

方式方法太多,沒啥技術含量,跳過。

六、執行匯入指令碼

注意,匯入表空間在源平臺所屬的使用者必須存在,另外一旦複製到目標庫後檔案路徑如果發生變化,一定要修改impscript.sql檔案中相應的路徑。

[oracle@jsslinux ~]$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 11月 20 10:45:53 2007

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

連線到: 

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> @/opt/oratmp/oradata/impscript.sql

目錄已建立。

目錄已建立。

PL/SQL 過程已成功完成。

目錄已刪除。

目錄已刪除。

SQL> 

自古華山一條路,但這不是華山,這是匯入後設資料,除了用指令碼匯入之外,你還可以直接通過impdp命令匯入(實際dbms_streams_tablespace_adm.attach_tablespaces函式就是呼叫的impdp),例如:

[oracle@jsslinux dpdump]$ impdp system/verysafe DUMPFILE=dmpfile.dmp DIRECTORY=DATA_PUMP_DIR TRANSPORT_DATAFILES=/opt/oratmp/oradata/JSSWEB.DBF

Import: Release 10.2.0.1.0 - Production on 星期一, 19 11月, 2007 19:13:21

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

連線到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

已成功載入/解除安裝了主表 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" 

啟動 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/******** DUMPFILE=dmpfile.dmp DIRECTORY=DATA_PUMP_DIR TRANSPORT_DATAFILES=/opt/oratmp/oradata/JSSWEB.DBF REMAP_SCHEMA=(jss:jss) 

處理物件型別 TRANSPORTABLE_EXPORT/PLUGTS_BLK

處理物件型別 TRANSPORTABLE_EXPORT/TABLE

處理物件型別 TRANSPORTABLE_EXPORT/TABLE_STATISTICS

處理物件型別 TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK

作業 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" 已於 19:13:26 成功完成

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7607759/viewspace-145404/,如需轉載,請註明出處,否則將追究法律責任。

相關文章