oracle逻辑备份与还原大全

表是逻辑单位,对表的备份叫做逻辑备份。(数据迁移)
可以跨用户移动数据,跨数据库移动数据,为测试保存原始数据状态,对数据库进行版本升级
逻辑导出注意事项:
exp程序在目录中发现同名文件时会直接覆盖,不提示!!
exp无法备份无段的空表
执行逻辑导出时一定要注意字符集!最好使用包含中文的小表做测试!!
导入数据时和导出数据时一模一样,导出之后数据库中表的数据变化会丢失!!
逻辑导出本质是对数据库进行select查询,把查询结果写成系统二进制文件。
备分过程中修改数据无法在备份数据中体现,还原回来可能丢数据。

1、逻辑导出,所有版本都可用,服务器端和客户端都可用
mkdir -p /home/oracle/expbk
exp userid=scott/passwd tables=emp file=/home/oracle/expbk/emp.dmp buffer=1024000 log=/home/oracle/expbk/emp.log
逻辑导入:
drop table t01 purge;
imp userid=scott/passwd tables=t01 file=/home/oracle/expbk/t01.dmp buffer=1048576 feedback=10000 log=/home/oracle/expbk/imp_t01.log

2、导出数据时带有查询条件
exp userid=scott/passwd tables=emp file=/home/oracle/expbk/emp_30.dmp query=\'where deptno=30\' buffer=1048576 log=/home/oracle/expbk/emp_30.log
导入时追加数据:ignore=y (有主键时不能用)
imp userid=scott/passwd tables=emp file=/home/oracle/expbk/emp_30.dmp ignore=y buffer=1048576 log=/home/oracle/expbk/imp_emp_30.log

3、闪回导出必须用system用户(insert,update,delete是可以闪回去的,其他操作无法闪回)
exp system/passwd tables=scott.emp file=/home/oracle/expbk/emp_1015.dmp buffer=102400 flashback_time=\"to_timestamp\(\'2017-07-01 10:15:00\',\'yyyy-mm-dd hh24:mi:ss\'\)\" log=/home/oracle/expbk/emp_1015.log
导入数据
imp system/passwd file=/home/oracle/expbk/emp_1015.dmp full=y ignore=y

4、只导出表结构(元数据)不导出数据:备份模型,不备份数据
exp scott/passwd tables=ob1 rows=n file=/home/oracle/expbk/ob1_metadata.dmp log=/home/oracle/expbk/ob1_metadata.log

5、导出用户:
exp userid=scott/passwd owner=scott file=/home/oracle/expbk/scott.dmp buffer=1048576 feedback=10000 log=/home/oracle/expbk/scott.log
导入用户(先创建好用户):
imp userid=scott/passwd full=y file=/home/oracle/expbk/scott.dmp buffer=1048576 feedback=10000 log=/home/oracle/expbk/imp_scott.log

6、跨用户导入数据:scott-->tom
imp userid=system/passwd file=/home/oracle/expbk/scott.dmp fromuser=scott touser=tom tables=dept,emp,salgrade buffer=1048576 feedback=10000 log=/home/oracle/expbk/imp_scott.log
(可以不加tables选项,默认导所有的,加哪个导哪个)

7、使用主机管道压缩备份数据
mknod /home/oracle/expbk/exp_pipe p
exp userid=scott/passwd owner=scott buffer=1048576 feedback=10000 log=/home/oracle/expbk/scott.log file=/home/oracle/expbk/exp_pipe & gzip </home/oracle/expbk/exp_pipe >scott.dmp.gz

8、导出表空间
exp userid=system/passwd tablespace=USERS file=/home/oracle/expbk/users.dmp buffer=1048576 log=/home/oracle/expbk/users.log
导入表空间
imp userid=scott/passwd owner=scott file=/home/oracle/expbk/scott.dmp buffer=1048576 feedback=10000 log=/home/oracle/expbk/scott.log


猜你喜欢

转载自blog.csdn.net/tab_007/article/details/80673981