Oracle DB 10g+ Backup and Restore

Here's the steps for backup a db schema, which just applies to oracle database.
Suppose the osl schema is osl/welcome1, and the ORACLE_SID=orcl, then:

  • Export Schema (backup)
    • First, create directory expdir
      SQL> CONNECT system/welcome1
      SQL> CREATE OR REPLACE DIRECTORY expdir AS '/home/oracle/exp_data';
      SQL> GRANT READ,WRITE ON DIRECTORY expdir TO PUBLIC;

    • Then use expdp
      $ORACLE_HOME/bin/expdp osl/welcome1@orcl DUMPFILE=osl_bak.dmp DIRECTORY=expdir SCHEMAS=osl
    • Then you can copy the /home/oracle/exp_data/osl_bak.dmp to some other directory or some other machine to backup it.

  • Import Schema (restore)
    • First, create directory expdir (if you already created it, plz ignore this step)
    • Then delete the osl schema (beware of this step !!!)
      SQL> CONNECT system/welcome1
      SQL> DROP USER osl CASCADE;
    • Then use impdp
      $ORACLE_HOME/bin/
      impdp osl/welcome1 DIRECTORY=expdir DUMPFILE=osl_bak.dmp

你可能感兴趣的:(oracle,sql)