加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

exp直接生成压缩文档

(2009-11-24 22:50:00)
标签:

exp

oracle

备份

管道

分类: 技术学习
    使用exp进行逻辑备份的时候,它是不压缩的。也就是可能会占据相对比较大空间。
    这里我有必要解释一下exp的参数compress。这个参数其实不是表示压缩的意思,它表示的意思是:exp compress=y表示將源表所有数据(总大小)压缩到一个extent中,在导入的时候只是导入到目标表的initial中,这样可能导致目标表空间不足(只用到init extent,而目标表的initial可能设置比较小) 。所以一般使用exp compress=n,这样原来的表的storage结构也一样导入到目标表。不至于出现都导入目标表的initial种的情况

    因此要想拿到一个压缩的exp出来的文件,可以先exp出来一个文件,然后利用OS命令来压缩这个文件,可是这样一做的意义不大。下面介绍一种直接通过exp就可以生成压缩文件的方法,它其实就是一个exp命令和操作系统的压缩命令以及管道的综合运用。

    我的目的是想将scott用户下面的信息导入到另外两个新建的用户tigerenix下面去。首先,建立必要的测试用户,这里省略。然后:

[oracle11g@csdba1850 test]$ exp system/oracle owner=scott compress=n file=scott_nocom.dmp

Export: Release 11.1.0.6.0 - Production on Thu Nov 8 16:54:23 2007

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

......

[oracle11g@csdba1850 test]$ ls -lthc

total 44K

-rw-r--r--  1 oracle11g oinstall 40K Nov  8 16:54 scott_nocom.dmp

 

[oracle11g@csdba1850 test]$ mknod /home/oracle11g/test/exp_pipe p  -- 建立一个中间过渡的管道

[oracle11g@csdba1850 test]$ cat exp_pipe.sh

nohup compress < /home/oracle11g/test/exp_pipe > /home/oracle11g/test/exp_scott.dmp.Z &

exp system/oracle owner=scott file=/home/oracle11g/test/exp_pipe log=exp_pipe.log

-- 这个shell脚本的作用就主要是让exp出来的信息,进入管道exp_pipe,然后操作系统接受管道出来的信息,将其压缩,于是就得到了经过压缩后的文件。

[oracle11g@csdba1850 test]$ sh exp_pipe.sh > /home/oracle11g/test/exp_scott.log 2>&1

[oracle11g@csdba1850 test]$ ls -lthc

total 88K

prw-r--r--  1 oracle11g oinstall    0 Nov  8 17:02 exp_pipe

-rw-r--r--  1 oracle11g oinstall 1.6K Nov  8 17:02 exp_pipe.log

-rw-r--r--  1 oracle11g oinstall 9.6K Nov  8 17:02 exp_scott.dmp.Z

-rw-r--r--  1 oracle11g oinstall 1.7K Nov  8 17:02 exp_scott.log

-rw-r--r--  1 oracle11g oinstall  170 Nov  8 17:00 exp_pipe.sh

-rw-r--r--  1 oracle11g oinstall  40K Nov  8 16:54 scott_nocom.dmp

 

    通过上面的最后比较发现,压缩后文件要远远小于没有压缩的文件。

    把经过压缩的文件,如何利用imp导入到数据库中呢?当然可以首先解压缩,然后再利用imp导入进去,这种方法就不说。下面介绍和exp原理相同的方法,利用管道来实现导入。

[oracle11g@csdba1850 test]$ mknod imp_pipe p  -- 同样是建立一个管道

[oracle11g@csdba1850 test]$ cat imp_pipe.sh

nohup uncompress -c /home/oracle11g/test/exp_scott.dmp.Z > /home/oracle11g/test/imp_pipe &

imp system/oracle file=/home/oracle11g/test/imp_pipe fromuser=scott touser=enix log=imp_pipe.log

-- 把操作系统解压出来的信息输入到管道中,imp接受管道传来的信息,将其导入至数据库

[oracle11g@csdba1850 test]$ sh imp_pipe.sh > /home/oracle11g/test/imp_scott.log 2>&1

 

    其实原理都是一样的,也是利用管道。

0

阅读 收藏 喜欢 打印举报/Report
前一篇:我的移动套餐
后一篇:经典赞美30句
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有