Professional Documents
Culture Documents
1.1
Execute the following commands to create a database directory. This directory must point to a valid
directory on the same server as the database: Execute following commands as sysdba.
SQL> CREATE DIRECTORY exp_backup AS '/u01/demo_exp_backup';
Directory created.
SQL> GRANT read, write ON DIRECTORY exp_backup TO scott;
Grant succeeded.
PS: Oracle introduced a default directory from 10g R2, called DATA_PUMP_DIR, that can be used:
SQL> SELECT directory_path FROM dba_directories WHERE directory_name =
EXP_BACKUP;
DIRECTORY_PATH
------------------------------------------------------------------------------/u01/demo_exp_backup
For oracle 10G, we are using data pump utility for export and import of data. For
Oracle 9i, we are using exp/imp utility.
DB_NAME: DEMO
TNS Service name: DEMO
Data Pump Directories for backup: EXP_BACKUP
Location of backup: /u01/demo_exp_backup
Userid/Password to export/import: sys/******** as sysdba
1.2 DATABASE LEVEL:
Assuming example for emp table under scott schema. You can table more than one table backup using
comma operator to separate tablenames.
For Oracle 9i:
$ cd $ORACLE_HOME
$ exp FILE=DBNAME_SCOTT_EMP_export_sysdate.dmp LOG=
DBNAME_SCOTT_EMP_export_sysdate.log OWNER=SCOTT TABLES=EMP
$ exp FILE=DBNAME_SCOTT_EMP-DEPT_export_sysdate.dmp LOG= DBNAME_SCOTT_EMPDEPT_export_sysdate.log OWNER=SCOTT TABLES=EMP,DEPT
For Oracle 10G:
$expdp DIRECTORY= EXP_BACKUP dumpfile=DBNAME_tablename_export.dmp
Expdp/impdp examples:
The exclude and include parameters availbale with expdp,impdp can be used as metadata filters so that
one can specify any objects like tables,indexes,triggers, procedure to be excluded or included during
export or import operation
syntax:
expdp <other_parameters> SCHEMAS=scott EXCLUDE=SEQUENCE,TABLE:IN (EMP,DEPT);
impdp <other_parameters> SCHEMAS=scott INCLUDE=PACKAGE,FUNCTION,
PROCEDURE,TABLE:=EMP
Examples of operator-usage:
EXCLUDE=SEQUENCE
or:EXCLUDE=TABLE:IN (EMP,DEPT)
or:EXCLUDE=INDEX:= MY_INDX
or:INCLUDE=PROCEDURE:LIKE MY_PROC_%
or:INCLUDE=TABLE:> E
The parameter can also be stored in a par (parameter file) as shown
Parameter file:exp.par
DIRECTORY = EXP_BACKUP
DUMPFILE = exp_tab.dmp
LOGFILE = exp_tab.log
SCHEMAS = scott
INCLUDE = TABLE:IN (EMP, DEPT)
expdp system/manager parfile=exp.par
If parameter file is not used then in unix special care needs to be taken in syntax of expdp and impdp, in
particular all the single quotes and double quotes needs to be preceded with the special character
\ .The syntax for windows and unix
Windows:
D:\> expdp system/manager DIRECTORY=EXP_BACKUP DUMPFILE=exp_tab.dmp
LOGFILE=exp_tab.log SCHEMAS=scott INCLUDE=TABLE:\IN (EMP, DEP)\
Unix:
% expdp system/manager DIRECTORY=EXP_BAKUP DUMPFILE=exp_tab.dmp
LOGFILE=exp_tab.log SCHEMAS=scott INCLUDE=TABLE:\IN \(\EMP\, \DEP\\)\