zoukankan      html  css  js  c++  java
  • Oracle 11g 数据库 expdp/impdp 全量导入导出

     

    从一个用户导出导入到另一个用户

    问题

    环境:oracle 11g; redhat 6

    usera是具有DBA权限,密码为usera

    全量导出usera用户下的所有内容,并导入到新建的userb用户

    解决

    创建Directory: create or replace directory DUMP_DIR_D as '/home/oracle/rhuser/oracledmp';

    1、重新测试之前要恢复环境

    DROP USER userb cascade;
    drop tablespace tbsfsj including contents and datafiles;

    2、创建表空间和用户及赋权

    create TABLESPACE tbsfsj DATAFILE '/home/oracle/rhuser/tbsfsj.dbf'  -- redhat user
    size 10M autoextend on maxsize 30G;
    
    create user userb identified by userb default tablespace tbsfsj;
    -- grant connect, resource, DATAPUMP_IMP_FULL_DATABASE, DATAPUMP_EXP_FULL_DATABASE
    -- to userb;
    GRANT dba to userb;
    grant read, write on directory DUMP_DIR_D to userb;

    3、schemas方式导出

    expdp usera/usera directory=DUMP_DIR_D dumpfile=exp1.dmp logfile=exp1.log schemas=usera

    4、schemas方式导入

    impdp userb/userb schemas=usera directory=DUMP_DIR_D dumpfile=imp1.dmp logfile=imp1.log remap_schema=usera:userb

    核对

    -- 以新用户userb登录,检查是否成功导入
    
    SQL> select count(*) from user_tables;
    
      COUNT(*)
    ----------
           126
    
    SQL> select count(*) from user_views;
    
      COUNT(*)
    ----------
       1
    
    SQL> select count(*) from user_sequences;
    
      COUNT(*)
    ----------
      32
    
    SQL> select count(*) from user_triggers;
    
      COUNT(*)
    ----------
       0

    脚本

    $ ssh root@remote_server_ip
    
    $ su - oracle
    
    $ cd /home/oracle/rhuser
    $ cat exp1_schemas_usera.sh
    #!/bin/bash
    if [ "$1" = '' ]
    then
        filename=defaultexp
    else
        filename=$1
    fi
    dumppathprefix="/home/oracle/rhuser/oracledmp"
    
    starttime=`date +'%s'`
    expdp usera/usera directory=DUMP_DIR_D dumpfile=$filename.dmp logfile=$filename.log schemas=usera
    endtime=`date +'%s'`
    
    res="本次运行时间: "$((endtime-starttime))"s"
    echo $res>>"$dumppathprefix/$filename.log"
    echo $res
    $ cat imp1_schemas_usera2fsj.sh
    #!/bin/bash
    if [ "$1" = '' ]
    then
        filename=defaultimp
    else
        filename=$1
    fi
    if [ "$2" = "" ]
    then
        dmp=exp1_schemas
    else
        dmp=$2
    fi
    dumppathprefix="/home/oracle/rhuser/oracledmp"
    
    starttime=`date +'%s'`
    impdp userb/userb schemas=usera directory=DUMP_DIR_D  dumpfile=$dmp.dmp logfile=$filename.log  remap_schema=usera:userb
    endtime=`date +'%s'`
    
    res="本次运行时间: "$((endtime-starttime))"s"
    echo $res>>"$dumppathprefix/$filename.log"
    echo $res

    讨论

    What Is Data Pump Export?

    Data Pump Export (hereinafter referred to as Export for ease of reading) is a utility for unloading data and metadata into a set of operating system files called a dump file set. The dump file set can be imported only by the Data Pump Import utility. The dump file set can be imported on the same system or it can be moved to another system and loaded there.

    The dump file set is made up of one or more disk files that contain table data, database object metadata, and control information. The files are written in a proprietary, binary format. During an import operation, the Data Pump Import utility uses these files to locate each database object in the dump file set.

    Because the dump files are written by the server, rather than by the client, the database administrator (DBA) must create directory objects that define the server locations to which files are written. See "Default Locations for Dump, Log, and SQL Files" for more information about directory objects.

    Data Pump Export enables you to specify that a job should move a subset of the data and metadata, as determined by the export mode. This is done using data filters and metadata filters, which are specified through Export parameters. See "Filtering During Export Operations".

    To see some examples of the various ways in which you can use Data Pump Export, refer to "Examples of Using Data Pump Export".

    Export provides different modes for unloading different portions of the database. The mode is specified on the command line, using the appropriate parameter. The available modes are described in the following sections:

    • "Full Export Mode"
    • "Schema Mode"
    • "Table Mode"
    • "Tablespace Mode"
    • "Transportable Tablespace Mode"

    The mode is specified on the command line, using the appropriate parameter. The available modes are described in the following sections:

    • "Full Import Mode"
    • "Schema Mode"
    • "Table Mode"
    • "Tablespace Mode"
    • "Transportable Tablespace Mode"

    参考

    1. Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(上)
    2. Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下)
  • 相关阅读:
    ES5新特性:理解 Array 中增强的 9 个 API
    ios
    Jquery异步 Deferred Object
    ES5中新增的Array方法详细说明
    Chart
    Angular常用语句
    vticker.js--垂直滚动插件
    <css系列>之css--float总结
    理解boot.img与静态分析Android/linux内核
    理解竞争条件( Race condition)漏洞
  • 原文地址:https://www.cnblogs.com/lcword/p/11775634.html
Copyright © 2011-2022 走看看