重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1030|回复: 0
打印 上一主题 下一主题

[Oracle] 如何从dump文件中提取元数据信息?

[复制链接]
跳转到指定楼层
楼主
发表于 2023-2-21 10:59:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如何从dump文件中提取元数据信息?

一、群里面有同学提到,需要将数据库中所有用户、角色的信息完全的提取出来,按照之前的经验有3种方法:

1)通过sq生成sql方式

2)通过oracle提供的包

3)通过expdp和impdp


二、实现方法

1)通过sq生成sql方式

--11g使用(创建用户)
select a.username,a.password_versions,a.account_status,a.lock_date,a.expiry_date,a.created,b.password,b.spare4,
       case when a.password_versions in ('10G ') then
                 'create user '||username||' identified by values '||''''||b.password||''''||' default tablespace '||default_tablespace||' temporary tablespace '||temporary_tablespace||';'
           when a.password_versions in ('10G 11G ','10G 11G 12C ') then
                'create user '||b.name||' identified by values '||''''||b.spare4||';'||b.password||''' default tablespace '||a.default_tablespace||' temporary tablespace '||a.temporary_tablespace||';'
           else '' end as "create user"
from dba_users a,user$ b
where a.username=b.name
and a.user_id=b.user#;

--(创建角色)
select 'create role '||role||';' from dba_roles;
--角色权限
select 'grant '||GRANTED_ROLE||' to '||grantee||';' from dba_role_privs where
grantee in(select username from dba_users where trunc(created) <> to_date('2010/4/20','yyyy/mm/dd'));

select 'grant '||GRANTED_ROLE||' to '||grantee||';' from dba_role_privs where
grantee in(select username from dba_users where username not in
(select name
from system.logstdby$skip_support
where action=0) );

SQL> select 'grant '||GRANTED_ROLE||' to '||grantee||';' from dba_role_privs where grantee in(select username from dba_users where default_tablespace in(' TBS1 ' , ' TBS2 '));


--系统权限
select 'grant '||PRIVILEGE||' to '||grantee||';' from DBA_SYS_PRIVS where grantee in (select username from dba_users where username not in
(select name
from system.logstdby$skip_support
where action=0) );

--对象权限
select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee||';' from dba_tab_privs where owner='XXX' ;

目标库根据上述查询结果进行创建。


2)通过oracle提供的包
dbms_metadata.get_ddl
具体操作百度上面很多,方法也是一样;

3)通过expdp和impdp
该方法,主要是通过从原库中抽取自己想要的元数据信息,然后转化成dmp文件内容;
再利用impdp方式将dump中的内容转成文本方式,供用户编辑调整使用
源库:
create directory dump_xtts as '/backup/';
expdp \' sys/his as sysdba \' DIRECTORY=dump_xtts LOGFILE=user_exp.log dumpfile=user_exp.dmp INCLUDE=USER,ROLE,ROLE_GRANT,PROFILE full=y

目标库:
[oracle@ol7 backup]$ scp oracle@192.168.9.179:/backup/user_exp.* .
create directory dump_xtts as '/backup/';
impdp \' / as sysdba \' DIRECTORY=dump_xtts LOGFILE=user_exp.log dumpfile=user_exp.dmp INCLUDE=USER,ROLE,ROLE_GRANT,PROFILE sqlfile=text.sql

注意:上面这个就是将dump中的文件转储到/backup/下的text.sql中,将该sql拿出来就是提取的元数据脚本了;





分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-20 23:33 , Processed in 0.096340 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表