简体   繁体   English

如何在 oracle 中的默认用户帐户之外的所有模式及其分配的角色上备份对象权限?

[英]How to take the backup of objects privileges on all schemas and its assigned roles except default user accounts in oracle?

Basically On TEST Environment how to take the backup of privileges and to generate grant statement of all objects owned by users except defaults in oracle before DB refresh from PROD to TEST.基本上在 TEST 环境中,如何在数据库从 PROD 刷新到 TEST 之前备份权限生成用户拥有的所有对象的授权语句,oracle 中的默认值除外。

So, we can revert back to those privileges after refresh to avoid any permission denied issue.因此,我们可以在刷新后恢复到这些权限以避免任何权限被拒绝的问题。

And also Looking for an alternate Solution of " dbms_metadata.get_dependent_ddl " and " dbms_metadata.get_granted_ddl " package.并且还在寻找“ dbms_metadata.get_dependent_ddl ”和“ dbms_metadata.get_granted_ddl ”package 的替代解决方案。 As it takes lots of time and generates many duplicate statements.因为它需要大量时间并生成许多重复的语句。

Generate the Grant Code statement script of all schemas except default accounts生成除默认账户外的所有模式的 Grant Code 语句脚本

set long 20000 longchunksize 20000 pagesize 0 linesize 1000 feedback off verify off trimspool on

spool file_name.sql
select 'grant '||granted_role||' to '||grantee||';' from DBA_ROLE_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_$database))
union all
select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee||';' from DBA_TAB_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_$database))
union all
select 'grant '||privilege||' to '||grantee||';' from DBA_SYS_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_$database))
union all
select 'grant '||privilege||' ('||column_name||') '||' on '||owner||'.'||table_name||' to '||grantee||';' from DBA_COL_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_$database));
spool off

To check the List of assigned roles.检查分配的角色列表。

select granted_role from DBA_ROLE_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_$database));

To generate the grant privileges statement of roles.生成角色的授予权限语句。

set long 20000 longchunksize 20000 pagesize 0 linesize 1000 feedback off verify off trimspool on

spool file_name.sql
select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee||';' from DBA_TAB_PRIVS where grantee in (select granted_role from DBA_ROLE_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_$database)));
spool off

I'm trying to put this in a sql script and spool the output but I'm getting errors that the table does not exist.我试图把它放在一个 sql 脚本中并假脱机输出,但我收到表不存在的错误。

select 'grant '||granted_role||'选择'授予'||granted_role||' to '||grantee||';'到'||受赠人||';' from DBA_ROLE_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_)) * ERROR at line 1: ORA-00942: table or view does not exist从 DBA_ROLE_PRIVS where grantee in (SELECT usr.username FROM sys.dba_users usr WHERE usr.created > (SELECT created FROM sys.v_)) * 第 1 行出现错误:ORA-00942:表或视图不存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM