Oracle 11g 数据库 expdp/impdp 全量导入导出
从一个用户导出导入到另一个用户
问题
环境:oracle 11g; redhat 6
usera是具有DBA权限,密码为usera
全量导出usera用户下的所有内容,并导入到新建的userb用户
解决
创建Directory: create or replace directory DUMP_DIR_D as '/home/oracle/rhuser/oracledmp';
1、重新测试之前要恢复环境
DROP USER userb cascade;
drop tablespace tbsfsj including contents and datafiles;
2、创建表空间和用户及赋权
create TABLESPACE tbsfsj DATAFILE '/home/oracle/rhuser/tbsfsj.dbf' -- redhat user
size 10M autoextend on maxsize 30G;
create user userb identified by userb default tablespace tbsfsj;
-- grant connect, resource, DATAPUMP_IMP_FULL_DATABASE, DATAPUMP_EXP_FULL_DATABASE
-- to userb;
GRANT dba to userb;
grant read, write on directory DUMP_DIR_D to userb;
3、schemas方式导出
expdp usera/usera directory=DUMP_DIR_D dumpfile=exp1.dmp logfile=exp1.log schemas=usera
4、schemas方式导入
impdp userb/userb schemas=usera directory=DUMP_DIR_D dumpfile=imp1.dmp logfile=imp1.log remap_schema=usera:userb
核对
-- 以新用户userb登录,检查是否成功导入
SQL> select count(*) from user_tables;
COUNT(*)
----------
126
SQL> select count(*) from user_views;
COUNT(*)
----------
1
SQL> select count(*) from user_sequences;
COUNT(*)
----------
32
SQL> select count(*) from user_triggers;
COUNT(*)
----------
0
脚本
$ ssh root@remote_server_ip
$ su - oracle
$ cd /home/oracle/rhuser
$ cat exp1_schemas_usera.sh
#!/bin/bash
if [ "$1" = '' ]
then
filename=defaultexp
else
filename=$1
fi
dumppathprefix="/home/oracle/rhuser/oracledmp"
starttime=`date +'%s'`
expdp usera/usera directory=DUMP_DIR_D dumpfile=$filename.dmp logfile=$filename.log schemas=usera
endtime=`date +'%s'`
res="本次运行时间: "$((endtime-starttime))"s"
echo $res>>"$dumppathprefix/$filename.log"
echo $res
$ cat imp1_schemas_usera2fsj.sh
#!/bin/bash
if [ "$1" = '' ]
then
filename=defaultimp
else
filename=$1
fi
if [ "$2" = "" ]
then
dmp=exp1_schemas
else
dmp=$2
fi
dumppathprefix="/home/oracle/rhuser/oracledmp"
starttime=`date +'%s'`
impdp userb/userb schemas=usera directory=DUMP_DIR_D dumpfile=$dmp.dmp logfile=$filename.log remap_schema=usera:userb
endtime=`date +'%s'`
res="本次运行时间: "$((endtime-starttime))"s"
echo $res>>"$dumppathprefix/$filename.log"
echo $res
讨论
Data Pump Export (hereinafter referred to as Export for ease of reading) is a utility for unloading data and metadata into a set of operating system files called a dump file set. The dump file set can be imported only by the Data Pump Import utility. The dump file set can be imported on the same system or it can be moved to another system and loaded there.
The dump file set is made up of one or more disk files that contain table data, database object metadata, and control information. The files are written in a proprietary, binary format. During an import operation, the Data Pump Import utility uses these files to locate each database object in the dump file set.
Because the dump files are written by the server, rather than by the client, the database administrator (DBA) must create directory objects that define the server locations to which files are written. See "Default Locations for Dump, Log, and SQL Files" for more information about directory objects.
Data Pump Export enables you to specify that a job should move a subset of the data and metadata, as determined by the export mode. This is done using data filters and metadata filters, which are specified through Export parameters. See "Filtering During Export Operations".
To see some examples of the various ways in which you can use Data Pump Export, refer to "Examples of Using Data Pump Export".
Export provides different modes for unloading different portions of the database. The mode is specified on the command line, using the appropriate parameter. The available modes are described in the following sections:
- "Full Export Mode"
- "Schema Mode"
- "Table Mode"
- "Tablespace Mode"
- "Transportable Tablespace Mode"
The mode is specified on the command line, using the appropriate parameter. The available modes are described in the following sections:
- "Full Import Mode"
- "Schema Mode"
- "Table Mode"
- "Tablespace Mode"
- "Transportable Tablespace Mode"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?