1 首先在备份服务器安装与生产数据库版本一致的数据库,注意要安装数据库,而不只是
客户端。
2 备份端操作:
2.1 创建导出/导入目录 bkpath
SQL> create directory bkpath as 'D:\testdb';
SQL> grant all on directory bkpath to system;
2.2 测试导出本地整个数据库:
C:\Windows\system32>expdp system/oracle directory=bkpath dumpfile=full.dmp log=full.log
full=y
测试导出本地 scott 用户:
C:\Windows\system32>expdp system/oracle directory=bkpath dumpfile=scott.dmp
log=scott.log schemas=scott
如果要一起导出多个用户,直接 schemas=user01,user02,user03…即可
2.3 测试连接生产数据库:
C:\Windows\system32>sqlplus system/oracle@vm_testdb
生产端创建测试用户:
SQL> create user test identified by test;
SQL> grant connect,resource to test;
连接测试用户,创建 test 表:
C:\Windows\system32>sqlplus test/test@vm_testdb
SQL> create table test as select * from user_objects;
2.4 创建指向生产数据的 database link
SQL> create public database link dblink_test connect to system identified by oracle using
'vm_testdb';
数据库链接已创建。
2.5 导出生产数据库中的 test 用户
expdp system/oracle directory=bkpath network_link=dblink_test
dumpfile=test.dmp logfile=test.log schemas=test
注释:语句中第一个 system/oracle 是用来登录本地数据库的,需要有 bkpath 的权限。实际
导出是异地数据库的 system/oracle(由 network_link 中指定的 db_link 决定)来执行的。
C:\Windows\system32>expdp system/oracle directory=bkpath network_link=dblink_test
dumpfile=test.dmp logfile=test.log schemas=test
Export: Release 11.2.0.1.0 - Production on 星期五 12 月 7 13:40:19 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SYSTEM"."SYS_EXPORT_SCHEMA_01":
system/******** directory=bkpath
network_link=dblink_test dumpfile=test.dmp logfi
le=test.log schemas=test
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 SCHEMA_EXPORT/USER
处理对象类型 SCHEMA_EXPORT/SYSTEM_GRANT
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
. . 导出了 "TEST"."TEST"
8.421 KB
1 行
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
SYSTEM.SYS_EXPORT_SCHEMA_01 的转储文件集为:
D:\TESTDB\TEST.DMP
作业 "SYSTEM"."SYS_EXPORT_SCHEMA_01" 已于 13:40:32 成功完成
3 将从生产库导出的文件导入备份库
以下内容也均从备份端执行:
导出:
C:\Windows\system32>expdp system/ok directory=bkpath network_link=dblink_test
dumpfile=test3.dmp logfile=test3.log schemas=test3
导入:
C:\Windows\system32>impdp system/ok directory=bkpath dumpfile=test3.dmp
logfile=impdptest3.log
成功导入。
由此可见,impdp 在导入的时候可以省略创建用户、授权的过程,条件是导出的时候是使
用的 system 用户。
参考:expdp xxx/xxx schemas=xxx directory=dump1 network_link =xxx
dumpfile=xxx_%U.dump filesize=5g
参考:
SQL> CREATE DIRECTORY DUMP_FILES1 AS '/usr/apps/dumpfiles1';
SQL> GRANT READ, WRITE ON DIRECTORY dpump_dir1 TO hr;
SQL> SELECT directory_name, directory_path FROM dba_directories;
C:\Users\liyh>expdp system/ok directory=bkpath dumpfile=scottss.dmp
schemas=scott,test1,test2
C:\Users\liyh>impdp system/ok directory=bkpath dumpfile=scottss.dmp
schemas=scott,test1,test2(不指定schemas 时会导入全部的schemas)
1、CONTENT=[ALL | DATA_ONLY | METADATA_ONLY]
ALL unloads both data and metadata. This is the default.
DATA_ONLY unloads only table row data; no database object definitions are
unloaded.
METADATA_ONLY unloads only database object definitions; no table row
data is unloaded. Be aware that if you specify CONTENT=METADATA_ONLY, then
when the dump file is subsequently imported, any index or table statistics
imported from the dump file will be locked after the import.
2、dumpfile
默认扩展名为.dmp,
文件名中可包含替代变量(%U),%U 从 1 到 99。意味着最多可生成多 99 个 dmp 文件。
如果 FILESIZE 参数指定,会限制 dump file 的最大值, FILESIZE=integer[B |
KB | MB | GB | TB]。如果需要更多的空间,并且使用了%U 参数,新的 dump file
会依次自动生成。
读:同时读取的数据文件数量
写:同时写入的 dump file 数量(parallel 数、CPU 数)