Chinaunix首页 | 论坛 | 博客
  • 博客访问: 53191
  • 博文数量: 10
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 197
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-05 13:38
个人简介

事在人为

文章分类

全部博文(10)

文章存档

2014年(2)

2013年(8)

我的朋友

分类: Oracle

2013-03-27 16:31:34

使用操作系统管道技术
$ mknod p p
 $ gzip < p > test.dmp.gz & exp eam/eam  buffer=31457280 CONSISTENT=Y COMPRESS=N file=p


脚本写法:

使用exp进行逻辑备份的时候,它是不压缩的。也就是可能会占据相对比较大空间。这里我

有必要解释一下exp的参数compress。这个参数其实不是表示压缩的意思,它表示的意思是


exp compress=y 与 exp compress=n:

exp compress=y表示將源表所有数据(总大小)压缩到一个extent中,在导入的时候只是导入

到目标表的initial中,这样可能导致目标表空间不足(只用到init extent,而目标表的

initial可能设置比较小) 。

所以一般使用exp compress=n,这样原来的表的storage结构也一样导入到目标表。不至于

出现都导入目标表的initial种的情况。

因此要想拿到一个压缩的exp出来的文件,可以先exp出来一个文件,然后利用OS命令来压缩

这个文件,可是这样一做的意义不大。下面介绍一种直接通过exp就可以生成压缩文件的方

法,它其实就是一个exp命令和操作系统的压缩命令以及管道的综合运用。

我的目的是想将scott用户下面的信息导入到另外两个新建的用户tiger和enix下面去。 首

先,建立必要的用户,这里省略。

然后:


[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

       其实原理都是一样的,也是利用管道。
使用后效果:
-rw-r--r-- 1 root   root      73721 Mar 27 01:16 cron.err
-rw-r--r-- 1 oracle dba  1368932352 Mar 27 01:16 eam.dmp
-rw-r--r-- 1 oracle dba       73591 Mar 27 01:16 eam.log
prw-r--r-- 1 oracle dba           0 Mar 27 16:13 p
-rw-r--r-- 1 oracle dba   194159007 Mar 27 16:13 test.dmp.gz

阅读(2878) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~