如何确定 Oracle Data Pump 导出文件中的模式

发布于 2024-07-05 09:30:50 字数 1185 浏览 5 评论 0 原文

  • 我有一个使用 expdp 创建的 Oracle 数据库备份文件 (.dmp)。
  • .dmp 文件是整个数据库的导出。
  • 我需要从此转储文件中恢复 1 个模式。
  • 我不知道此转储文件中的架构名称。
  • 要使用 impdp 导入数据,我需要加载架构的名称。

因此,我需要检查 .dmp 文件并列出其中的所有架构,我该怎么做?


更新 (2008-09-18 13:02) - 更详细的信息:

我当前使用的 impdp 命令是:

impdp user/password@database directory=DPUMP_DIR 
      dumpfile=EXPORT.DMP logfile=IMPORT.LOG  

并且 DPUMP_DIR 已正确配置。

SQL> SELECT directory_path
2  FROM dba_directories
3  WHERE directory_name = 'DPUMP_DIR';

DIRECTORY_PATH
-------------------------
D:\directory_path\dpump_dir\

是的,EXPORT.DMP 文件实际上位于该文件夹中。

运行 impdp 命令时收到的错误消息是:

Connected to: Oracle Database 10g Enterprise Edition ...
ORA-31655: no data or metadata objects selected for the job
ORA-39154: Objects from foreign schemas have been removed from import

此错误消息大多是预期的。 我需要 impdp 命令为:

impdp user/password@database directory=DPUMP_DIR dumpfile=EXPORT.DMP 
      SCHEMAS=SOURCE_SCHEMA REMAP_SCHEMA=SOURCE_SCHEMA:MY_SCHEMA

但要做到这一点,我需要源模式。

  • I have an Oracle database backup file (.dmp) that was created with expdp.
  • The .dmp file was an export of an entire database.
  • I need to restore 1 of the schemas from within this dump file.
  • I don't know the names of the schemas inside this dump file.
  • To use impdp to import the data I need the name of the schema to load.

So, I need to inspect the .dmp file and list all of the schemas in it, how do I do that?


Update (2008-09-18 13:02) - More detailed information:

The impdp command i'm current using is:

impdp user/password@database directory=DPUMP_DIR 
      dumpfile=EXPORT.DMP logfile=IMPORT.LOG  

And the DPUMP_DIR is correctly configured.

SQL> SELECT directory_path
2  FROM dba_directories
3  WHERE directory_name = 'DPUMP_DIR';

DIRECTORY_PATH
-------------------------
D:\directory_path\dpump_dir\

And yes, the EXPORT.DMP file is in fact in that folder.

The error message I get when I run the impdp command is:

Connected to: Oracle Database 10g Enterprise Edition ...
ORA-31655: no data or metadata objects selected for the job
ORA-39154: Objects from foreign schemas have been removed from import

This error message is mostly expected. I need the impdp command be:

impdp user/password@database directory=DPUMP_DIR dumpfile=EXPORT.DMP 
      SCHEMAS=SOURCE_SCHEMA REMAP_SCHEMA=SOURCE_SCHEMA:MY_SCHEMA

But to do that, I need the source schema.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

梦里°也失望 2024-07-12 09:30:50

运行 impdp 命令来生成 sqlfile,您需要以具有 DATAPUMP_IMP_FULL_DATABASE 角色的用户身份运行它。

或者...以低特权用户身份运行它并使用 MASTER_ONLY=YES 选项,然后检查主表。 例如

select value_t 
from SYS_IMPORT_TABLE_01 
where name = 'CLIENT_COMMAND' 
and process_order = -59;

col object_name for a30
col processing_status head STATUS for a6
col processing_state head STATE for a5
select distinct
  object_schema,
  object_name,
  object_type,
  object_tablespace,
  process_order,
  duplicate,
  processing_status,
  processing_state
from sys_import_table_01
where process_order > 0
and object_name is not null
order by object_schema, object_name
/

http://download.oracle.com/otndocs/产品/数据库/enterprise_edition/utilities/pdf/oow2011_dp_mastering.pdf

The running the impdp command to produce an sqlfile, you will need to run it as a user which has the DATAPUMP_IMP_FULL_DATABASE role.

Or... run it as a low privileged user and use the MASTER_ONLY=YES option, then inspect the master table. e.g.

select value_t 
from SYS_IMPORT_TABLE_01 
where name = 'CLIENT_COMMAND' 
and process_order = -59;

col object_name for a30
col processing_status head STATUS for a6
col processing_state head STATE for a5
select distinct
  object_schema,
  object_name,
  object_type,
  object_tablespace,
  process_order,
  duplicate,
  processing_status,
  processing_state
from sys_import_table_01
where process_order > 0
and object_name is not null
order by object_schema, object_name
/

http://download.oracle.com/otndocs/products/database/enterprise_edition/utilities/pdf/oow2011_dp_mastering.pdf

奢华的一滴泪 2024-07-12 09:30:50

如果您使用 impdp 会将 dmp 备份的 DDL 导出到文件。 102/b14215/dp_import.htm#sthref354" rel="noreferrer">SQLFILE 参数。 例如,将其放入文本文件中,

impdp '/ as sysdba' dumpfile=<your .dmp file> logfile=import_log.txt sqlfile=ddl_dump.txt

然后检查 ddl_dump.txt 备份中的表空间、用户和架构。

根据文档,这实际上并没有修改数据库:

SQL并未真正执行,目标系统保持不变。

impdp exports the DDL of a dmp backup to a file if you use the SQLFILE parameter. For example, put this into a text file

impdp '/ as sysdba' dumpfile=<your .dmp file> logfile=import_log.txt sqlfile=ddl_dump.txt

Then check ddl_dump.txt for the tablespaces, users, and schemas in the backup.

According to the documentation, this does not actually modify the database:

The SQL is not actually executed, and the target system remains unchanged.

于我来说 2024-07-12 09:30:50

如果您使用可以处理大文件的编辑器打开 DMP 文件,您也许能够找到提到架构名称的区域。 请确保不要更改任何内容。 如果您打开原始转储的副本会更好。

If you open the DMP file with an editor that can handle big files, you might be able to locate the areas where the schema names are mentioned. Just be sure not to change anything. It would be better if you opened a copy of the original dump.

深海夜未眠 2024-07-12 09:30:50

更新 (2008-09-19 10:05) - 解决方案:

我的解决方案: 社会工程,我努力挖掘并找到了知道架构名称的人。
技术解决方案:搜索 .dmp 文件确实得到架构名称。
一旦我知道了模式名称,我就搜索转储文件并了解在哪里可以找到它。

在 .dmp 文件中可以看到架构名称的位置:

  • SOURCE_SCHEMA
    这出现在每个表名称/定义之前。

  • SCHEMA_LIST“SOURCE_SCHEMA”
    这是在 .dmp 末尾附近看到的。

有趣的是,在 SCHEMA_LIST 'SOURCE_SCHEMA' 部分周围,它还有用于创建转储的命令行、使用的目录、使用的 par 文件、运行的 Windows 版本以及导出会话设置(语言,日期格式)。

所以,问题解决了:)

Update (2008-09-19 10:05) - Solution:

My Solution: Social engineering, I dug real hard and found someone who knew the schema name.
Technical Solution: Searching the .dmp file did yield the schema name.
Once I knew the schema name, I searched the dump file and learned where to find it.

Places the Schemas name were seen, in the .dmp file:

  • <OWNER_NAME>SOURCE_SCHEMA</OWNER_NAME>
    This was seen before each table name/definition.

  • SCHEMA_LIST 'SOURCE_SCHEMA'
    This was seen near the end of the .dmp.

Interestingly enough, around the SCHEMA_LIST 'SOURCE_SCHEMA' section, it also had the command line used to create the dump, directories used, par files used, windows version it was run on, and export session settings (language, date formats).

So, problem solved :)

唯憾梦倾城 2024-07-12 09:30:50

假设您没有首先生成该文件的 expdp 作业的日志文件,最简单的选择可能是使用 SQLFILE 参数 让 impdp 生成 DDL 文件(基于完全导入)。 然后您可以从该文件中获取架构名称。 当然,这并不理想,因为 impdp 必须读取整个转储文件以提取 DDL,然后再次获取您感兴趣的模式,并且您必须执行一些文本文件搜索各种 CREATE USER 语句,但应该是可行的。

Assuming that you do not have the log file from the expdp job that generated the file in the first place, the easiest option would probably be to use the SQLFILE parameter to have impdp generate a file of DDL (based on a full import). Then you can grab the schema names from that file. Not ideal, of course, since impdp has to read the entire dump file to extract the DDL and then again to get to the schema you're interested in, and you have to do a bit of text file searching for the various CREATE USER statements, but it should be doable.

孤檠 2024-07-12 09:30:50

我的解决方案(类似于 KyleLanser 的答案)(在 Unix 机器上):

strings dumpfile.dmp | grep SCHEMA_LIST

My solution (similar to KyleLanser's answer) (on a Unix box):

strings dumpfile.dmp | grep SCHEMA_LIST
风透绣罗衣 2024-07-12 09:30:50

就我而言,根据 Aldur 和 slafs 的答案,我想出了这个表达式,它应该只告诉您原始模式的名称:

cat -v file.dmp | grep 'SCHEMA_LIST' | uniq -u | grep -o -P '(?<=SCHEMAS\=).*(?=content)'

Tested for a DMP file from Oracle 19.8 version。

In my case, based on Aldur's and slafs' answers I came up with this expression that should tell you just the name of the original schema:

cat -v file.dmp | grep 'SCHEMA_LIST' | uniq -u | grep -o -P '(?<=SCHEMAS\=).*(?=content)'

Tested for a DMP file from Oracle 19.8 version.

牵你的手,一向走下去 2024-07-12 09:30:50

您需要搜索 OWNER_NAME。

cat -v dumpfile.dmp | grep -o '<OWNER_NAME>.*</OWNER_NAME>' | uniq -u

cat -v 将转储文件转换为可见文本。

grep -o 仅显示匹配项,因此我们看不到很长的行

uniq -u 删除重复行,因此您会看到更少的输出。

即使在大型转储文件上,这种方法也能很好地工作,并且可以进行调整以在脚本中使用。

You need to search for OWNER_NAME.

cat -v dumpfile.dmp | grep -o '<OWNER_NAME>.*</OWNER_NAME>' | uniq -u

cat -v turn the dumpfile into visible text.

grep -o shows only the match so we don't see really long lines

uniq -u removes duplicate lines so you see less output.

This works pretty well, even on large dump files, and could be tweaked for usage in a script.

挥剑断情 2024-07-12 09:30:50

第一步:这是一个简单的例子。 您必须使用 SQLFILE 选项从转储文件创建 SQL 文件。

第 2 步:在生成的 SQL 文件(此处为tables.sql)中查找 CREATE USER

示例如下:

$ impdp directory=exp_dir dumpfile=exp_user1_all_tab.dmp  logfile=imp_exp_user1_tab sqlfile=tables.sql

导入:版本 11.2.0.3.0 - 于 2013 年 4 月 26 日星期五 08:29:06 发布

版权所有 (c) 1982、2011,Oracle 和/或其附属公司。 保留所有权利。

用户名:/作为sysdba

处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA 作业“SYS”。“SYS_SQL_FILE_FULL_01”于 08:29:12 成功完成

$ grep "CREATE USER" tables.sql

创建由值“S:270D559F9B97C05EA50F78507CD6EAC6AD63969E5E;BBE7786A5F9103”标识的用户“USER1”

这里解释了很多数据泵选项 http://www.acehints.com/p/site-map.html

Step 1: Here is one simple example. You have to create a SQL file from the dump file using SQLFILE option.

Step 2: Grep for CREATE USER in the generated SQL file (here tables.sql)

Example here:

$ impdp directory=exp_dir dumpfile=exp_user1_all_tab.dmp  logfile=imp_exp_user1_tab sqlfile=tables.sql

Import: Release 11.2.0.3.0 - Production on Fri Apr 26 08:29:06 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Username: / as sysdba

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Job "SYS"."SYS_SQL_FILE_FULL_01" successfully completed at 08:29:12

$ grep "CREATE USER" tables.sql

CREATE USER "USER1" IDENTIFIED BY VALUES 'S:270D559F9B97C05EA50F78507CD6EAC6AD63969E5E;BBE7786A5F9103'

Lot of datapump options explained here http://www.acehints.com/p/site-map.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文