本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:彼岸·花
日志总数:39
评论数量:115
留言数量:-16
访问次数:403588
建立时间:2005年8月6日




[一路前行]Oracle 数据库导入导出和windows环境下的oracle服务
文章收藏,  网上资源

子轩 发表于 2007/4/30 11:00:12

执行环境:可以在SQLPLUS.EXE或者DOS(命令行)中执行, DOS中可以执行时由于 在oracle 8i 中  安装目录\ora81\BIN被设置为全局路径, 该目录下有EXP.EXE与IMP.EXE文件被用来执行导入导出。 oracle用java编写,我想SQLPLUS.EXE、EXP.EXE、IMP.EXE这俩个文件是被包装后的类文件。 SQLPLUS.EXE调用EXP.EXE、IMP.EXE他们所包裹的类,完成导入导出功能。 下面介绍的是导入导出的实例,向导入导出看实例基本上就可以完成,因为导入导出很简单。数据导出:exp qhmis/qhmis@qhmis  file='d:\backup\qhmis\qhmis20060526.dmp'  grants=y  full=n 1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中   exp system/manager@TEST file=d:\daochu.dmp full=y 2 将数据库中system用户与sys用户的表导出   exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys) 3 将数据库中的表table1 、table2导出   exp system/manager@TEST file=d:\daochu.dmp tables=(table1,table2)  4 将数据库中的表table1中的字段filed1以"00"打头的数据导出   exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\" where filed1 like '00%'\"       上面是常用的导出,对于压缩我不太在意,用winzip把dmp文件可以很好的压缩。                     不过在上面命令后面 加上 compress=y  就可以了 数据的导入 1 将D:\daochu.dmp 中的数据导入 TEST数据库中。   imp system/manager@TEST  file=d:\daochu.dmp   上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。   在后面加上 ignore=y 就可以了。 2 将d:\daochu.dmp中的表table1 导入 imp system/manager@TEST  file=d:\daochu.dmp  tables=(table1) 下面这句是执行将c盘的oracle的备份的用户qhmis导入到用户qhmis的数据库imp qhmis/qhmis@qhmis  file='c:qhmis20060224.dmp'  ignore=n  grants=y  full=y 500)this.width=500'>将一个数据库的某用户的所有表导到另外数据库的一个用户下面的例子   500)this.width=500'>exp userid=system/manager owner=username1 file=expfile.dmp 500)this.width=500'>imp userid=system/manager fromuser=username1 touser=username2 ignore=y file=expfile.dmp 500)this.width=500'>500)this.width=500'>ORACLE数据库有两类备份方法。第一类为物理备份,该方法实现数据库的完整恢复,但数据库必须运行在归挡模式下(业务数据库在非归挡模式下运行),且需要极大的外部存储设备,例如磁带库;第二类备份方式为逻辑备份,业务数据库采用此种方式,此方法不需要数据库运行在归挡模式下,不但备份简单,而且可以不需要外部存储设备。 500)this.width=500'>500)this.width=500'>500)this.width=500'>数据库逻辑备份方法 500)this.width=500'>ORACLE数据库的逻辑备份分为三种模式:表备份、用户备份和完全备份。 500)this.width=500'>500)this.width=500'>500)this.width=500'>表模式 500)this.width=500'>备份某个用户模式下指定的对象(表)。业务数据库通常采用这种备份方式。 500)this.width=500'>若备份到本地文件,使用如下命令: 500)this.width=500'>exp icdmain/icd rows=y indexes=n compress=n buffer=65536 500)this.width=500'>feedback=100000 volsize=0 500)this.width=500'>file=exp_icdmain_csd_yyyymmdd.dmp 500)this.width=500'>log=exp_icdmain_csd_yyyymmdd.log 500)this.width=500'>tables=icdmain.commoninformation,icdmain.serviceinfo,icdmain.dealinfo 500)this.width=500'>若直接备份到磁带设备,使用如下命令: 500)this.width=500'>exp icdmain/icd rows=y indexes=n compress=n buffer=65536 500)this.width=500'>feedback=100000 volsize=0 500)this.width=500'>file=/dev/rmt0 500)this.width=500'>log=exp_icdmain_csd_yyyymmdd.log 500)this.width=500'>tables=icdmain.commoninformation,icdmain.serviceinfo,icdmain.dealinfo 500)this.width=500'>注:在磁盘空间允许的情况下,应先备份到本地服务器,然后再拷贝到磁带。出于速度方面的考虑,尽量不要直接备份到磁带设备。 500)this.width=500'>500)this.width=500'>500)this.width=500'>用户模式 500)this.width=500'>备份某个用户模式下的所有对象。业务数据库通常采用这种备份方式。 500)this.width=500'>若备份到本地文件,使用如下命令: 500)this.width=500'>exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=65536 500)this.width=500'>feedback=100000 volsize=0 500)this.width=500'>file=exp_icdmain_yyyymmdd.dmp 500)this.width=500'>log=exp_icdmain_yyyymmdd.log 500)this.width=500'>若直接备份到磁带设备,使用如下命令: 500)this.width=500'>exp icdmain/icd owner=icdmain rows=y indexes=n compress=n buffer=65536 500)this.width=500'>feedback=100000 volsize=0 500)this.width=500'>file=/dev/rmt0 500)this.width=500'>log=exp_icdmain_yyyymmdd.log 500)this.width=500'>注:如果磁盘有空间,建议备份到磁盘,然后再拷贝到磁带。如果数据库数据量较小,可采用这种办法备份。 500)this.width=500'>500)this.width=500'>500)this.width=500'>完全模式 500)this.width=500'>备份完整的数据库。业务数据库不采用这种备份方式。备份命令为: 500)this.width=500'>exp icdmain/icd rows=y indexes=n compress=n buffer=65536 500)this.width=500'>feedback=100000 volsize=0 full=y 500)this.width=500'>file=exp_fulldb_yyyymmdd.dmp(磁带设备则为/dev/rmt0) 500)this.width=500'>log=exp_fulldb_yyyymmdd.log 500)this.width=500'>对于数据库备份,建议采用增量备份,即只备份上一次备份以来更改的数据。增量备份 500)this.width=500'>命令: 500)this.width=500'>exp icdmain/icd rows=y indexes=n compress=n buffer=65536 500)this.width=500'>feedback=100000 volsize=0 full=y inctype=incremental 500)this.width=500'>file=exp_fulldb_yyyymmdd.dmp(磁带设备则为/dev/rmt0) 500)this.width=500'>log=exp_fulldb_yyyymmdd.log 500)this.width=500'>注:关于增量备份必须满足下列条件: 500)this.width=500'>1. 只对完整数据库备份有效,且第一次需要full=y参数,以后需要inctype=incremental参数。 500)this.width=500'>2. 用户必须有EXP_FULL_DATABASE的系统角色。 500)this.width=500'>3. 话务量较小时方可采用数据库备份。 500)this.width=500'>4. 如果磁盘有空间,建议备份到磁盘,然后再备份到磁带。 500)this.width=500'>业务数据库备份方法及周期 500)this.width=500'>用EXP进行备份前,先在SYS用户下运行CATEXP.SQL文件(如果以前已运行该文件,则不要执行这个脚本)。 500)this.width=500'>没有特殊说明,不允许在客户端执行备份命令。 500)this.width=500'>500)this.width=500'>备份命令参照表模式下的备份命令。 500)this.width=500'>从磁盘文件备份到磁带 500)this.width=500'>如果首先备份到本地磁盘文件,则需要转储到磁带设备上。 500)this.width=500'>1. 若需查看主机上配置的磁带设备,使用如下命令: 500)this.width=500'>lsdev -Cc tape 500)this.width=500'>显示的结果如下例所示: 500)this.width=500'>rmt0 Available 30-58-00-2,0 SCSI 4mm Tape Drive 500)this.width=500'>rmt1 Defined  30-58-00-0,0 SCSI 4mm Tape Drive 500)this.width=500'>标明Available的设备是可用的磁带设备。 500)this.width=500'>2. 若需查看磁带存储的内容,使用如下命令: 500)this.width=500'>tar -tvf /dev/rmt0 500)this.width=500'>显示的结果如下例所示: 500)this.width=500'>-rw-r--r-- 300 400 8089600 Jan 11 14:33:57 2001 exp_icdmain_20010111.dmp 500)this.width=500'>如果显示类似如下内容,则表示该磁带存储的备份数据是从数据库直接备份到磁带上,而非从本地磁盘转储到磁带的备份文件,因此操作系统无法识别。 500)this.width=500'>tar: 0511-193 An error occurred while reading from the media. 500)this.width=500'>There is an input or output error. 500)this.width=500'>或 500)this.width=500'>tar: 0511-169 A directory checksum error on media; -267331077 not equal to 25626. 500)this.width=500'>3. 对于新磁带或无需保留现存数据的磁带,使用如下命令: 500)this.width=500'>tar -cvf /dev/rmt0 exp_icdmain_yyyymmdd.dmp 500)this.width=500'>注:A. 该命令将无条件覆盖磁带上的现存数据。 500)this.width=500'>  B. 文件名不允许包含路径信息,如:/backup/exp_icdmain_yyyymmdd.dmp。 500)this.width=500'>4. 对于需要保留现存数据的磁带,使用如下命令: 500)this.width=500'>tar -rvf /dev/rmt0 exp_icdmain_yyyymmdd.dmp 500)this.width=500'>注:该命令将文件exp_icdmain_yyyymmdd.dmp追加到磁带的末端,不会覆盖现存的数据。 500)this.width=500'>特别强调:如果备份时是从数据库直接备份到磁带上,则不可再向该磁带上追加复制任何其他文件,否则该备份数据失效。 500)this.width=500'>5. 若需将转储到磁带上的备份文件复制到本地硬盘,使用如下命令: 500)this.width=500'>A. 将磁带上的全部文件复制到本地硬盘的当前目录 500)this.width=500'>tar -xvf /dev/rmt0 500)this.width=500'>B. 将磁带上的指定文件复制到本地硬盘的当前目录 500)this.width=500'>tar -xvf /dev/rmt0 exp_icdmain_yyyymmdd.dmp 500)this.width=500'>备份时间安排 500)this.width=500'>由于备份时对系统I/O有较大影响,所以,建议在晚上11点以后进行备份工作。 500)this.width=500'>业务数据库Oracle版本的恢复,恢复方案需根据备份方案确定。由于业务数据库采用表备份和用户备份相结合的方案,所以业务数据库的恢复需根据实际情况采用表恢复和用户恢复相结合的方案。500)this.width=500'>500)this.width=500'>恢复方案 500)this.width=500'>数据库的逻辑恢复分为表恢复、用户恢复、完全恢复三种模式。500)this.width=500'>500)this.width=500'>表模式 500)this.width=500'>此方式将根据按照表模式备份的数据进行恢复。 500)this.width=500'>A. 恢复备份数据的全部内容 500)this.width=500'>若从本地文件恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 500)this.width=500'>file=exp_icdmain_cs 500)this.width=500'>d_yyyymmdd.dmp 500)this.width=500'>log=imp_icdmain_csd_yyyymmdd.log 500)this.width=500'>若从磁带设备恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 500)this.width=500'>log=imp_icdmain_csd_yyyymmdd.log 500)this.width=500'>B. 恢复备份数据中的指定表 500)this.width=500'>若从本地文件恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 500)this.width=500'>file=exp_icdmain_cs 500)this.width=500'>d_yyyymmdd.dmp 500)this.width=500'>log=imp_icdmain_csd_yyyymmdd.log 500)this.width=500'>tables=commoninformation,serviceinfo 500)this.width=500'>若从磁带设备恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 500)this.width=500'>file=/dev/rmt0 500)this.width=500'>log=imp_icdmain_csd_yyyymmdd.log 500)this.width=500'>tables=commoninformation,serviceinfo 500)this.width=500'>500)this.width=500'>500)this.width=500'>用户模式 500)this.width=500'>此方式将根据按照用户模式备份的数据进行恢复。 500)this.width=500'>A. 恢复备份数据的全部内容 500)this.width=500'>若从本地文件恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 500)this.width=500'>file=exp_icdmain_yy 500)this.width=500'>yymmdd.dmp 500)this.width=500'>log=imp_icdmain_yyyymmdd.log 500)this.width=500'>若从磁带设备恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 500)this.width=500'>log=imp_icdmain_yyyymmdd.log 500)this.width=500'>B. 恢复备份数据中的指定表 500)this.width=500'>若从本地文件恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 500)this.width=500'>file=exp_icdmain_yy 500)this.width=500'>yymmdd.dmp 500)this.width=500'>log=imp_icdmain_yyyymmdd.log 500)this.width=500'>tables=commoninformation,serviceinfo 500)this.width=500'>若从磁带设备恢复,使用如下命令: 500)this.width=500'>imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n 500)this.width=500'>commit=y buffer=65536 feedback=100000 ignore=n volsize=0 file=/dev/rmt0 500)this.width=500'>log=imp_icdmain_yyyymmdd.log 500)this.width=500'>tables=commoninformation,serviceinfo 500)this.width=500'>500)this.width=500'>完全模式 500)this.width=500'>如果备份方式为完全模式,采用下列恢复方法: 500)this.width=500'>若从本地文件恢复,使用如下命令: 500)this.width=500'>imp system/manager rows=y indexes=n commit=y buffer=65536 500)this.width=500'>feedback=100000 ignore=y volsize=0 full=y 500)this.width=500'>file=exp_icdmain_yyyymmdd.dmp 500)this.width=500'>log=imp_icdmain_yyyymmdd.log 500)this.width=500'>若从磁带设备恢复,使用如下命令: 500)this.width=500'>imp system/manager rows=y indexes=n commit=y buffer=65536 500)this.width=500'>feedback=100000 ignore=y volsize=0 full=y 500)this.width=500'>file=/dev/rmt0 500)this.width=500'>log=imp_icdmain_yyyymmdd.


阅读全文(5396) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144796670 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号