1. 程式人生 > >使用資料泵單獨匯出dblink

使用資料泵單獨匯出dblink

最新需要單獨匯出dblink,之前發現通過create database link建立的dblink,通過schema可以匯出

通過create public database link 語句建立的dblink,通過schema沒法匯出,通過加上full=y,匯出元資料可以匯出dblink

。但是這樣會把sys下的其他的元資料也匯出來。再匯入的時候,會有告警。

今天研究了下,可以使用一下的語句匯出匯入。

expdp "'/ as sysdba'" directory=DIR dumpfile=dblink.dmp include=db_link full=y

匯出的過程如下:

C:\Users\Administrator>expdp "'/ as sysdba'" directory=DIR dumpfile=dblink.dmp i
nclude=db_link full=y

Export: Release 11.2.0.1.0 - Production on 星期二 10月 16 01:23:49 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

連線到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Produc
tion
With the Partitioning, OLAP, Data Mining and Real Application Testing options
自動啟用 FLASHBACK 以保持資料庫完整性。
啟動 "SYS"."SYS_EXPORT_FULL_01":  "/******** AS SYSDBA" directory=DIR dumpfile=d
blink.dmp include=db_link full=y
正在使用 BLOCKS 方法進行估計...
處理物件型別 DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
使用 BLOCKS 方法的總估計: 0 KB
處理物件型別 DATABASE_EXPORT/SCHEMA/DB_LINK
已成功載入/解除安裝了主表 "SYS"."SYS_EXPORT_FULL_01"
******************************************************************************
SYS.SYS_EXPORT_FULL_01 的轉儲檔案集為:
  D:\DUMP\DBLINK.DMP
作業 "SYS"."SYS_EXPORT_FULL_01" 已於 01:23:52 成功完成

檢視匯出的sql語句

impdp "'/ as sysdba'" directory=DIR dumpfile=dblink.dmp sqlfile=dblink.sql


-- 匯出過程
C:\Users\Administrator>impdp "'/ as sysdba'" directory=DIR dumpfile=dblink.dmp s
qlfile=dblink.sql

Import: Release 11.2.0.1.0 - Production on 星期二 10月 16 01:26:57 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

連線到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Produc
tion
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功載入/解除安裝了主表 "SYS"."SYS_SQL_FILE_FULL_01"
啟動 "SYS"."SYS_SQL_FILE_FULL_01":  "/******** AS SYSDBA" directory=DIR dumpfile
=dblink.dmp sqlfile=dblink.sql
處理物件型別 DATABASE_EXPORT/SCHEMA/DB_LINK
作業 "SYS"."SYS_SQL_FILE_FULL_01" 已於 01:26:59 成功完成
-- CONNECT SYS
ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
-- new object type path: DATABASE_EXPORT/SCHEMA/DB_LINK
CREATE PUBLIC DATABASE LINK "131"
   CONNECT TO "APPS" IDENTIFIED BY VALUES '05248D0BE733DEF84B94DC1B8C76933140'
   USING 'XXXX_rac';
 
CREATE PUBLIC DATABASE LINK "XXXX_131"
   CONNECT TO "APPS" IDENTIFIED BY VALUES '05937694247596309877ED0DD024218509'
   USING '(DESCRIPTION =  
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.XXX.XXX)(PORT = 1521))
  )
  (CONNECT_DATA =
    (SERVICE_NAME = XXX)
  )
)';
 
CREATE PUBLIC DATABASE LINK "XXX_87"
   CONNECT TO "SYSTEM" IDENTIFIED BY VALUES '051DA4C75897EB22BBB5BB5F07D6843CCA'
   USING '
(DESCRIPTION=
    (ADDRESS=
      (PROTOCOL=TCP)
      (HOST=192.168.101.XXX)
      (PORT=1521)
    )
    (CONNECT_DATA=
      (SERVICE_NAME=orcl)
    )
  )
';
 
-- CONNECT STREAMADMIN
CREATE DATABASE LINK "XXXX"
   CONNECT TO "STREAMADMIN" IDENTIFIED BY VALUES '05A0435B49CF8F0AAFF50A39916689D7E3'
   USING 'XXXX';

-- 匯入 。 這裡有一個錯誤,原因是有個dblink的schema是其他的,剛好這個使用者沒有在資料庫中建立。

D:\app\test\product\11.2.0\dbhome_1\BIN>impdp "'/ as sysdba'" directory=dump dumpfile=DBLINK.DMP logfile=impdblink.log

Import: Release 11.2.0.4.0 - Production on 星期二 10月 16 09:48:09 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

連線到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功載入/解除安裝了主表 "SYS"."SYS_IMPORT_FULL_01"
啟動 "SYS"."SYS_IMPORT_FULL_01":  "/******** AS SYSDBA" directory=dump dumpfile=DBLINK.DMP logfile=impdblink.log
處理物件型別 DATABASE_EXPORT/SCHEMA/DB_LINK
ORA-39083: 物件型別 DB_LINK 建立失敗, 出現錯誤:
ORA-31625: 必須有方案 STREAMADMIN 才能匯入此物件, 但此方案不可訪問
ORA-01435: 使用者不存在
失敗的 sql 為:
CREATE DATABASE LINK "XXXX"  CONNECT TO "STREAMADMIN" IDENTIFIED BY VALUES ':1'  USING 'XXXX'

作業 "SYS"."SYS_IMPORT_FULL_01" 已經完成, 但是有 1 個錯誤 (於 星期二 10月 16 09:48:35 2018 elapsed 0 00:00:17 完成)

-- 檢視DBLINK 。dblink已經匯入 。

[email protected]>select owner,db_link from dba_db_links;

OWNER      DB_LINK
---------- --------------------
PUBLIC     131
PUBLIC     XXX_131
PUBLIC     XXX_87
PUBLIC     DBMS_CLRDBLINK
PUBLIC     TO_NOCDB
DLINKUSER  NO_PUB_DLINK

已選擇6行。

[email protected]>

END。