一: 备份oracle数据库
备份有两种方式一种是exp方式,还有一种是expdp
比如我有一个oracle数据库person , 里面有两个scheam, 比如student和teacher

#导出person数据库中的,student、teacher这两个scheam,
exp system/passwd@person  file=D:\20180807.dmp owner=(student,teacher);

#导出一张表数据,导出student里面的成绩表
exp system/passwd@person file=D:\score.dmp tables=(student.score)

#数据泵导出,导出全库
expdp system/passwd@person directory=DATA_PUMP_DIR dumpfile=person.DMP EXCLUDE=STATISTICS full=y logfile=expperson.log

#导出指定scheam和版本
expdp system/passwd@person directory=expdir dumpfile=person.dmp logfile=person1203.log schemas=(student,teacher) version=11.2.0.1.0

二: 还原数据库
exp导出的备份文件需要用imp的导入语句,expdp 导出的备份文件需要用impdp的导入语句。
1、在客户端先删除要还原的用户

drop user student cascade;
drop user teacher cascade;

2、创建用户

#123456是这个用户对应的密码,SYSTEM是默认的表空间,创建用户指定表空间
create user student identified by 123456 Default tablespace SYSTEM;
create user teacher identified by 123456 Default tablespace SYSTEM;

3、赋权限

grant create session,connect, resource, dba to student;
grant create session,connect, resource, dba to teacher;

以上三个步骤都在客户端执行,比如plsql
4、执行备份脚本,在数据库安装的服务器上在cmd中执行

#D:\20180807.dmp,这个是备份文件所在的位置,将整个备份文件都导入
imp system/passwd@person file=D:\20180807.dmp full=y ignore=y;

#指定要导入的scheam
imp system/passwd@person fromuser=(student) touser=(student) file=D:\20180807.dmp commit=y ignore=y;

#导入一张表数据
imp system/passwd@person file=D:\score.dmp fromuser=(student) tables=score 

impdp system/passwd@person directory=DATA_PUMP_DIR dumpfile=20180807.dmp  logfile=dp.log partition_options=none table_exists_action= replace;


Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐