Centos610-oracle 备份和还原

前言

本文是为基于Centos6.*(linux)系列的Oracle备份和还原的操作记录,其中根据expdp和impdp不同参数可实现不同场景下的导出导入,为不同OS下面的Oracle迁移打下基础。

正文

1.准备工作

  1.0导入账号准备    

create tablespace EXPDP_DATA datafile '/home/oracle/app/oracle/oradata/EXPDP_DATA.dbf' size 100m autoextend on  next 50m maxsize 10240m  extent management local; 

create temporary tablespace EXPDP_TEMP   tempfile '/home/oracle/app/oracle/oradata/EXPDP_TEMP.DBF' size 50m  autoextend on  next 50m maxsize 10240m  extent management local;

create user EXPDP_USER identified by 123456  account unlock default tablespace EXPDP_DATA  TEMPORARY TABLESPACE EXPDP_TEMP; 

grant connect,resource to EXPDP_USER;

   1.1.xshell:oracle账号登录

    mkdir ora_back;

    查看目录:pwd 显示 /home/oracle/ora_back

  1.2oracle新建逻辑目录

    create directory ora_back as '/home/oracle/ora_back/';

    查看目录是否存在

    select * from dba_directories;

    

   1.3逻辑目录账号授权

    grant read,write on directory ora_back to scott;         导出账号目录对象授权(此处备份操作建议使用system账号,本文以scott为例)。

    grant read,write on directory ora_back to EXPDP_USER;   导入账号目录对象授权

   1.4设置oracle导出支持

    exec dbms_metadata_util.load_stylesheets;

    1.5设置导出账号0条记录表支持导出(已设置过,就不需要再次执行)

    select table_name from user_tables where NUM_ROWS=0;

    alter table table1 allocate extend;(设置指定的表支持导出)

    select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;(已有空表添加导出支持)

     1.6新表支持自动导出(已设置过,就不需要再次执行)

    sqlplus:    

      show parameter deferred_segment_creation

      alter system set deferred_segment_creation=false

2.导出导入

  2.1expdp 主要参数说明:

     TABLES=需要导出的表名1,表名2

     TABLESPACES=需要导出的表空间

     VERSION=需要导入的oracle版本号

     SCHEMAS=需要导出的方案列表

     JOB_NAME=导出作业名称

     INCLUDE=需要包含的特定对象

     FULL=Y/N是否需要导出整个库

     DIRECTORY=存储导出文件的目录对象

  2.2导出操作

    linux 终端模式(非sqlplus模式)执行下面导出语句

    expdp scott/orcl directory=ora_back dumpfile=scott_expdp.dmp schemas=scott

    执行结果:

          

3.导入工作

  3.1导入参数

    remap_schema=导出登录账号:导入登陆账号

    dumpfile=dmp备份文件

    table_exists_action=replace对象已存在时采取替换策略(SKIP | APPEND | TRUNCATE | FRPLACE)

    directory=目录对象

    

  3.2导入操作
    linux 终端模式(非sqlplus模式)执行下面导出语句

    impdp EXPDP_USER/123456 directory=ora_back dumpfile=scott_expdp.dmp TABLE_EXISTS_ACTION=REPLACE remap_schema=SCOTT:EXPDP_USER

    执行结果:

      

   3.3导入对比:

      导入前:

         

      导入后:

        

      对比结果表明导出导入操作Ok

4.实际应用

  4.1请参考前面步骤操作。

    

原文地址:https://www.cnblogs.com/oumi/p/12339863.html