You are on page 1of 3

Oracle - Backup and Restore

Preparing for backup and restore


First, grant "create any directory" to the user, in this example, "MVAULT":
C:\>SET ORACLE_HOME=G:\app\admin\product\11.2.0\dbhome_1
C:\> sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 17 13:43:08 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> connect sys/password as sysdba
SQL> grant create any directory to MVAULT;.
SQL> grant EXP_FULL_DATABASE to MVAULT;
SQL> grant IMP_FULL_DATABASE to MVAULT;
SQL> exit

Next login as MVAULT and create the directory where you want the backup. The backup directory should already
exist:
C:\> sqlplus MVAULT/ MVAULT
SQL> create or replace directory mybackup_dir as 'C:\db_backup;
SQL> exit
[NOTE: Directory db_backup must exist in C:\ before executing above command]

Oracle Backup (expdp)


C:\> expdp MVAULT/MVAULT schemas= MVAULT directory=mybackup_dir
dumpfile= MVAULT_BKP.dmp logfile= MVAULT_LOG.log
Starting " MVAULT"."SYS_EXPORT_SCHEMA_01": MVAULT/**** schemas= MVAULT directory=mybackup_dir
dumpfile= MVAULT_BKP.dmp logfile= MVAULT_LOG.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
...
Total estimation using BLOCKS method: 14.20 GB
...
. . exported " MVAULT"."PT_DATASOURCE_RECORD" 1.025 GB 10743004 rows
. . exported " MVAULT"."PT_PROPERTY" 384.1 MB 2768318 rows
...

Oracle Restore (impdp)


COPY THE FILE MVAULT_BKP.dmp from EXPORTED MACHINE to MACHINE ON WHICH YOU WANT TO
IMPORT
C:\> sqlplus / as sysdba
SQL> drop user MVAULT CASCADE;
SQL> create user MVAULT identified by MVAULT;.
SQL> GRANT ALL PRIVILEGES TO MVAULT;
SQL> exit

[oracle]$ impdp MVAULT/ MVAULT schemas= MVAULT directory=mybackup_dir


dumpfile= MVAULT_BKP.dmp logfile= MVAULT_LOG.log
Import: Release 10.2.0.1.0 - 64bit Production on Saturday, 17 March, 2007 20:26:57
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "PALANTIR_USER"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "PALANTIR_USER"."SYS_IMPORT_SCHEMA_01": palantir_user/***** schemas=palantir_user
directory=dmp_dir dumpfile=palantir_031707.dmp logfile=imp_palantir_031707.log*
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC
ORA-31684: Object type TYPE:"PALANTIR_USER"."SGYTPCSEL" already exists
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "PALANTIR_USER"."PLAN_TABLE" exists. All dependent metadata and data will be skipped due
to table_exists_action of skip
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "PALANTIR_USER"."PT_DATASOURCE" 7.261 GB 638809 rows
. . imported "PALANTIR_USER"."PT_MEDIA" 1.688 GB 970442 rows
. . imported "PALANTIR_USER"."PT_DATASOURCE_RECORD" 1.025 GB 10743004 rows
. . imported "PALANTIR_USER"."PT_PROPERTY" 384.1 MB 2768318 rows
...

Some dumps are done as one user and imported as another. If you are not importing as the same user, then you
need to explicitly state this by adding the following parameter to your command line:
REMAP_SCHEMA=palantir_user:new_user
Thus the total command line would look as follows:
[oracle]$ impdp palantir_user/password schemas=palantir_user directory=dmp_dir
dumpfile=palantir_031707.dmp logfile=imp_palantir_031707.log REMAP_SCHEMA=palantir_user:new_user
In addition, if you are switching tablespaces, you'll need to remap tablespaces:

REMAP_TABLESPACE=support:users
Lastly, always run dbms stats after an imp:
[oracle]$ . oraenv
ORACLE_SID = oracle ? oracle
[oracle]$ sqlplus new_user/password
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Feb 17 17:05:17 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> exec dbms_stats.gather_schema_stats('new_user');
Note - the 'new_user' argument is the schema name to run statistics against. This is usually the same as your
username.

You might also like