重慶思莊oracle技術(shù)分享-如何從dump文件中提取元數(shù)據(jù)信息
如何從dump文件中提取元數(shù)據(jù)信息?
1)通過sq生成sql方式
?
2)通過oracle提供的包
?
3)通過expdp和impdp
?
實(shí)現(xiàn)方法
?
1)通過sq生成sql方式
?
--11g使用(創(chuàng)建用戶)
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#;
--(創(chuàng)建角色)
select 'create role '||role||';' from dba_roles;
--角色權(quán)限
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 '));
--系統(tǒng)權(quán)限
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) );
--對象權(quán)限
select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee||';' from dba_tab_privs where owner='XXX' ;
目標(biāo)庫根據(jù)上述查詢結(jié)果進(jìn)行創(chuàng)建。
2)通過oracle提供的包
dbms_metadata.get_ddl
具體操作百度上面很多,方法也是一樣;
3)通過expdp和impdp
該方法,主要是通過從原庫中抽取自己想要的元數(shù)據(jù)信息,然后轉(zhuǎn)化成dmp文件內(nèi)容;
再利用impdp方式將dump中的內(nèi)容轉(zhuǎn)成文本方式,供用戶編輯調(diào)整使用
源庫:
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
目標(biāo)庫:
[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
注意:上面這個(gè)就是將dump中的文件轉(zhuǎn)儲(chǔ)到/backup/下的text.sql中,將該sql拿出來就是提取的元數(shù)據(jù)腳本了;
?