How to include roles and grants into datapump export

For sure one way to do it, would be this one:

Prepare the parameters file first:

FULL=YES
INCLUDE=SCHEMA:"IN (SELECT 'PUBLIC' FROM DUAL UNION SELECT username FROM dba_users WHERE username in ('DB_USER1','DB_USER2'))"
INCLUDE=PUBLIC_SYNONYM/SYNONYM:"IN (SELECT synonym_name FROM dba_synonyms WHERE owner = 'PUBLIC' AND table_owner in ('DB_USER1','DB_USER2'))"
DIRECTORY=DATA_PUMP_DIR
DUMPFILE=orcl_expdp.dmp
LOGFILE=orcl_expdp.log
INCLUDE=ROLE:"IN (select role from dba_roles where role in (select grantee from dba_tab_privs where grantor in ('DB_USER1','DB_USER2')))" 

And the command to run would be this one:

expdp  \'/ as sysdba\' DIRECTORY=DATA_PUMP_DIR parfile= orcl_full.par

Leave Comment

Your email address will not be published. Required fields are marked *