zoukankan      html  css  js  c++  java
  • oracle 数据库备份还原

    ::备份完整的空数据库,包括:表,视图,序列,函数,包等
    exp aaa/bbb@192.168.1.163/orcl OWNER=aaa file=F:ccc.dmp ROWS=N statistics=none

    ::备份某几个表结构和数据

    exp aaa/bbb@192.168.1.163/orcl  file=F:ccc.dmp tables=(table1,table2) statistics=none

    ::备份表中的分部数据

    exp aaa/bbb@192.168.1.163/orcl   file=F:ccc.dmp tables=table1  query=" where   addvcd like '41%%'"  statistics=none

    ::还原数据
    imp  aaa/bbb@192.168.1.163/orcl  full=y file=F:ccc.dmp

    ::导出所有表前3000条数据

    expdp  aaa/"bbb@123"@orcl  DIRECTORY=DB_EXPDP dumpfile=aaa3000.dmp  include=table query="'where rownum<=3000'" logfile=aaa3000.log ;

    ::还原数据

    impdp  aaaa/aaa@orcl directory=ccc dumpfile=aaa3000 cluster=no remap_schema=aaa:bbb logfile=aaa3000.log

    参考

    使用expdp、impdp和exp、imp时应该注重的事项:

    1、exp和imp是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用。 
    2、expdp和impdp是服务端的工具程序,他们只能在oracle服务端使用,不能在客户端使用。 
    3、imp只适用于exp导出的文件,不适用于expdp导出文件;impdp只适用于expdp导出的文件,而不适用于exp导出文件。 
    4、对于10g以上的服务器,使用exp通常不能导出0行数据的空表,而此时必须使用expdp导出。

    exp、imp导入导出
    sqlplus 进入数据库中 
    导出 
    直接在命令行下写命令 
    1.导出自己的表   
    exp userid=scott/tiger@myoral tables=(emp,dept) file=/opt/e1.dmp 
      
    2.导出其它方案的表 如果用户要导出其它方案的表,则需要dba的权限或是exp_full_database的权限,比如system就可以导出scott的表   
    exp userid=system/manager@myoral tables=(scott.emp) file=d:e2.emp  
    3. 导出表的结构   
    exp userid=scott/tiger@accp tables=(emp) file=/opt/e3.dmp rows=n  
    4. 使用直接导出方式  
    exp userid=scott/tiger@accp tables=(emp) file=/opt/e4.dmp direct=y  
    这种方式比默认的常规方式速度要快,当数据量大时,可以考虑使用这样的方法。 这时需要数据库的字符集要与客户端字符集完全一致,否则会报错 
    导出方案 导出方案是指使用export工具导出一个方案或是多个方案中的所有对象(表,索引,约束...)和数据。并存放到文件中 
    1. 导出自己的方案  
    exp userid=scott/tiger@myorcl owner=scott file=/opt/scott.dmp  
    2. 导出其它方案 如果用户要导出其它方案,则需要dba的权限或是exp_full_database的权限,比如system用户可以导出任何方案  
    exp userid=system/manager@myorcl owner=(system,scott) file=/opt/system.dmp  
    导出数据库  
    导出数据库是指利用export导出所有数据库中的对象及数据,要求该用户具有dba的权限或者是exp_full_database权限 增量备份(好处是第一次备份后,第二次备份就快很多了) 
     exp userid=system/manager@myorcl full=y inctype=complete file=/opt/all.dmp 
    导入  
    1. 导入自己的表  
    imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp  
    2. 导入表到其它用户 要求该用户具有dba的权限 
    imp_full_database imp userid=system/tiger@myorcl tables=(emp) file=/opt/xx.dmp touser=scott
     3. 导入表的结构,只导入表的结构而不导入数据  
    imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp rows=n 
    4. 导入数据 如果对象(如比表)已经存在可以只导入表的数据 
    imp userid=scott/tiger@myorcl tables=(emp) file=/opt/xx.dmp ignore=y 
    导入方案 导入方案是指使用import工具将文件中的对象和数据导入到一个或是多个方案中。如果要导入其它方案,要求该用户具有dba的权限,或者imp_full_database
     1. 导入自身的方案 
    imp userid=scott/tiger file=/opt/xxx.dmp  
    2. 导入其它方案 要求该用户具有dba的权限  
    imp userid=system/manager file=/opt/xxx.dmp fromuser=system touser=scott 
    导入数据库  
    在默认情况下,当导入数据库时,会导入所有对象结构和数据,案例如下:  
    imp userid=system/manager full=y file=/opt/xxx.dmp 

    expdp、impdp导入导出
    一、准备工作

    1)、在备份目的路径建立备份文件夹 
    例如:d:ak

    2)、用sys用户在oracle中创建逻辑目录 
    SQL>create directory oracleBak_dir as ‘d:ak’;

    3)、查看数据库中的逻辑目录 
    SQL>select * from dba_directories;

    4)、授权用户有对逻辑目录的读写权限 
    SQL>grant read,write on directory oracleBak_dir to someone;

    二、导出

    1)导出用户 
    expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp directory=oracleBak_dir ;

    2)导出表 
    expdp scott/tiger@orcl tables=emp,dept dumpfile=expdp.dmp directory=oracleBak_dir ;

    3)按查询条件导 
    expdp scott/tiger@orcl directory=oracleBak_dir dumpfile=expdp.dmp tables=emp query=’where deptno=20’;

    4)按表空间导 
    expdp system/manager@orcl directory=oracleBak_dir dumpfile=tablespace.dmp tablespaces=temp,example;

    5)导整个数据库 
    expdp system/manager@orcl directory=oracleBak_dir dumpfile=full.dmp full=y;

    三、导入数据

    1)导入用户(从用户scott导入到用户scott) 
    impdp scott/tiger@orcl directory=oracleBak_dir dumpfile=expdp.dmp schemas=scott;

    2)导入表(从scott用户中把表dept和emp导入到system用户中) 
    impdp system/manager@orcl directory=oracleBak_dir dumpfile=expdp.dmp tables=scott.dept,scott.emp remap_schema=scott:system;

    3)导入表空间 
    impdp system/manager@orcl directory=oracleBak_dir dumpfile=tablespace.dmp tablespaces=example;

    4)导入数据库 
    impdb system/manager@orcl directory=oracleBak_dir dumpfile=full.dmp full=y;

    5)追加数据 
    impdp system/manager@orcl directory=dump_dir dumpfile=expdp.dmp schemas=systemtable_exists_action

    参考文档: 
    http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_export.htm#i1007509

    http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_import.htm#g1025464
    ————————————————
    版权声明:本文为CSDN博主「残月飞鹰」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/songyanfei1205/article/details/79753279

  • 相关阅读:
    node
    github
    [模块] pdf转图片-pdf2image
    python 15 自定义模块 随机数 时间模块
    python 14 装饰器
    python 13 内置函数II 匿名函数 闭包
    python 12 生成器 列表推导式 内置函数I
    python 11 函数名 迭代器
    python 10 形参角度 名称空间 加载顺序
    python 09 函数参数初识
  • 原文地址:https://www.cnblogs.com/li-sx/p/7493657.html
Copyright © 2011-2022 走看看