您的位置:首页 > 其它

备份系列——Exp/Imp基本使用指南

2016-02-24 22:02 429 查看
概念:

1.用于备份恢复和数据迁移,可以实施全库级、用户级、表级的数据备份和恢复。

2.对于数据量在G级或者G级以内的,强调高可用性,可以容忍少量数据丢失的数据库系统,Exp/Imp是可以尝试的逻辑备份方式

3.处于客户端程序,但都可以在客户端和服务器使用。

export:从数据库中导出数据到dump文件中

import:从dump文件中导入数据到数据库中

dump文件:二进制格式的转储文件,不可手工编辑,可以跨OS/跨版本使用

使用场景:

数据库之间传送数据



数据库的备份和恢复



三种模式

1:表方式,将指定表的数据exp/imp。

导出:

导出一张或几张表:

$ exp user/pwd file=/dir/xxx.dmp log=xxx.log tables=table1,table2

导出某张表的部分数据

$ exp user/pwd file=/dir/xxx.dmp log=xxx.log tables=table1
query="where col1=\’ …\’

and col2 \<…\”

导入:

导入一张或几张表

$ imp user/pwd file=/dir/xxx.dmp log=xxx.log tables=table1,table2fromuser=dbuser

touser=dbuser2 commit=y ignore=y

详细过程:

创建一个表空间

SYS@orcl>createtablespace test_tbs

2 datafile '/home/oracle/test/test_data02.dbf'

3 size5m

4 autoextend on maxsize 512M;

创建两个用户

SYS@orcl>createuser testuser identified by testuser default tablespace test_tbs;

User created.

SYS@orcl>createuser testuser2 identified by testuser2 default tablespace test_tbs;

User created.

给新用户授权

SYS@orcl>grant CREATE SESSION,CREATE TABLE to testuser;

Grant succeeded.

SYS@orcl>grant CREATE SESSION,CREATE TABLE to testuser2;

Grant succeeded.

赋予用户在表空间中能够使用的配额

SYS@orcl>alteruser testuser1 quota 50M on test_tbs;

User altered.

SYS@orcl>alteruser testuser2 quota 50M on test_tbs;

User altered.

登陆用户testuser

SYS@orcl>conntestuser/testuser;

Connected.

创建表,插入数据

TESTUSER@orcl>create table testuser.exptest( a int);

Table created.

TESTUSER@orcl>insertinto testuser.exptest values (1);

1 row created.

TESTUSER@orcl>commit;

Commit complete.

TESTUSER@orcl>select* from testuser.exptest;

A

----------

1

登陆用户testuser2,确定没有exptest表

TESTUSER2@orcl>select* from testuser2.exptest;

select * fromtestuser2.exptest

*

ERROR at line 1:

ORA-00942: tableor view does not exist

切换到Linux终端界面,登陆oracle用户

[root@11g_s ~]#su – oracle

[oracle@11g_s~]$ exp testuser/testuser@orcl tables=exptest file ~/test/exp/tb_exp.dmplog=~/test/exp/testuserExp.log

Export: Release11.2.0.1.0 - Production on Tue Feb 23 18:53:25 2016

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 - Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

Export done inUS7ASCII character set and UTF8 NCHAR character set

server usesWE8MSWIN1252 character set (possible charset conversion)

About to exportspecified tables via Conventional Path ...

. . exportingtable EXPTEST 1 rows exported

EXP-00011:TESTUSER.FILE does not exist

EXP-00009: noprivilege to export /HOME/ORACLE/TEST/EXP/TB_EXP's table DMP

Exportterminated successfully with warnings.

[oracle@11g_s~]$ exp testuser/testuser@orcl tables=exptest file=~/test/exp/tb_exp.dmplog=~/test/exp/testuserExp.log

Export: Release11.2.0.1.0 - Production on Tue Feb 23 18:54:20 2016

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 - Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

Export done inUS7ASCII character set and UTF8 NCHAR character set

server usesWE8MSWIN1252 character set (possible charset conversion)

About to exportspecified tables via Conventional Path ...

. . exportingtable EXPTEST 1 rows exported

Export terminated successfully without warnings.

[oracle@11g_s~]$ imp testuser2/testuser2@orcl fromuser=testuser touser=testuser2file=~/test/exp/tb_exp.dmp log=~/test/exp/tb_imp.log

Import: Release11.2.0.1.0 - Production on Tue Feb 23 18:58:36 2016

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 - Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

Export filecreated by EXPORT:V11.02.00 via conventional path

Warning: theobjects were exported by TESTUSER, not by you

import done inUS7ASCII character set and UTF8 NCHAR character set

import serveruses WE8MSWIN1252 character set (possible charset conversion)

. importingTESTUSER's objects into TESTUSER2

. . importingtable "EXPTEST" 1rows imported

Import terminated successfully without warnings.

切换到sqlplus界面,登陆testuser2用户查看是否导入成功

TESTUSER2@orcl>select* from testuser2.exptest;

A

----------

1

不同用户之间表的Exp/Imp成功

2:用户方式,将指定用户的所有对象及数据导出/导入

导出:

$exp user/pwd file=/dir/xxx.dmp log=xxx.log owner=(xx,yy) # 要导出数据的数据库帐号

只导出数据对象,不导出数据(rows=n )

$exp user/pwd file=/dir/xxx.dmp log=xxx.log owner=user
rows=n #是否导出行数据,默认y,n则否

导入:

$imp user/pwd file=/dir/xxx.dmp log=xxx.log fromuser=dbuser touser=dbuser2

commit=yignore=y

详细过程:

[oracle@11g_s~]$ exp bankuser/bankuser file=~/bank/exp/bank_user.dmp log=~/bank/exp/

bank_user.logowner=bankuser

Export: Release11.2.0.1.0 - Production on Wed Feb 24 04:29:34 2016

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 - Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

Export done inWE8MSWIN1252 character set and UTF8 NCHAR character set

. exportingpre-schema procedural objects and actions

. exportingforeign function library names for user BANKUSER

. exportingPUBLIC type synonyms

. exportingprivate type synonyms

. exportingobject type definitions for user BANKUSER

About to exportBANKUSER's objects ...

. exportingdatabase links

. exportingsequence numbers

. exportingcluster definitions

. about toexport BANKUSER's tables via Conventional Path ...

. . exportingtable EXPTEST 2 rows exported

. exportingsynonyms

. exportingviews

. exportingstored procedures

. exportingoperators

. exportingreferential integrity constraints

. exportingtriggers

. exportingindextypes

. exportingbitmap, functional and extensible indexes

. exportingposttables actions

. exportingmaterialized views

. exportingsnapshot logs

. exporting jobqueues

. exportingrefresh groups and children

. exportingdimensions

. exportingpost-schema procedural objects and actions

. exportingstatistics

Export terminated successfully without warnings.

[oracle@11g_s~]$ imp bankuser2/bankuser2 file=~/bank/exp/bank_user.dmp log=~/bank/exp/

bank_user.logfromuser=bankuser touser=bankuser2 commit=y ignore=y

Import: Release11.2.0.1.0 - Production on Wed Feb 24 04:32:34 2016

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 - Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

Export filecreated by EXPORT:V11.02.00 via conventional path

Warning: theobjects were exported by BANKUSER, not by you

import done inWE8MSWIN1252 character set and UTF8 NCHAR character set

. . importingtable "EXPTEST" 2rows imported

Import terminated successfully without warnings.

3.全库方式,将数据库中的所有对象导出/导入

导出:

expuserid=sys/sys@orcl BUFFER=8192 FILE=x:\*.dmp LOG=x:\*.log
full=y grants=y

实际工作中用的最多的导入命令

impuserid=sys/sys@orcl BUFFER=81920 FILE=x:\*.dmp LOG=x:\*.log
full=y grants=y ignore=y

ignore解释:

当要导入数据库中已经存在了某个表(test),如果该表没有唯一性约束,那么在导入时加参数ignore=y,则会把数据完全导入到表中,而且不报错。

当表已经存在了唯一性约束,特别是主键的约束,那么在导入时,只导入主键中不存在的记录. 导入过程中会有警告.

操作与其它模式差不多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: