备份和恢复用户角色oracle

时间:2017-09-28 12:13:29

标签: oracle backup roles restore settings

是否可以使用脚本备份用户角色(而不是整个数据库),或者在Oracle 11中是否有一些备份功能? 我希望备份用户并稍后通过脚本恢复它们,这应该用作备份错误配置的备份。

DBA_USERS DBA_ROLES DBA_ROLE_PRIVS ROLE_TAB_PRIVS SESSION_PRIVS SESSION_ROLES TABLE_PRIVILEGES

目前,我可以查询或创建存储大多数用户设置的表的视图。但是,从该源创建角色并授予权限涉及大量文本转换。 视图>存储到文件> concat将它们转换为create / grant>在命令行上执行脚本

是否有另一种方法可以导出和导入用户权限和角色以及将它们分配给表的方式?或者我可以简单地备份和恢复此问题中提到的表而不会制动数据库吗?

1 个答案:

答案 0 :(得分:0)

您可以使用数据泵来备份它们:

expdp cyrille/*******@//localhost:1521/orclpdb \
dumpfile=exp_USER_GRANTS.dmp \
logfile=exp_USER_GRANTS.log \
directory=MY_DIRECTORY \
INCLUDE=GRANT \
INCLUDE=OBJECT_GRANT \
INCLUDE=SYSTEM_GRANT \
INCLUDE=ROLE_GRANT \
INCLUDE=USER \
full=y

Export: Release 12.2.0.1.0 - Production on Wed Sep 27 11:35:35 2017

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Starting "*****"."SYS_EXPORT_FULL_01":  cyrille/********@//localhost:1521/orclpdb dumpfile=exp_USER_GRANTS.dmp logfile=exp_USER_GRANTS.log directory=MY_DIRECTORY INCLUDE=GRANT INCLUDE=OBJECT_GRANT INCLUDE=SYSTEM_GRANT INCLUDE=ROLE_GRANT INCLUDE=USER full=y
Processing object type DATABASE_EXPORT/SYS_USER/USER
Processing object type DATABASE_EXPORT/SCHEMA/USER
Processing object type DATABASE_EXPORT/GRANT/SYSTEM_GRANT/PROC_SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/GRANT/SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/ROLE_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/DIRECTORY/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/GRANT/PROCOBJ_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/JAVA_CLASS/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/JAVA_RESOURCE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/OPERATOR/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/INDEXTYPE/GRANT/OWNER_GRANT/OBJECT_GRANT
Master table "CYRILLE"."SYS_EXPORT_FULL_01" successfully loaded/unloaded
******************************************************************************
Dump file set for CYRILLE.SYS_EXPORT_FULL_01 is:
  /u01/exp_USER_GRANTS.dmp

从该转储中,您还可以使用sqlfile参数生成脚本:

impdp cyrille/******@//localhost:1521/orclpdb  dumpfile=exp_USER_GRANTS.dmp  logfile=imp_USER_GRANTS.log  directory=MY_DIRECTORY sqlfile=my_script.sql

这将生成带有脚本的sql文件。