使用数据泵导入导出数据库

1.在本地创建转存目录:

oracle@linux:~> mkdir 0905 
oracle@linux:~>

2.连接数据库,并创建转存目录:

oracle@linux:~> sqlplus zxdbp_test/zxdbp_test@zxin;

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Sep 5 15:42:39 2016

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> create directory dir_dump as '/home/oracle/0905';

Directory created.

SQL>

使用system用户给转存目录赋予读写权限

SQL> conn system
Enter password:
Connected.


SQL> grant read,write on directory dir_dump to zxdbp_test;

Grant succeeded.

SQL>

2.使用expdp命令对数据库zxdbp_test进行备份:

oracle@linux:~> expdp zxdbp_test/zxdbp_test@zxin directory=dir_dump dumpfile=1.dmp logfile=1.log;

Export: Release 10.2.0.4.0 - 64bit Production on Monday, 05 September, 2016 15:54:38

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "ZXDBP_TEST"."SYS_EXPORT_SCHEMA_01": 
zxdbp_test/********@zxin directory=dir_dump dumpfile=1.dmp logfile=1.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
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/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
. . exported "ZXDBP_TEST"."TEST"                         11.89 KB     128 rows
Master table "ZXDBP_TEST"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for ZXDBP_TEST.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/0905/1.dmp
Job "ZXDBP_TEST"."SYS_EXPORT_SCHEMA_01" successfully completed at 15:55:17

oracle@linux:~>

3.使用impdp导入数据库:

先从数据库中删掉44条记录,

SQL> delete test where rownum<=44;

44 rows deleted.

SQL> commit;

Commit complete.

SQL> select count(*) from test;

  COUNT(*)
----------
        84

SQL>

然后恢复:

oracle@linux:~> impdp zxdbp_test/zxdbp_test@zxin directory=dir_dump dumpfile=1.dmp table_exists_action=truncate logfile=2.log;     

Import: Release 10.2.0.4.0 - 64bit Production on Monday, 05 September, 2016 16:06:50

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "ZXDBP_TEST"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "ZXDBP_TEST"."SYS_IMPORT_FULL_01": 
zxdbp_test/********@zxin directory=dir_dump dumpfile=1.dmp table_exists_action=truncate logfile=2.log
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"ZXDBP_TEST" already exists
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/TABLE/TABLE
ORA-39153: Table "ZXDBP_TEST"."TEST" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "ZXDBP_TEST"."TEST"                         11.89 KB     128 rows
Job "ZXDBP_TEST"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 16:06:53

oracle@linux:~>

恢复完成,其中有一个参数table_exists_action=truncate是指针对存在的表的处理方式,我这里直接truncate掉,然后我们去查一下数据库:


SQL> select count(*) from test;


  COUNT(*)
----------
       128

SQL>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值