oracle数据库的备份与恢复(expdp与impdp),expdpimpdp
参考:http://blog.csdn.net/oraclemch/article/details/5551634
oracle 11g 初学者指南
http://www.cnblogs.com/netsql/articles/1745978.html
网上的资料都很零碎,而且大部分都不能完成要求的功能,所以做了些整理与完善
准备工作
1 在环境变量中队bin目录进行配置。默认情况下,安装oracle数据库时,将自动配置相应的环境变量,
例如D:/oracle/product/10.2.0/db_1/BIN
2 在oracle安装路径的bin文件夹中,确定expdp.exe和impdp.exe文件的存在。
3 创建一个外部目录。
data pump要求为将要创建和读取的数据文件和日志文件创建目录,用来指向
使用的外部目录。在oracle中创建目录对象时,可以使用 create directory
语句。
【实例】
1,检查,高级环境变量-pathpath里面有无bin目录
2,检查expdp.exe、impdp.exe文件是否存在。
3,建立目录
c:/> sqlplus /nolog
sql> conn sys/sys as sysdba
sql> create directory mypump as 'd:/app/temp';
sql> grant read, write on directory mypump to scot
实现数据导出
【实例】
1,表模式导出
expdp scott/scott_2009 directory=mypumpdumpfile=expdptab.dmp tables=dept,emp
(select * from dba_tablespaces; altertablespace testspace online;)
2,schema模式导出
(ORA-39083 这个错误的原因是出在用户的权限上,而且是在导出的时候在expdp之前执行 grant EXP_FULL_DATABASE to scott;)
expdp system/system directory=mypumpdumpfile=expdp.dmp schemas=scott nologfile=y
3,表空间数据导出
expdp system/system directory=mypumpdumpfile=expdpspace.dmp tablespaces=EPISCMCC_DTS
4,全库模式导出
expdpsystem/system directory=mypump dumpfile=expdp.dmp full=y
实现数据导入
1,表模式导入
impdpscott/scott_2009 directory=mypump dumpfile=expdptab.dmp tables=dept,emp
2,schema模式导入
impdpsystem/system directory=mypump dumpfile=expdp.dmp schemas=scott
3,表空间数据导入
impdp system/tiger directory=mypump dumpfile=expdspaces.dmp remap_tablespace=EPISCMCC_DTS:EPISCMCC_DTS table_exists_action=replace
4,全库模式导入
impdpsystem/system directory=mypump dumpfile=expdp.dmp full=y table_exists_action=replace
其中:在表空间导入与全库导入的时候要事先创建表空间与相应的表空间下的用户具体步骤如下:
导入到数据库之前,要在新数据库创建相应的表空间及用户
其中源数据库中的表空间为EPICMCC_DTS,该表空间下的用户为EPICMCC
/*创建临时表空间*/ create temporary tablespace EPISCMCC_TEMP tempfile 'C:\app\z002w00r-e01\oradata\orcl\EPISCMCC_TEMP.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local /*创建表空间*/ create tablespace EPISCMCC_DTS logging datafile 'C:\app\z002w00r-e01\oradata\orcl\EPISCMCC_DTS.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local /*创建用户指定表空间*/ create user EPISCMCC identified by tiger default tablespace EPISCMCC_DTS temporary tablespace EPISCMCC_TEMP /*给用户授权*/ grant connect,resource,dba to EPISCMCC
这个百度上一搜一大把,都说的很详细,楼主没搜过,
数据导出:
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 将数据库中的表inner_notify、notify_staff_relat导出
exp aichannel/aichannel@TESTDB2 file= d:datanewsmgnt.dmp tables=(inner_notify,notify_staff_relat)
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
imp aichannel/aichannel@HUST full=y file=d:datanewsmgnt.dmp ignore=y
上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
在后面加上 ignore=y 就可以了。
2 将d:daochu.dmp中的表table1 导入
imp system/manager@TEST file=d:daochu.dmp tables=(table1)
基本上上面的导入导出够用了。不少情况要先是将表彻底删除,然后导入。
注意:
操作者要有足够的权限,权限不够它会提示。
数据库时可以连上的。可以用tnsping TEST 来获得数据库TEST能否连上。
当然,上面的方法在导出数据时可能会导出很大的包,那是因为你的用户可能在授权的时候授予了DBA的权限,所以可以采用下面方法来进行数据库备份:
数据库备份
建议系统过渡后,每周进行一次备份。或者在数据表发生重大改变前,对要改变的数据表进行备份。
执行以下步骤,进行备份。
在命令行里,敲入“cmd”,回车,进入命令行窗口。
在窗口中,输入:
exp mas/123456@mas
系统提示:输入数组提取缓冲区大小: 4096 >
可以直接回车;
系统提示:导出文件: EXPDAT.DMP>
此处输入导出文件的位置,其路径必须存在,Oracle在这里不会自动建立路径,但可以建立文件名。备份文件以dmp作为后缀。
输入内容如:e:\work\mas_db_090925v1.dmp 回车
系统提示: (1)E(完整的数据库),(2)U(用户) 或 (3)T(表): (2)U > u
此处可以输入u,也可以直接回车,因为系统此时默认的是U
系统提示:导出权限(......余下全文>>
参数exclude:
exclude=object_type[:name_clause][,...]
比如:impdp user/pass DIRECTORY=dmpdir DUMPFILE=user.dmp exclude=PROCEDURE:"in('p1', 'p2')",TABLE_STATISTICS