You are on page 1of 10

26.

LOGICAL BACKUP (IMPORT AND EXPORT )

1. TABLE LEVEL: SAME USER AND SAME TABLESPACE


---------------------------------------------

A) MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE


B) MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE

TEST DATABASE (DB32): PROD DATABASE (DB31):

1. TABLE: FRIENDS 1. TABLE: NOT AVAILABLE


2. USER: FM 2. USER : FM
3. TABLESPACE: PROD 3. TABLESAPCE: PROD

METHOD FIRST (SAME USER AND SAME TABLESPACE):


--------------------------------------------

DB31: IMPORT MACHINE:


---------------------

SQL> create user fm identified by fm;

User created.

SQL> create tablespace prod datafile '/u01/app/oracle/oradata/prod/fm01.dbf' size


20m;

Tablespace created.

DB32: EXPORT MACHINE:


---------------------

SQL> create user fm identified by fm;

User created.

SQL> create tablespace prod datafile '/u01/app/oracle/oradata/test/fm01.dbf' size


20m;

Tablespace created.

SQL> grant connect, resource to fm identified by fm;

Grant succeeded.

SQL> grant create table, create session, create sequence to fm;

Grant succeeded.

[oracle@db32 ~]$ cd /u01

[oracle@db32 u01]$ ls

[oracle@db32 u01]$ mkdir expdp

SQL> create directory expd as '/u01/expdp';

Directory created.
DB31: IMPORT MACHINE:
--------------------

[oracle@db31 ~]$ cd /u01

[oracle@db31 u01]$ ls

[oracle@db31 u01]$ mkdir impdp

SQL> create directory impd as '/u01/impdp';

Directory created.

A) MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE:


---------------------------------------------------------------

[oracle@db32 ~]$ expdp directory=expd dumpfile=hrtbl.dmp tables=fm.friends

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_01": /******** AS SYSDBA directory=expd
dumpfile=hrtbl.dmp tables=fm.friends
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "FM"."FRIENDS" 5.656 KB 15 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
/u01/expdp/hrtbl.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 00:42:29

[oracle@db32 ~]$ cd /u01

[oracle@db32 u01]$ ls

[oracle@db32 u01]$ cd expdp

[oracle@db32 expdp]$ ls

[oracle@db32 expdp]$ scp hrtbl.dmp oracle@192.168.139.31:/u01/impdp

B) MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE:


----------------------------------------------------------------

[oracle@db31 ~]$ cd /u01

[oracle@db31 u01]$ ls

[oracle@db31 u01]$ cd impdp

[oracle@db31 impdp]$ ls

[oracle@db31 impdp]$ impdp directory=impd dumpfile=hrtbl.dmp tables=fm.friends


Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TABLE_01": /******** AS SYSDBA directory=impd
dumpfile=hrtbl.dmp tables=fm.friends
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "FM"."FRIENDS" 5.656 KB 15 rows
Job "SYS"."SYS_IMPORT_TABLE_01" successfully completed at 00:57:03

[oracle@db31 ~]$ !sql

SQL> conn fm/fm

SQL> select * from tab;

SQL> select * from friends;

=================================================================================TH
E
END===============================================================================

2. TABLE LEVEL: SAME USER AND DIFFENRENT TABLESPACE:


---------------------------------------------------

A) MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE


B) MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE

TEST DATABASE (DB32): PROD DATABASE (DB31):

1. TABLE: FRIENDS 1. TABLE: NOT AVAILABLE


2. USER: FM 2. USER : FM
3. TABLESPACE: PROD 3. TABLESAPCE:
TEST(Diffenent)

METHOD SECOND (SAME USER AND DIFFENRENT TABLESPACE):


---------------------------------------------------

DB31: IMPORT MACHINE:


--------------------

SQL> create tablespace test datafile '/u01/app/oracle/oradata/prod/fm02.dbf' size


20m;

Tablespace created.

DB32: EXPORT MACHINE


-------------------

[oracle@db32 ~]$ cd /u01


[oracle@db32 u01]$ ls

[oracle@db31 ~]$ !sql

[oracle@db32 u01]$ mkdir expdp1

SQL> create directory expd2 as '/u01/expdp1';

Directory created.

DB31: IMPORT MACHINE:


---------------------

[oracle@db31 ~]$ cd /u01

[oracle@db31 u01]$ ls

[oracle@db31 ~]$ !sql

[oracle@db31 u01]$ mkdir impdp1

SQL> create directory imp2 as '/u01/impdp1';

Directory created.

A) MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE:


----------------------------------------------------------------

[oracle@db32 ~]$ expdp directory=expd2 dumpfile=hrtbl1.dmp tables=fm.schoolmates

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_01": /******** AS SYSDBA directory=expd2
dumpfile=hrtbl1.dmp tables=fm.schoolmates
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "FM"."SCHOOLMATES" 5.531 KB 5 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
/u01/expdp1/hrtbl1.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 01:43:50

[oracle@db32 expdp1]$ scp hrtbl1.dmp oracle@192.168.139.31:/u01/impdp1


oracle@192.168.139.31's password:
hrtbl1.dmp 100% 84KB 84.0KB/s 00:00

B) MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE:


---------------------------------------------------------------

[oracle@db31 impdp1]$ impdp directory=imp2 dumpfile=hrtbl1.dmp


tables=fm.schoolmates remap_tablespace=fm:test
Import: Release 11.2.0.1.0 - Production on Sun Aug 20 01:45:36 2017

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

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TABLE_01": /******** AS SYSDBA directory=imp2
dumpfile=hrtbl1.dmp tables=fm.schoolmates remap_tablespace=fm:test
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "FM"."SCHOOLMATES" 5.531 KB 5 rows
Job "SYS"."SYS_IMPORT_TABLE_01" successfully completed at 01:45:45

=================================================================================TH
E
END===============================================================================

3. TABLE LEVEL: DIFFENRENT USER AND SAME TABLESPACE:


----------------------------------------------------

A)MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE


B)MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE

TEST DATABASE (DB32): PROD DATABASE (DB31):

1. TABLE:CLASSMATES 1. TABLE: NOT AVAILABLE


2. USER: FM 2. USER : FM2 (Diffenrent)
3. TABLESPACE: PROD 3. TABLESAPCE: PROD

METHOD THIRD (DIFFENRENT USER AND SAME TABLESPACE):


---------------------------------------------------

DB31: IMPORT MACHINE:


---------------------

SQL> create user fm2 identified by fm2;

User created.

SQL> grant connect, resource to fm2 identified by fm2;

Grant succeeded.

SQL> grant create table, create session, create sequence to fm2;

Grant succeeded.

DB32: EXPORT MACHINE:


--------------------

[oracle@db32 ~]$ cd /u01


[oracle@db32 u01]$ ls

[oracle@db32 u01]$ mkdir expdp2

[oracle@db32 ~]$ !sql

SQL> create directory expd3 as '/u01/expdp2';

Directory created.

DB31: IMPORT MACHINE:


--------------------

[oracle@db31 ~]$ cd /u01

[oracle@db31 u01]$ ls

[oracle@db31 u01]$ mkdir impdp2

[oracle@db31 ~]$ !sql

SQL> create directory impd3 as '/u01/impdp2';

Directory created.

A) MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE:


---------------------------------------------------------------

[oracle@db32 ~]$ expdp directory=expd3 dumpfile=hrtbl2.dmp tables=fm.classmates

Export: Release 11.2.0.1.0 - Production on Sun Aug 20 02:10:57 2017

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

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_01": /******** AS SYSDBA directory=expd3
dumpfile=hrtbl2.dmp tables=fm.classmates
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "FM"."CLASSMATES" 5.523 KB 5 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
/u01/expdp2/hrtbl2.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 02:11:10

[oracle@db32 expdp2]$ scp hrtbl2.dmp oracle@192.168.139.31:/u01/impdp2


oracle@192.168.139.31's password:
hrtbl2.dmp 100% 84KB 84.0KB/s 00:00

B) MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE:


----------------------------------------------------------------
[oracle@db31 impdp2]$ impdp directory=impd3 dumpfile=hrtbl2.dmp
tables=fm.classmates remap_schema=fm:fm2

Import: Release 11.2.0.1.0 - Production on Sun Aug 20 02:17:54 2017

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

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TABLE_01": /******** AS SYSDBA directory=impd3
dumpfile=hrtbl2.dmp tables=fm.classmates remap_schema=fm:fm2
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "FM2"."CLASSMATES" 5.523 KB 5 rows
Job "SYS"."SYS_IMPORT_TABLE_01" successfully completed at 02:18:01

[oracle@db31 ~]$ !sql

SQL> conn fm2/fm2


Connected.
SQL> select * from tab;

SQL> select * from classmates;

=================================================================================TH
E
END===============================================================================

4. TABLE LEVEL: DIFFENRENT USER AND DIFFENRENT TABLESPACE


---------------------------------------------------------

A)MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE


B)MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE

TEST DATABASE (DB32): PROD DATABASE (DB31):

1. TABLE:CITIES 1. TABLE: NOT AVAILABLE


2. USER: FM 2. USER : FM2
3. TABLESPACE: PROD 3. TABLESAPCE: TEST

METHOD FOURTH (DIFFENRENT USER AND DIFFENRENT TABLESPACE):


---------------------------------------------------------

DB31: IMPORT MACHINE:


---------------------

SQL> alter user fm2 identified by fm2 default tablespace test;

User altered.

DB32: EXPORT MACHINE:


--------------------
SQL> alter user fm identified by fm default tablespace prod;

User altered.

[oracle@db32 ~]$ cd /u01

[oracle@db32 u01]$ ls

[oracle@db32 u01]$ mkdir expdp3

[oracle@db32 ~]$ !sql

SQL> create directory expd4 as '/u01/expdp3';

Directory created.

DB31: IMPORT MACHINE:


--------------------

[oracle@db31 ~]$ cd /u01

[oracle@db31 u01]$ ls

[oracle@db31 u01]$ mkdir impdp3

[oracle@db31 ~]$ !sql

SQL> create directory impd4 as '/u01/impdp3';

Directory created.

A) MACHINE DB32 (SOURCE DATABASE 192.168.139.32) EXPORT MACHINE:


----------------------------------------------------------------

[oracle@db32 ~]$ expdp directory=expd4 dumpfile=hrtbl3.dmp tables=fm.cities

Export: Release 11.2.0.1.0 - Production on Sun Aug 20 02:47:35 2017

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

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_01": /******** AS SYSDBA directory=expd4
dumpfile=hrtbl3.dmp tables=fm.cities
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "FM"."CITIES" 5.562 KB 8 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
/u01/expdp3/hrtbl3.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 02:48:00
[oracle@db32 expdp3]$ scp hrtbl3.dmp oracle@192.168.139.31:/u01/impdp3
oracle@192.168.139.31's password:
hrtbl3.dmp 100% 84KB 84.0KB/s 00:00

B) MACHINE DB31 (TARGET DATABASE 192.168.139.31) IMPORT MACHINE:


---------------------------------------------------------------

[oracle@db31 impdp3]$ impdp directory=impd4 dumpfile=hrtbl3.dmp tables=fm.cities


remap_schema=fm:fm2 remap_tablespace=prod:test

Import: Release 11.2.0.1.0 - Production on Sun Aug 20 02:53:09 2017

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

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 -


Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYS"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_TABLE_01": /******** AS SYSDBA directory=impd4
dumpfile=hrtbl3.dmp tables=fm.cities remap_schema=fm:fm2 remap_tablespace=prod:test
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "FM2"."CITIES" 5.562 KB 8 rows
Job "SYS"."SYS_IMPORT_TABLE_01" successfully completed at 02:53:22

[oracle@db31 ~]$ !sql

SQL> conn fm2/fm2


Connected.
SQL> select * from tab;

SQL> select * from cities;

ID NAME
---------- --------------------
1 hyderabad
2 mumbai
3 pune
4 banglore
5 chennai
6 dehli
7 kolkata
8 noida

=================================================================================TH
E
END===============================================================================

You might also like