Instructions for using expdp/impdp to backup database in Oracle

1. Preface _

2. Technical introduction

3. Implementation plan

3.1 Creation of backup directory

3.2 expdp export database

3.3 impdp import database

4. Result verification

4.1 Comparison of database structures

4.2 Comparison of database data

 

 

1.  Preface

With the rapid development of computer network , the importance of information security is becoming more and more obvious, but, as an important content of information security, the importance of data backup is often ignored by people. As long as data transmission, data storage, data exchange, software failure, hard disk bad sectors, etc. occur, data failure may occur. At this time, if data backup and data recovery means and measures are not taken, it will lead to data loss. Without database backup, there will be no database recovery. Enterprises should regard the work of enterprise data backup as a system work that cannot be ignored, select corresponding backup equipment and technology for it, and carry out economical and reliable data backup, so as to avoid possible occurrences. significant losses.

2.  Technical introduction

Oracle 10g introduced data pump (Data Dump) technology, the role of data pump export and import (expdp and impdp) has the following four points:

1) Realize logical backup and logical recovery

2) Move objects between database users

3) Move objects between databases

4) Realize table space move

What are the advantages of this technology and the previous exp/imp? In short , the recovery and backup speed are very fast . Before explaining how to use the data pump, let's first understand the difference between the two:

Before 10g, you could only use the exp/imp command to back up; since 10g, oracle provides two methods, exp/imp and expdp/impdp, but we must figure out before using:

1. exp/imp are client-side tools, they can be used both on the client-side and on the server-side; that is to say, you can directly back up the database on another computer to your own computer .

2. expdp/impdp are server-side tools, they can only backup the database to the server (that is to say, you run this command on your own computer, but the backup database is still on the server) .

3. exp/imp and expdp/impdp cannot be used interchangeably, that is to say, the database backed up with exp/imp can only be imported with the exp/imp command, and vice versa .

three, implementation plan

3.1  Creation of backup directory

When using the expdp command, the exported files can only be stored in the specified directory, so you need to create a specific directory and authorize the user before using it .

First , you need to create the corresponding dump directory on the physical hard disk , and then execute the DDL and DCL commands.

The following statement is executed under PL/SQL Command Window

create directory dump_dir as 'E:\oracle\dump;

grant read,write on directory dump_dir to xmuedu;

 

 



  

3.2 expdp导出数据库

执行导出命令:

C:\Users\Administrator>expdp c##newo/root dumpfile=newo.dmp directory=dump_dir



  

导出完成后,若没有出现异常可在directory目录下找到dmp文件,即备份数据。

expdp还可以进行定制化的导出,用户可根据自己的实际需求来添加参数。

参数说明如下:

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
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
ESTIMATE={BLOCKS | STATISTICS}
设置为BLOCKS时,oracle会按照目标对象所占用的数据块个数乘以数据块尺寸估算对象占用的空间,设置为STATISTICS时,根据最近统计值估算对象占用空间。
Expdp scott/tiger TABLES=emp ESTIMATE=STATISTICS DIRECTORY=dump DUMPFILE=a.dump
6. ESTIMATE_ONLY
指定是否只估算导出作业所占用的磁盘空间,默认值为N
EXTIMATE_ONLY={Y | N}
设置为Y时,导出作用只估算对象所占用的磁盘空间,而不会执行导出作业,为N时,不仅估算对象所占用的磁盘空间,还会执行导出操作.
Expdp scott/tiger ESTIMATE_ONLY=y NOLOGFILE=y
7. EXCLUDE(具体见2、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
SELECT * FROM DBA_DATAPUMP_JOBS;--查看存在的job
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
指定数据库链名,如果要将远程数据库对象导出到本地例程的转储文件中,必须设置该选项。
如:expdp gwm/gwm directory=dir_dp NETWORK_LINK=igisdb tables=p_street_area dumpfile =p_street_area.dmp logfile=p_street_area.log     job_name=my_job
igisdb是目的数据库与源数据的链接名,dir_dp是目的数据库上的目录
而如果直接用使用连接字符串(@fgisdb),expdp属于服务端工具,expdp生成的文件默认是存放在服务端的。
17. NOLOGFILE
该选项用于指定禁止生成导出日志文件,默认值为N。
18. PARALLEL
指定执行导出操作的并行进程个数,默认值为1
注:并行度设置不应该超过CPU数的2倍,如果cpu为2个,可将PARALLEL设为2,在导入时速度比PARALLEL为1要快,而对于导出的文件,如果PARALLEL设为2,导出文件只有一个,导出速度提高不多,因为导出都是到同一个文件,会争抢资源。所以可以设置导出文件为两个,如下所示:
expdp gwm/gwm directory=d_test dumpfile=gwmfile1.dp,gwmfile2.dp parallel=2
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 dumpfile=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。

3.3 impdp导入数据库

执行导出命令:

C:\Users\Administrator>impdp c##newo/root dumpfile=newo.dmp directory=dump_dir



  

用户可根据自己的实际需求来添加参数。参数说明如下:

1. TABBLE_EXISTS_ACTION={SKIP | APPEND | TRUNCATE | FRPLACE }
当设置该选项为SKIP时,导入作业会跳过已存在表处理下一个对象;当设

置为APPEND时,会追加数据,为TRUNCATE时,导入作业会截断表,然后为其追加新数据;当设置为REPLACE时,导入作业会删除已存在表,重建表病追加数据,注意,TRUNCATE选项不适用与簇表和NETWORK_LINK选项;
2. REMAP_SCHEMA
该选项用于将源方案的所有对象装载到目标方案中:REMAP_SCHEMA=source_schema:target_schema
3. REMAP_TABLESPACE
将源表空间的所有对象导入到目标表空间中:REMAP_TABLESPACE=source_tablespace:target:tablespace
4. REMAP_DATAFILE
该选项用于将源数据文件名转变为目标数据文件名,在不同平台之间搬移表空间时可能需要该选项。
REMAP_DATAFIEL=source_datafie:target_datafile

四、结果校验

4.1 数据库结构的对比

主要对比两个数据库的表结构是否一致。PL/SQL DEVELOPER提供了两个数据库表结构的比对方法。具体操作详见《ORACLE 数据库对比方法简介》。

4.2 数据库数据的对比

主要对比两个数据库各个表数据是否一致,对比方法将两个数据库中所有用户表的数据生成由INSERT语句组成的文本文件,放在数据库服务器上的两个不同的目录下,用BEYOND COMPARE进行文件比对。具体操作详见《ORACLE 数据库对比方法简介》。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326769444&siteId=291194637