一、exp 导出和 imp 导入
-- exp导出:
exp middb/middb@middb12c
file=/data/XXX.dmp -- 导出路径
full=y -- 导出全库
owner=(middb,ewdb) -- 导出库
tables=(table1,table2) -- 导出表
query=\" where filed1 like ‘00%‘\" -- 字段filed1以"00"打头的数据导出
compress=y -- 压缩
indexs=y -- 导出索引
-- imp导入:
imp middb/middb@middb12c
file=/data/XXX.dmp
log=/data/XXX.log
tables=table1 -- 导出XXX.dmp中的table1
full=y
ignore=y
二、expdp 导出和 impdp 导入:
-- expdp导出:
expdp middb/middb@middb12c
directory=dp -- create directory dp as ‘/home/data/‘
content=all
dumpfile=XXX_`date ‘+%Y%m%d_%H%M‘`.dmp
logfile=XXX_`date ‘+%Y%m%d_%H%M‘`.log
exclude=trigger,index -- 过滤触发器,索引
tablespace=XXX -- 导出表空间
schemas=XXX,XXX -- 导出用户
tables=XXX,XXX
query="where rownum<11" -- 过滤条件 (在导出为tables的时候使用) shell中:query="\"where $time_col >= to_date(‘$start_date‘,‘yyyymmdd‘) and $time_col < to_date(‘$end_date‘,‘yyyymmdd‘)\""
parallel=8 -- 建议parallel设置不要超过cpu*2
cluster=n -- 使用 parallel 时使用
compression=ALL -- 压缩
##impdp导入
impdp middb/middb@middb12c
directory=dp ##create directory dp as ‘/home/data/‘
dumpfile=XXX_`date ‘+%Y%m%d_%H%M‘`.dmp
logfile=XXX_`date ‘+%Y%m%d_%H%M‘`.log
tablespace=XXX
schemas=XXX,XXX
table_exists_action=append
##sqlludr2导出:
sqluldr2_linux64_10204.bin
user=middb/middb@middb12c
file=/data/tablename.txt
log=/data/log/tablename.log
charset=utf8 field=‘0x01‘
query="select XXX from tablename";
##sqlldr导入:
sqlldr ewdb/ORACLE@ewdb12c
control=/data/ctl/tablename.ctl
data=/data/tablename.txt
log=/data/log/tablename.log
bad=/data/log/bad_tablename.log;
##eg:
1.expdp \"/ as sysdba\" directory=DP content=all dumpfile=s05_%U.dp logfile=s05_exp.log parallel=4 cluster=n schemas=S05 version=12.1.0.2.0
2.scp
3.impdp \"/ as sysdba\" directory=DP content=all dumpfile=s05_%U.dp logfile=s05_imp.log parallel=4 cluster=n schemas=S05 remap_tablespace=tbs_bigwaste:tbs_s05 remap_schema=sec:secooler
expdp c##ogg/Welcome1324@db_clear directory=DP content=all dumpfile=s06_`date ‘+%Y%m%d‘`.dp logfile=s06_exp_`date ‘+%Y%m%d‘`.log parallel=2 cluster=n exclude=trigger,index tables=scetc.TBL_GBTOLLLANEDIC
scp oracle@10.51.0.43:/data/dump
impdp s06/s06@orcl19c directory=dump content=all dumpfile=s06_20200312.dp logfile=s06_imp_`date ‘+%Y%m%d‘`.log parallel=2 cluster=n remap_tablespace=TBSD_DIC:tbs_s06,TBSI_BASE:tbs_s06 REMAP_SCHEMA=scetc:s06
==================================================================================
四、进度查询和监控
但领导问你导数进度时,会不会手忙脚乱的,无从查起?当然,作为一个负责任的DBA,实时的知道导出导入的进度,是必须掌握的技能。
1、 查看数据泵作业的运行情况
select owner_name owr,job_name jbn,operation ope,job_mode jbm,state,degree, attached_sessions atts,datapump_sessions dats from dba_datapump_jobs;
select sid, serial#,session_type from v$session s, dba_datapump_sessions d where s.saddr = d.saddr;
2、监控数据泵的逻辑备份程度
SELECT sid, serial#, context, sofar, totalwork, ROUND(sofar/totalwork*100,2) "%_COMPLETE"
FROM v$session_longops WHERE totalwork != 0 AND sofar <> totalwork;
SID SERIAL# CONTEXT SOFAR TOTALWORK %_COMPLETE
103 89 0 54 7 83.33
3、查看数据泵的详细进度
expdp etl/etl@orcl19c attach= SYS_EXPORT_TABLE_01
Import> status
Job: SYS_IMPORT_TABLE_01
Operation: IMPORT
Mode: TABLE
State: EXECUTING
Bytes Processed: 1,364,791,288
Percent Done: 99
Current Parallelism: 2
Job Error Count: 0
Dump File: /opt/datadump/expdp_testdump_20181218_01.dmp
===================================================================================
一、expdp状态查看及中断方法
1、查询expdp的job的名字
SQL> select job_name from dba_datapump_jobs;
JOB_NAME
------------------------------
SYS_EXPORT_SCHEMA_01
2、查询expdp状态
$ expdp test01/oracle_123 attach=SYS_EXPORT_SCHEMA_01
3、停止job
Export> stop_job
提问是否停止job,输入yes
Export> kill_job
提问是否杀掉job,输入yes
到这步,expdp就停止了。
二、impdp状态查看及中断方法
1、查看job的名字
SQL> select job_name from dba_datapump_jobs;
JOB_NAME
------------------------------
SYS_IMPORT_SCHEMA_01
2、查看impdp状态
$impdp system/oracle attach=SYS_IMPORT_SCHEMA_01
3、停止impdp
Import>stop_job
提问是否停止job,输入yes
Import>kill_job
提问是否杀掉job,输入yes