oracle 数据备份
前言
众所周知,数据是一个系统的重中之重。如果说数据没有了,那么一切都完了。基于此,我整理了一下oracle备份的相关经验,经过了实际项目的严格考验!
备份方法
1.编写bat文件:
首先,编写备份的脚本文件,我命名为back_up.bat,文件内容如下(仅供参考):
back_up.bat:
@echo ========删除七天前的备份和日志文件==============
forfiles /p d:\db_backup /s /m *.dmp /d -7 /c "cmd /c del @FILE"
forfiles /p d:\db_backup /s /m *.log /d -7 /c "cmd /c del @FILE"
@echo ========备份生产环境test_real下的表开始===============
exp test_real/[email protected] file=d:\db_backup\test_real%date:~0,4%%date:~5,2%%date:~8,2%.dmp owner=test_real log=d:\db_backup\test_real%date:~0,4%%date:~5,2%%date:~8,2%.log
@echo ========备份生产环境test_real下的表结束===============
@echo ========备份生产环境test_user_real下的表开始===============
exp test_user_real/[email protected] file=d:\db_backup\test_user%date:~0,4%%date:~5,2%%date:~8,2%.dmp owner=test_user_real log=d:\db_backup\test_user%date:~0,4%%date:~5,2%%date:~8,2%.log
@echo ========备份生产环境test_user_real下的表结束===============
2.新增windows计划任务,定时执行编写好的脚本文件:
(1)依次打开控制面板→管理工具 →任务计划程序,选择创建基本任务。
(2)按照步骤进行设置即可。设置好的计划任务如下。
附录
1.解决不能导出空表的问题
执行如下sql语句:
select 'alter table ' || table_name || ' allocate extent;'
from user_tables
where num_rows = 0 or num_rows is null;
将生成出的sql语句复制到文件中,调整好后进行执行
alter table MISSIVE_DOC_PASS allocate extent;
alter table MEETING_ROOM allocate extent;
alter table BULLETIN_BULLETIN allocate extent;
使用下面的sql语句进行验证
select table_name, segment_created
from user_tables
where num_rows = 0 or num_rows is null;
结果均为YES代表生效,导出数据的时候将连同空表一同导出。