ä¸ãå建é»è¾ç®å½ï¼è¯¥å½ä»¤ä¸ä¼å¨æä½ç³»ç»å建çæ£çç®å½ï¼æ好以
system
ç管çåå建ã
create directory dpdata1 as 'd:\test\dump';
äºãæ¥ç管ççåç®å½ï¼åæ¶æ¥çæä½ç³»ç»æ¯å¦åå¨ï¼å 为
Oracle
并ä¸å
³å¿è¯¥ç®å½æ¯å¦åå¨ï¼å¦æä¸åå¨ï¼ååºéï¼
select * from dba_directories;
ä¸ãç»
scott
ç¨æ·èµäºå¨æå®ç®å½çæä½æéï¼æ好以
system
ç管çåèµäºã
grant read,write on directory dpdata1 to scott;
åã导åºæ°æ®
1)
æç¨æ·å¯¼
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=dpdata1;
2)
并è¡è¿ç¨
parallel
expdp scott/tiger@orcl directory=dpdata1 dumpfile=scott3.dmp parallel=40 job_name=scott3
3)
æ表å导
expdp scott/tiger@orcl TABLES=emp,dept dumpfile=expdp.dmp DIRECTORY=dpdata1;
4)
ææ¥è¯¢æ¡ä»¶å¯¼
expdp scott/tiger@orcl directory=dpdata1 dumpfile=expdp.dmp Tables=emp query='WHERE deptno=20';
5)
æ表空é´å¯¼
expdp system/manager DIRECTORY=dpdata1 DUMPFILE=tablespace.dmp TABLESPACES=temp,example;
6)
导æ´ä¸ªæ°æ®åº
expdp system/manager DIRECTORY=dpdata1 DUMPFILE=full.dmp FULL=y;
äºãè¿åæ°æ®
1)
导å°æå®ç¨æ·ä¸
impdp scott/tiger DIRECTORY=dpdata1 DUMPFILE=expdp.dmp SCHEMAS=scott;
2)
æ¹å表ç
owner
impdp system/manager DIRECTORY=dpdata1 DUMPFILE=expdp.dmp TABLES=scott.dept REMAP_SCHEMA=scott:system;
3)
导å
¥è¡¨ç©ºé´
impdp system/manager DIRECTORY=dpdata1 DUMPFILE=tablespace.dmp TABLESPACES=example;
4)
导å
¥æ°æ®åº
impdb system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y;
5)
追å æ°æ®
impdp system/manager DIRECTORY=dpdata1 DUMPFILE=expdp.dmp SCHEMAS=system TABLE_EXISTS_ACTION=append;
----------------------------Expdp/Impdp
çç¸å
³åæ°
----------------------------
EXPDP
å½ä»¤è¡é项
1. ATTACH
该é项ç¨äºå¨å®¢æ·ä¼è¯ä¸å·²åå¨å¯¼åºä½ç¨ä¹é´å»ºç«å
³è
.
è¯æ³å¦ä¸
ATTACH=[schema_name.]job_name
Schema_name
ç¨äºæå®æ¹æ¡å
,job_name
ç¨äºæå®å¯¼åºä½ä¸å
.
注æ
,
å¦æ使ç¨
ATTACH
é项
,
å¨å½ä»¤è¡é¤äºè¿æ¥å符串å
ATTACH
é项å¤
,
ä¸è½æå®ä»»ä½å
¶ä»é项
,
示ä¾å¦ä¸
:
Expdp scott/tiger ATTACH=scott.export_job
2. CONTENT
该é项ç¨äºæå®è¦å¯¼åºçå
容
.
é»è®¤å¼ä¸º
ALL
CONTENT={ALLÂ |Â DATA_ONLYÂ |Â METADATA_ONLY}
å½è®¾ç½®
CONTENT
为
ALL
æ¶
,
å°å¯¼åºå¯¹è±¡å®ä¹åå
¶æææ°æ®
.
为
DATA_ONLY
æ¶
,
åªå¯¼åºå¯¹è±¡æ°æ®
,
为
METADATA_ONLY
æ¶
,
åªå¯¼åºå¯¹è±¡å®ä¹
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dump
CONTENT=METADATA_ONLY
3. DIRECTORY
æå®è½¬å¨æ件åæ¥å¿æ件æå¨çç®å½
DIRECTORY=directory_object
Directory_object
ç¨äºæå®ç®å½å¯¹è±¡å称
.
éè¦æ³¨æ
,
ç®å½å¯¹è±¡æ¯ä½¿ç¨
CREATEÂ DIRECTORY
è¯å¥å»ºç«ç对象
,
èä¸æ¯
OS
ç®å½
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dump
建ç«ç®å½
:
CREATE DIRECTORY dump as âd:dumpâ;
æ¥è¯¢å建äºé£äºåç®å½
:
SELECTÂ *Â FROMÂ dba_directories;
4. DUMPFILE
ç¨äºæå®è½¬å¨æ件çå称
,
é»è®¤å称为
expdat.dmp
DUMPFILE=[directory_object:]file_name [,â¦.]
Directory_object
ç¨äºæå®ç®å½å¯¹è±¡å
,file_name
ç¨äºæå®è½¬å¨æ件å
.
éè¦æ³¨æ
,
å¦æä¸æå®
directory_object,
导åºå·¥å
·ä¼èªå¨ä½¿ç¨
DIRECTORY
é项æå®çç®å½å¯¹è±¡
Expdp scott/tiger DIRECTORY=dump1 DUMPFILE=dump2:a.dmp
5. ESTIMATE
æå®ä¼°ç®è¢«å¯¼åºè¡¨æå ç¨ç£ç空é´åæ¹æ³
.
é»è®¤å¼æ¯
BLOCKS
EXTIMATE={BLOCKSÂ |Â STATISTICS}
设置为
BLOCKS
æ¶
,oracle
ä¼æç
§ç®æ 对象æå ç¨çæ°æ®å个æ°ä¹ä»¥æ°æ®å尺寸估ç®å¯¹è±¡å ç¨ç空é´
,
设置为
STATISTICS
æ¶
,
æ ¹æ®æè¿ç»è®¡å¼ä¼°ç®å¯¹è±¡å ç¨ç©ºé´
Expdp scott/tiger TABLES=emp ESTIMATE=STATISTICS
DIRECTORY=dump DUMPFILE=a.dump
6. EXTIMATE_ONLY
æå®æ¯å¦åªä¼°ç®å¯¼åºä½ä¸æå ç¨çç£ç空é´
,
é»è®¤å¼ä¸º
N
EXTIMATE_ONLY={YÂ |Â N}
设置为
Y
æ¶
,
导åºä½ç¨åªä¼°ç®å¯¹è±¡æå ç¨çç£ç空é´
,
èä¸ä¼æ§è¡å¯¼åºä½ä¸
,
为
N
æ¶
,
ä¸ä»
ä¼°ç®å¯¹è±¡æå ç¨çç£ç空é´
,
è¿ä¼æ§è¡å¯¼åºæä½
.
Expdp scott/tiger ESTIMATE_ONLY=y NOLOGFILE=y
7. EXCLUDE
该é项ç¨äºæå®æ§è¡æä½æ¶éæ¾è¦æé¤å¯¹è±¡ç±»åæç¸å
³å¯¹è±¡
EXCLUDE=object_type[:name_clause] [,â¦.]
Object_type
ç¨äºæå®è¦æé¤ç对象类å
,name_clause
ç¨äºæå®è¦æé¤çå
·ä½å¯¹è±¡
.EXCLUDE
å
INCLUDE
ä¸è½åæ¶ä½¿ç¨
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dup EXCLUDE=VIEW
8. FILESIZE
æå®å¯¼åºæ件çæ大尺寸
,
é»è®¤ä¸º
0,(
表示æ件尺寸没æéå¶
)
9. FLASHBACK_SCN
æå®å¯¼åºç¹å®
SCN
æ¶å»ç表æ°æ®
FLASHBACK_SCN=scn_value
Scn_value
ç¨äºæ è¯
SCN
å¼
.FLASHBACK_SCN
å
FLASHBACK_TIME
ä¸è½åæ¶ä½¿ç¨
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dmp
FLASHBACK_SCN=358523
10. FLASHBACK_TIME
æå®å¯¼åºç¹å®æ¶é´ç¹ç表æ°æ®
FLASHBACK_TIME=âTO_TIMESTAMP(time_value)â
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dmp FLASHBACK_TIME=
âTO_TIMESTAMP(â
25-08-2004
14:35:
00â
,âDD-MM-YYYYÂ HH24:MI:SSâ)â
11. FULL
æå®æ°æ®åºæ¨¡å¼å¯¼åº
,
é»è®¤ä¸º
N
FULL={YÂ |Â N}
为
Y
æ¶
,
æ è¯æ§è¡æ°æ®åºå¯¼åº
.
12. HELP
æå®æ¯å¦æ¾ç¤º
EXPDP
å½ä»¤è¡é项ç帮å©ä¿¡æ¯
,
é»è®¤ä¸º
N
å½è®¾ç½®ä¸º
Y
æ¶
,
ä¼æ¾ç¤ºå¯¼åºé项ç帮å©ä¿¡æ¯
.
Expdp help=y
13. INCLUDE
æå®å¯¼åºæ¶è¦å
å«ç对象类ååç¸å
³å¯¹è±¡
INCLUDE = object_type[:name_clause] [,â¦Â ]
14. JOB_NAME
æå®è¦å¯¼åºä½ç¨çå称
,
é»è®¤ä¸º
SYS_XXX
JOB_NAME=jobname_string
15. LOGFILE
æå®å¯¼åºæ¥å¿æ件æ件çå称
,
é»è®¤å称为
export.log
LOGFILE=[directory_object:]file_name
Directory_object
ç¨äºæå®ç®å½å¯¹è±¡å称
,file_name
ç¨äºæå®å¯¼åºæ¥å¿æ件å
.
å¦æä¸æå®
directory_object.
导åºä½ç¨ä¼èªå¨ä½¿ç¨
DIRECTORY
çç¸åºé项å¼
.
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dmp logfile=a.log
16. NETWORK_LINK
æå®æ°æ®åºé¾å
,
å¦æè¦å°è¿ç¨æ°æ®åºå¯¹è±¡å¯¼åºå°æ¬å°ä¾ç¨ç转å¨æ件ä¸
,
å¿
须设置该é项
.
17. NOLOGFILE
该é项ç¨äºæå®ç¦æ¢çæ导åºæ¥å¿æ件
,
é»è®¤å¼ä¸º
N.
18. PARALLEL
æå®æ§è¡å¯¼åºæä½ç并è¡è¿ç¨ä¸ªæ°
,
é»è®¤å¼ä¸º
1
19. PARFILE
æå®å¯¼åºåæ°æ件çå称
PARFILE=[directory_path]Â file_name
20. QUERY
ç¨äºæå®è¿æ»¤å¯¼åºæ°æ®ç
where
æ¡ä»¶
QUERY=[schema.]Â [table_name:]Â query_clause
Schema
ç¨äºæå®æ¹æ¡å
,table_name
ç¨äºæå®è¡¨å
,query_clause
ç¨äºæå®æ¡ä»¶éå¶åå¥
.QUERY
é项ä¸è½ä¸
CONNECT=METADATA_ONLY,EXTIMATE_ONLY,TRANSPORT_TABLESPACES
çé项åæ¶ä½¿ç¨
.
Expdp scott/tiger directory=dump dumpfiel=a.dmp
Tables=emp query=âWHERE deptno=
20â
21. SCHEMAS
该æ¹æ¡ç¨äºæå®æ§è¡æ¹æ¡æ¨¡å¼å¯¼åº
,
é»è®¤ä¸ºå½åç¨æ·æ¹æ¡
.
22. STATUS
æå®æ¾ç¤ºå¯¼åºä½ç¨è¿ç¨ç详ç»ç¶æ
,
é»è®¤å¼ä¸º
0
23. TABLES
æå®è¡¨æ¨¡å¼å¯¼åº
TABLES=[schema_name.]table_name[:partition_name][,â¦]
Schema_name
ç¨äºæå®æ¹æ¡å
,table_name
ç¨äºæå®å¯¼åºç表å
,partition_name
ç¨äºæå®è¦å¯¼åºçååºå
.
24. TABLESPACES
æå®è¦å¯¼åºè¡¨ç©ºé´å表
25. TRANSPORT_FULL_CHECK
该é项ç¨äºæå®è¢«æ¬ç§»è¡¨ç©ºé´åæªæ¬ç§»è¡¨ç©ºé´å
³èå
³ç³»çæ£æ¥æ¹å¼
,
é»è®¤ä¸º
N.
å½è®¾ç½®ä¸º
Y
æ¶
,
导åºä½ç¨ä¼æ£æ¥è¡¨ç©ºé´ç´æ¥çå®æ´å
³èå
³ç³»
,
å¦æ表空é´æå¨è¡¨ç©ºé´æå
¶ç´¢å¼æå¨ç表空é´åªæä¸ä¸ªè¡¨ç©ºé´è¢«æ¬ç§»
,
å°æ¾ç¤ºé误信æ¯
.
å½è®¾ç½®ä¸º
N
æ¶
,
导åºä½ç¨åªæ£æ¥å端ä¾èµ
,
å¦ææ¬ç§»ç´¢å¼æå¨è¡¨ç©ºé´
,
ä½æªæ¬ç§»è¡¨æå¨è¡¨ç©ºé´
,
å°æ¾ç¤ºåºéä¿¡æ¯
,
å¦ææ¬ç§»è¡¨æå¨è¡¨ç©ºé´
,
æªæ¬ç§»ç´¢å¼æå¨è¡¨ç©ºé´
,
åä¸ä¼æ¾ç¤ºé误信æ¯
.
26. TRANSPORT_TABLESPACES
æå®æ§è¡è¡¨ç©ºé´æ¨¡å¼å¯¼åº
27. VERSION
æå®è¢«å¯¼åºå¯¹è±¡çæ°æ®åºçæ¬
,
é»è®¤å¼ä¸º
COMPATIBLE.
VERSION={COMPATIBLEÂ |Â LATESTÂ |Â version_string}
为
COMPATIBLE
æ¶
,
ä¼æ ¹æ®åå§ååæ°
COMPATIBLE
çæ对象å
æ°æ®
;
为
LATEST
æ¶
,
ä¼æ ¹æ®æ°æ®åºçå®é
çæ¬çæ对象å
æ°æ®
.version_string
ç¨äºæå®æ°æ®åºçæ¬å符串
.
è°ç¨
EXPDP
使ç¨
EXPDP
å·¥å
ᾦ
,
å
¶è½¬å¨æ件åªè½è¢«åæ¾å¨
DIRECTORY
对象对åºç
OS
ç®å½ä¸
,
èä¸è½ç´æ¥æå®è½¬å¨æ件æå¨ç
OS
ç®å½
.
å æ¤
,
使ç¨
EXPDP
å·¥å
ᾦ
,
å¿
é¡»é¦å
建ç«
DIRECTORY
对象
.
并ä¸éè¦ä¸ºæ°æ®åºç¨æ·æäºä½¿ç¨
DIRECTORY
对象æé
.
-------------------------------------
åºç¨
-------------------------------------
Data Pump
åæ äºæ´ä¸ªå¯¼åº
/
导å
¥è¿ç¨çå®å
¨é©æ°ãä¸ä½¿ç¨å¸¸è§ç
SQL
å½ä»¤ï¼èæ¯åºç¨ä¸ç¨
API
ï¼
direct path api etc)
æ¥ä»¥æ´å¿«å¾å¤çé度å è½½åå¸è½½æ°æ®ã
1.Data Pump
导åº
expdp
ä¾åï¼
sql>create directory dpdata1 as '/u02/dpdata1';
sql>grant read, write on directory dpdata1 to ananda;
$expdp ananda/abc123 tables=CASES directory=DPDATA1 dumpfile=expCASES.dmp   job_name=CASES_EXPORT
$expdp ananda/abc123 tables=CASES directory=DPDATA1
dumpfile=expCASES_%U.dmp parallel=4 job_name=Cases_Export
include/exclude
ä¾åï¼
include=table:"in('DB','TS')"
æè
include=table:"like '%E%'"
æè
include=function,package,procedure,table:"='EMP'"
æè
exclude=SEQUENCE,TABLE:"INÂ ('EMP','DEPT')"
2.Data Pump
导å
¥
expdp
1)
ä»
expdp
ä¸è·åæ°æ®æº
exp.dmp
2)
å¤å¶æ个æ°æ®åºä¸çä¸ä¸ª
schema
å°å¦ä¸ä¸ªæ°æ®åºä¸ã
3)
å¨åä¸ä¸ªæ°æ®åºä¸æä¸ä¸ª
schema
ä¸ææç对象å¤å¶å°å¦ä¸ä¸ª
schema
ä¸ã
ä¾åï¼
1)impdp
çæ°æ®æºæ¯
expdp
导åºæ¥ç
DMP
æ件
impdp ananda/abc123 directory=dpdata1 dumpfile=expCASES.dmp job_name=cases_import
2)
å¤å¶æ个æ°æ®åºä¸çä¸ä¸ª
schema
å°å¦ä¸ä¸ªæ°æ®åºä¸ã
--1.newwork_link
为ç®æ æ°æ®åºå»ºç«ç
database_link
ï¼
(
ç¨æ·
test
éè¦
grant exp_full_database to TEST; )
create public database link TOLINK
connect to TEST identified by oracle
using '(DESCRIPTION =
(ADDRESS_LISTÂ =
(ADDRESSÂ =Â (PROTOCOLÂ =Â TCP)(HOSTÂ =
10.0.20
.199)(PORTÂ =Â 1521))
)
(CONNECT_DATAÂ =
(SERVICE_NAMEÂ =Â orcl)
)
)';
--2.impdp
å¨ç®æ æ°æ®åºæå¡å¨ä¸æ§è¡
åªè½ä½çæ¬åé«çæ¬
imp
impdp network_link=TOLINK schemas=test remap_schema=test:link2
3)
å¨åä¸ä¸ªæ°æ®åºä¸æä¸ä¸ª
schema
ä¸ææç对象å¤å¶å°å¦ä¸ä¸ª
schema
ä¸ã
--1.
å建è¿æ¥èªå·±ç
database link:
create public database link system_self connect to system identified by "system" using 'orcl';
æ°æ®åºé¾æ¥å·²å建ã
--2.
å¤å¶
hr schema
å°
test schema:
impdp system/system network_link=system_self schemas=hr remap_schema=hr:test
©èä½æå½ä½è
ææï¼æ¥èª51CTOå客ä½è
jamm118çååä½åï¼è°¢ç»è½¬è½½ï¼å¦åå°è¿½ç©¶æ³å¾è´£ä»»
Oracle
pythonçæåºå½æ°sort,sortedå¨å表æåºååå
¸æåºä¸çåºç¨è¯¦è§£å举ä¾
PostgreSQLé»è¾å¤ä»½pg_dump使ç¨åå
¶åç解æ
PostgreSQLå¦ä½å é¤ä¸ä½¿ç¨çxlogæ件
PostgreSQL pg_ctl startè¶
æ¶åæ
Greenplum -- segment æ»æºåæ¢å¤
postgresql 主å¤ååæ¢-æ¢å¤æ¹æ¡
顺丰å åºå·¥ç¨å¸éå¼é¤ï¼é¾éä»ä¸ä¼æ¢å¤è¯¯å æ°æ®ï¼
ä»å åºå°æ¢å¤å°è·ä¸äºè·¯-æ°æ®æ¢å¤å·¥ç¨å¸è§£è¯´é¡ºä¸°å åºäºä»¶
ã干货ãæ°æ®åºååºå表åºç¡åå®è·µ