1. 程式人生 > >oracle服務端導出/導入方式expdp/impdp

oracle服務端導出/導入方式expdp/impdp

ola schema ons oracle服務 task 條件 ... related ack

1. expdp導出步驟

1.1 用sys管理員登錄sqlplus

技術分享圖片
[root@hxjk_test_mysql_redis_file oracle]# sqlplus

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 21 21:49:35 2018

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

Enter user-name: orcl
Enter password: 

Connected to:
Oracle Database 11g Enterprise Edition Release 
11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
View Code

創建邏輯目錄;

技術分享圖片
SQL> create directory BACKDIR as /opt/oracle/oradata/orcl/;

Directory created.
View Code

查看

技術分享圖片
SQL> select * from dba_directories;

OWNER                   DIRECTORY_NAME
------------------------------ ------------------------------ DIRECTORY_PATH -------------------------------------------------------------------------------- SYS XMLDIR /ade/b/2125410156/oracle/rdbms/xml SYS BACKDIR /opt/oracle/oradata/orcl/ SYS DATA_PUMP_DIR
/opt/oracle/admin/orcl/dpdump/ OWNER DIRECTORY_NAME ------------------------------ ------------------------------ DIRECTORY_PATH -------------------------------------------------------------------------------- SYS ORACLE_OCM_CONFIG_DIR /opt/oracle/product/11.2.0/db_1/ccr/state
View Code

1.2 用expdp導出dmp,有五種導出方式:

第一種:“full=y”,全量導出數據庫;

expdp carloan/[email protected]:1521/orcl dumpfile=carloan_20181121.dmp directory=backdir full=y logfile=carloan_20181121.log;

carloan_20181121.log日誌文件內容如下,會導出整個庫內所有的表空間:

技術分享圖片
;;; 
Export: Release 11.2.0.1.0 - Production on Wed Nov 21 21:35:44 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
;;; 
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "CARLOAN"."SYS_EXPORT_FULL_01":  carloan/********@192.168.40.64:1521/orcl dumpfile=carloan_20181121.dmp directory=backdir full=y logfile=carloan_20181121.log 
Estimate in progress using BLOCKS method...
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 592.4 MB
Processing object type DATABASE_EXPORT/TABLESPACE
Processing object type DATABASE_EXPORT/PROFILE
Processing object type DATABASE_EXPORT/SYS_USER/USER
Processing object type DATABASE_EXPORT/SCHEMA/USER
Processing object type DATABASE_EXPORT/ROLE
Processing object type DATABASE_EXPORT/GRANT/SYSTEM_GRANT/PROC_SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/GRANT/SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/ROLE_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/DEFAULT_ROLE
Processing object type DATABASE_EXPORT/SCHEMA/TABLESPACE_QUOTA
Processing object type DATABASE_EXPORT/RESOURCE_COST
Processing object type DATABASE_EXPORT/TRUSTED_DB_LINK
Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/SEQUENCE
Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/DIRECTORY/DIRECTORY
Processing object type DATABASE_EXPORT/DIRECTORY/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/CONTEXT
Processing object type DATABASE_EXPORT/SCHEMA/PUBLIC_SYNONYM/SYNONYM
Processing object type DATABASE_EXPORT/SCHEMA/SYNONYM
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/TYPE_SPEC
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/PRE_SYSTEM_ACTIONS/PROCACT_SYSTEM
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/PROCOBJ
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/POST_SYSTEM_ACTIONS/PROCACT_SYSTEM
Processing object type DATABASE_EXPORT/SCHEMA/PROCACT_SCHEMA
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/PRE_TABLE_ACTION
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/INDEX
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/CONSTRAINT/CONSTRAINT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/COMMENT
Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE/PACKAGE_SPEC
Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/FUNCTION
Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/PROCEDURE
Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/ALTER_FUNCTION
Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/ALTER_PROCEDURE
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/VIEW
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/COMMENT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE_BODIES/PACKAGE/PACKAGE_BODY
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/TYPE_BODY
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/POST_TABLE_ACTION
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TRIGGER
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/TRIGGER
Processing object type DATABASE_EXPORT/SCHEMA/EVENT/TRIGGER
Processing object type DATABASE_EXPORT/SCHEMA/MATERIALIZED_VIEW
Processing object type DATABASE_EXPORT/SCHEMA/JOB
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/POST_INSTANCE/PROCACT_INSTANCE
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/POST_INSTANCE/PROCDEPOBJ
Processing object type DATABASE_EXPORT/SCHEMA/POST_SCHEMA/PROCOBJ
Processing object type DATABASE_EXPORT/SCHEMA/POST_SCHEMA/PROCACT_SCHEMA
Processing object type DATABASE_EXPORT/AUDIT
. . exported "ORCL"."MA_ASSET_RELATED_DETAIL"            104.7 MB 2743778 rows
. . exported "MA_HXPH0709"."MA_ASSET_RELATED_DETAIL"     52.51 MB 1375642 rows
. . exported "CARLOAN"."BASE_CITYS"                      39.89 MB  713987 rows

……

Master table "CARLOAN"."SYS_EXPORT_FULL_01" successfully loaded/unloaded
******************************************************************************
Dump file set for CARLOAN.SYS_EXPORT_FULL_01 is:
  /opt/oracle/oradata/orcl/carloan_20181121.dmp
Job "CARLOAN"."SYS_EXPORT_FULL_01" successfully completed at 21:41:11
View Code

第二種:schemas按用戶導出;

expdp carloan/[email protected]:1521/orcl schemas=carloan dumpfile=carloan_20181121_2.dmp directory=backdir logfile=carloan_20181121_2.log;

carloan_20181121_2.log,會導出用戶carloan默認表空間carloan的數據。

技術分享圖片
;;; 
Export: Release 11.2.0.1.0 - Production on Wed Nov 21 21:48:17 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
;;; 
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "CARLOAN"."SYS_EXPORT_SCHEMA_01":  carloan/********@192.168.40.64:1521/orcl schemas=carloan dumpfile=carloan_20181121_2.dmp directory=backdir logfile=carloan_20181121_2.log 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 63.06 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/FUNCTION/FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/FUNCTION/ALTER_FUNCTION
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/JOB
. . exported "CARLOAN"."BASE_CITYS"                      39.89 MB  713987 rows
. . exported "CARLOAN"."ACT_EVT_LOG"                     2.036 MB    5590 rows
. . exported "CARLOAN"."BASE_CARS"                       1.758 MB   24488 rows
. . exported "CARLOAN"."MSG_INTERFACE_LOG"               1.851 MB    1869 rows
. . exported "CARLOAN"."BASE_CAR_TYPE"                   1.224 MB   12244 rows
. . exported "CARLOAN"."ACT_HI_ACTINST"                  112.1 KB     833 rows
. . exported "CARLOAN"."ACT_HI_COMMENT"                  49.88 KB     643 rows

……

Master table "CARLOAN"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for CARLOAN.SYS_EXPORT_SCHEMA_01 is:
  /opt/oracle/oradata/orcl/carloan_20181121_2.dmp
Job "CARLOAN"."SYS_EXPORT_SCHEMA_01" successfully completed at 21:48:50
View Code

第三種:按表空間導出;

expdp carloan/[email protected]:1521/orcl TABLESPACES=carloan dumpfile=carloan_20181121_3.dmp directory=backdir logfile=carloan_20181121_3.log;

carloan_20181121_3.log內容如下:

技術分享圖片
;;; 
Export: Release 11.2.0.1.0 - Production on Wed Nov 21 22:08:43 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
;;; 
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "CARLOAN"."SYS_EXPORT_TABLESPACE_01":  carloan/********@192.168.40.64:1521/orcl TABLESPACES=carloan dumpfile=carloan_20181121_3.dmp directory=backdir logfile=carloan_20181121_3.log 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 63.06 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/COMMENT
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "CARLOAN"."BASE_CITYS"                      39.89 MB  713987 rows
. . exported "CARLOAN"."ACT_EVT_LOG"                     2.036 MB    5590 rows
. . exported "CARLOAN"."BASE_CARS"                       1.758 MB   24488 rows
. . exported "CARLOAN"."MSG_INTERFACE_LOG"               1.851 MB    1869 rows

……

Master table "CARLOAN"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for CARLOAN.SYS_EXPORT_TABLESPACE_01 is:
  /opt/oracle/oradata/orcl/carloan_20181121_3.dmp
Job "CARLOAN"."SYS_EXPORT_TABLESPACE_01" successfully completed at 22:09:05
View Code

第四種:導出表;

expdp carloan/[email protected]:1521/orcl TABLES=ACT_RU_TASK dumpfile=carloan_20181121_4.dmp directory=backdir logfile=carloan_20181121_4.log;

第五種:按查詢條件導;

2.impdp導入步驟

如果不是同一臺服務器,需要先將上面的dmp文件下載到目標服務器上,建立邏輯目錄,放入邏輯目錄下

用impdp命令導入,下面介紹兩種

第一種同名用戶導入,從用戶A導入到用戶A;

impdp carloan/[email protected]:1521/orcl directory=backdir dumpfile=‘carloan_20181113144951.dmp‘ schemas=carlo

第二種. 從carloan用戶中把表ACT_GE_BYTEARRAY 導入到carloan2用戶中;

impdp carloan2/[email protected]:1521/orcl tables=carloan.ACT_GE_BYTEARRAY remap_schema=carloan:carloan2 directory=backdir dumpfile=carloan_20181113144951.dmp;

oracle服務端導出/導入方式expdp/impdp