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)命令举例(下)
  • 相关阅读:
    HTML_严格模式与混杂模式
    不要和一种编程语言厮守终生:为工作正确选择(转)
    iOS开发编码建议与编程经验(转)
    UTF-8 和 GBK 的 NSString 相互转化的方法
    UICollectionView 总结
    UIViewController的生命周期及iOS程序执行顺序
    objective-c 中随机数的用法
    clipsToBounds 与 masksToBounds 的区别与联系
    网络请求 代码 系统自带类源码
    iOS CGRectGetMaxX/Y 使用
  • 原文地址:https://www.cnblogs.com/lawlietfans/p/7608151.html
Copyright © 2011-2022 走看看