logical backup

13
LOGICAL BACKUP Posted by Narashim Reddy .R on August 16, 2009 Rate This Levels of Logical backup: 1.Database 2.Tablespace, Transport tablespace 3.User/Schema 4.Object(table) [oracle@ reddy ~]$ exp help=y Note:To take Logical Backup Database must be open. To export the entire database to a single file dba.dmp in the current directory: [oracle@ reddy ~]$ exp system/manager full=y file=dba.dmp log=dba.log consistent=y To import the full database exported in the example above [oracle@ reddy ~]$ imp system/manager full=y file=dba.dmp To Dump a single schema to disk (we use the Scott example schema here) login to server which has an Oracle client: [oracle@ reddy ~]$ exp system/manager file=scott.dmp owner=scott Export: Release 10.2.0.1.0 – Production on Fri Nov 7 15:41:31 2008 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production With the Partitioning, OLAP and Data Mining options Export done in US7ASCII character set and AL16UTF16 NCHAR character set About to export specified users … . exporting pre-schema procedural objects and actions . exporting foreign function library names for user SCOTT . exporting PUBLIC type synonyms . exporting private type synonyms . exporting object type definitions for user SCOTT About to export SCOTT‘s objects …

Upload: printesh-patel

Post on 14-Nov-2015

3 views

Category:

Documents


0 download

DESCRIPTION

Logical_backup

TRANSCRIPT

  • LOGICAL BACKUP

    Posted by Narashim Reddy .R on August 16, 2009

    Rate This

    Levels of Logical backup:

    1.Database

    2.Tablespace, Transport tablespace

    3.User/Schema

    4.Object(table)

    [oracle@ reddy ~]$ exp help=y

    Note:To take Logical Backup Database must be open.

    To export the entire database to a single file dba.dmp in the current

    directory:

    [oracle@ reddy ~]$ exp system/manager full=y

    file=dba.dmp log=dba.log consistent=y

    To import the full database exported in the example above

    [oracle@ reddy ~]$ imp system/manager full=y file=dba.dmp

    To Dump a single schema to disk (we use the Scott example schema here)

    login to server which has an Oracle client:

    [oracle@ reddy ~]$ exp system/manager file=scott.dmp owner=scott

    Export: Release 10.2.0.1.0 Production on Fri Nov 7 15:41:31 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export done in US7ASCII character set and AL16UTF16 NCHAR character set

    About to export specified users

    . exporting pre-schema procedural objects and actions

    . exporting foreign function library names for user SCOTT

    . exporting PUBLIC type synonyms

    . exporting private type synonyms

    . exporting object type definitions for user SCOTT

    About to export SCOTTs objects

  • . exporting database links

    . exporting sequence numbers

    . exporting cluster definitions

    . about to export SCOTTs tables via Conventional Path

    . . exporting table BONUS 0 rows exported

    . . exporting table DEPT 4 rows exported

    . . exporting table EMP 14 rows exported

    . . exporting table SALGRADE 5 rows exported

    . exporting synonyms

    . exporting views

    . exporting stored procedures

    . exporting operators

    . exporting referential integrity constraints

    . exporting triggers

    . exporting indextypes

    . exporting bitmap, functional and extensible indexes

    . exporting posttables actions

    . exporting materialized views

    . exporting snapshot logs

    . exporting job queues

    . exporting refresh groups and children

    . exporting dimensions

    . exporting post-schema procedural objects and actions

    . exporting statistics

    Export terminated successfully without warnings.

    To import all the tables from the exported dump file to the same

    schema(scott schema for example) :

    [oracle@ reddy ~]$ sqlplus scott/tiger

    SQL*Plus: Release 10.2.0.1.0 Production on Fri Nov 7 15:56:58 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    DEPT TABLE

    EMP TABLE

  • BONUS TABLE

    SALGRADE TABLE

    SQL> drop table salgrade;

    Table dropped.

    SQL> drop table bonus;

    Table dropped.

    SQL> drop table emp;

    Table dropped.

    SQL> drop table dept;

    Table dropped.

    SQL> !

    [oracle@ reddy ~]$ imp system/manager file=scott.dmp fromuser=scott

    touser=scott

    Import: Release 10.2.0.1.0 Production on Fri Nov 7 16:01:55 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.01 via conventional path

    import done in US7ASCII character set and AL16UTF16 NCHAR character set

    . importing SCOTTs objects into SCOTT

    . . importing table BONUS 0 rows imported

    . . importing table DEPT 4 rows imported

    . . importing table EMP 14 rows imported

    . . importing table SALGRADE 5 rows imported

    About to enable constraints

    Import terminated successfully without warnings.

    [oracle@ reddy ~]$ sqlplus scott/tiger

    SQL*Plus: Release 10.2.0.1.0 Production on Fri Nov 7 16:02:11 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    DEPT TABLE

    BONUS TABLE

  • EMP TABLE

    SALGRADE TABLE

    To import all the tables from the exported dump file to the different

    schema:

    [oracle@ reddy ~]$ sqlplus reddy/ reddy

    SQL*Plus: Release 10.2.0.1.0 Production on Fri Nov 7 16:24:07 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    no rows selected

    SQL> !

    [oracle@ reddy ~]$ imp system/manager file=scott.dmp fromuser=scott touser=

    reddy

    Import: Release 10.2.0.1.0 Production on Fri Nov 7 16:27:11 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.01 via conventional path

    import done in US7ASCII character set and AL16UTF16 NCHAR character set

    . importing SCOTTs objects into reddy

    . . importing table BONUS 0 rows imported

    . . importing table DEPT 4 rows imported

    . . importing table EMP 14 rows imported

    . . importing table SALGRADE 5 rows imported

    About to enable constraints

    Import terminated successfully without warnings.

    [oracle@ reddy ~]$ exit

    exit

    SQL> show user

    USER is reddy

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    DEPT TABLE

    BONUS TABLE

  • EMP TABLE

    SALGRADE TABLE

    To export specific tables to disk.

    Login to server which has an Oracle client:

    [oracle@ reddy ~]$ exp system/manager

    file=expdat.dmp tables=(scott.emp,scott.dept)

    Export: Release 10.2.0.1.0 Production on Fri Nov 7 16:53:04 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export done in US7ASCII character set and AL16UTF16 NCHAR character set

    About to export specified tables via Conventional Path

    Current user changed to SCOTT

    . . exporting table EMP 14 rows exported

    . . exporting table DEPT 4 rows exported

    Export terminated successfully without warnings.

    To import the dept and emp tables from the scott schema:

    [oracle@ reddy ~]$ sqlplus scott/tiger

    SQL*Plus: Release 10.2.0.1.0 Production on Fri Nov 7 17:00:24 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    DEPT TABLE

    BONUS TABLE

    EMP TABLE

    SALGRADE TABLE

    SQL> drop table emp;

    Table dropped.

    SQL> drop table dept;

    Table dropped.

    SQL> !

    [oracle@ reddy ~]$ imp system/manager file=expdat.dmp fromuser=scott

    tables=(dept,emp)

  • Import: Release 10.2.0.1.0 Production on Fri Nov 7 17:02:16 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.01 via conventional path

    import done in US7ASCII character set and AL16UTF16 NCHAR character set

    . importing SYSTEMs objects into SYSTEM

    . importing SCOTTs objects into SCOTT

    . . importing table EMP 14 rows imported

    . . importing table DEPT 4 rows imported

    About to enable constraints

    Import terminated successfully without warnings.

    [oracle@ reddy ~]$ sqlplus scott/tiger

    SQL*Plus: Release 10.2.0.1.0 Production on Fri Nov 7 17:02:41 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    DEPT TABLE

    BONUS TABLE

    EMP TABLE

    SALGRADE TABLE

    To import tables and change the owner:

    SQL> conn reddy/ reddy

    Connected.

    SQL> select * from tab;

    no rows selected

    SQL> !

    [oracle@ reddy ~]$ imp system/manager file=expdat.dmp fromuser=scott

    touser= reddy tables=(dept,emp)

    Import: Release 10.2.0.1.0 Production on Fri Nov 7 17:11:17 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

  • With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.01 via conventional path

    import done in US7ASCII character set and AL16UTF16 NCHAR character set

    . importing SCOTTs objects into reddy

    . . importing table EMP 14 rows imported

    . . importing table DEPT 4 rows imported

    About to enable constraints

    Import terminated successfully without warnings.

    [oracle@ reddy ~]$ sqlplus reddy/ reddy

    SQL*Plus: Release 10.2.0.1.0 Production on Fri Nov 7 17:11:32 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> show user

    USER is reddy

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    EMP TABLE

    DEPT TABLE

    To export specific tablespaces to disk.

    Login to server which has an Oracle client:

    SQL> show user

    USER is SYS

    SQL> select tablespace_name from dba_tablespaces;

    TABLESPACE_NAME

    SYSTEM

    UNDOTBS1

    SYSAUX

    TEMP

    USERS

    TMP2

    6 rows selected.

    SQL> !

    [oracle@ reddy ~]$ exp system/manager file=anil.dmp tablespaces=users;

    Export: Release 10.2.0.1.0 Production on Sat Nov 8 12:09:46 2008

  • Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export done in US7ASCII character set and AL16UTF16 NCHAR character set

    About to export selected tablespaces

    For tablespace USERS

    . exporting cluster definitions

    . exporting table definitions

    . . exporting table A1 14 rows exported

    . . exporting table A2 4 rows exported

    . . exporting table DEPT 4 rows exported

    . . exporting table EMP 14 rows exported

    . exporting referential integrity constraints

    . exporting triggers

    Export terminated successfully without warnings.

    To import all the tables from the exported dump file to the schema:

    [oracle@ reddy ~]$ exit

    exit

    SQL> conn anil/anil

    Connected.

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    A1 TABLE

    A2 TABLE

    SQL> drop table a1;

    Table dropped.

    SQL> drop table a2;

    Table dropped.

    SQL> conn reddy/ reddy

    Connected.

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    EMP TABLE

    DEPT TABLE

    SQL> drop table emp;

  • Table dropped.

    SQL> drop table dept;

    Table dropped.

    SQL> conn sys as sysdba

    Enter password:

    Connected.

    SQL> !

    [oracle@ reddy ~]$ sqlplus anil/anil

    SQL*Plus: Release 10.2.0.1.0 Production on Sat Nov 8 12:25:02 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    no rows selected

    SQL> conn reddy/ reddy

    Connected.

    SQL> select * from tab;

    no rows selected

    SQL> !

    [oracle@ reddy ~]$ imp system/manager file=anil.dmp tablespaces=users full=y

    Import: Release 10.2.0.1.0 Production on Sat Nov 8 12:26:12 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.01 via conventional path

    import done in US7ASCII character set and AL16UTF16 NCHAR character set

    . importing SYSTEMs objects into SYSTEM

    . importing ANILs objects into ANIL

    . . importing table A1 14 rows imported

    . . importing table A2 4 rows imported

    . importing reddys objects into reddy

    . . importing table DEPT 4 rows imported

    . . importing table EMP 14 rows imported

    Import terminated successfully without warnings.

    [oracle@ reddy ~]$ sqlplus anil/anil

    SQL*Plus: Release 10.2.0.1.0 Production on Wed Nov 12 12:46:01 2008

  • Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    A2 TABLE

    A1 TABLE

    SQL> !

    [oracle@ reddy ~]$ sqlplus reddy/ reddy

    SQL*Plus: Release 10.2.0.1.0 Production on Wed Nov 12 12:46:29 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Connected to:

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 Production

    With the Partitioning, OLAP and Data Mining options

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

    DEPT TABLE

    EMP TABLE

    TRANSPORTABLE TABLESPACE:

    SQL> create user anil7 identified by anil7

    2 default tablespace test

    3 quota unlimited on test;

    User created.

    SQL> grant connect,resource,create table to anil7;

    Grant succeeded.

    SQL> connect anil7

    Enter password:

    Connected.

    SQL> create table test7 (c1 number) tablespace test;

    Table created.

    SQL> begin

    2 for i in 1..10000 loop

    3 insert into test7 values(i);

    4 end loop;

    5 end;

  • 6 /

    PL/SQL procedure successfully completed.

    SQL> select count(*) from test7;

    COUNT(*)

    -

    10000

    SQL> commit;

    Commit complete.

    SQL> execute dbms_tts.TRANSPORT_SET_CHECK(TEST,TRUE);

    PL/SQL procedure successfully completed.

    SQL> select * from transport_set_violations;

    no rows selected, then it is self contained(not violating).

    SQL> alter tablespace test read only;

    Tablespace altered.

    SQL> !

    [oracle@ reddy ~]$ exp file=test.dmp transport_tablespace=y

    tablespaces=TEST;

    Export: Release 10.2.0.1.0 Production on Thu Dec 11 16:27:23 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Username: sys as sysdba

    Password:

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export done in US7ASCII character set and AL16UTF16 NCHAR character set

    Note: table data (rows) will not be exported

    About to export transportable tablespace meta data.

    For tablespace TEST

    . exporting cluster definitions

    . exporting table definitions

    . . exporting table TEST7

    . exporting referential integrity constraints

    . exporting triggers

    . end transportable tablespace metadata export

    Export terminated successfully without warnings.

    [oracle@ reddy ~]$ scp test.dmp 192.168.1.9:/home/oracle/

    [email protected] password:

    test.dmp 100% 16KB 16.0KB/s 00:00

  • [oracle@ reddy ~]$ scp /home/oracle/tarun/datafiles/test01.dbf

    192.168.1.9:/home/oracle/tarun4/datafiles/

    [email protected] password:

    test01.dbf 100% 40MB 10.0MB/s 00:04

    SQL> alter tablespace test read write;

    Tablespace altered.

    Importing Tablespace in Destination System:

    SQL> create user anil7 identified by anil7;

    User created.

    SQL> grant dba to anil7;

    Grant succeeded.

    SQL> !

    [oracle@ reddy ~]$ imp file=test.dmp transport_tablespace=y

    tablespaces=TEST datafiles=/home/oracle/tarun4/datafiles/test01.dbf;

    Import: Release 10.2.0.1.0 Production on Thu Dec 11 16:30:07 2008

    Copyright (c) 1982, 2005, Oracle. All rights reserved.

    Username: sys as sysdba

    Password:

    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    Production

    With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.01 via conventional path

    About to import transportable tablespace(s) metadata

    import done in US7ASCII character set and AL16UTF16 NCHAR character set

    . importing SYSs objects into SYS

    . importing SYSs objects into SYS

    . importing ANIL7s objects into ANIL7

    . . importing table TEST7

    . importing SYSs objects into SYS

    Import terminated successfully without warnings.

    SQL> alter tablespace test read write;

    Tablespace altered.

    SQL> conn anil7

    Enter password:

    Connected.

    SQL> select * from tab;

    TNAME TABTYPE CLUSTERID

    - -

  • TEST7 TABLE

    SQL> select count(*) from test7;

    COUNT(*)

    -