Linux下ORCLE数据库增量备份脚本 (基础篇)

来源:互联网 发布:从你的全世界路过知乎 编辑:程序博客网 时间:2024/04/26 22:14

 ORCLE数据库备份策略
1.通过使用exp和imp命令实现数据库导出和导入。  
有三种模式:
       a. 用户模式: 导出(导入)用户所有对象以及对象中的数据;
       b. 表模式: 导出(导入)用户所有表或者指定的表;
       c. 整个数据库: 导出(导入)数据库中所有对象。
如:
普通导出
a.导出一个完整数据库
     exp system/manager file=f.dmp   full=y
b.导出数据库定义而不导出数据
     exp system/manager file=f.dmp   full=y rows=n
普通导入:
a.完全导入
imp system/manager file=f.dmp full=y
b.数据库结构存在时,只导入数据
imp system/manager file=f.dmp full=y ignore=y
2.每周进行数据库备份,以防数据库被意外破坏后恢复数据
安排如下:
周一:       完全备份(f1)       exp xxx/xxx inctype=complete     file=f1.dmp
周二:       增量备份(f2)       exp xxx/xxx inctype=incremental   file=f2.dmp
周三:       增量备份(f3)       exp xxx/xxx inctype=incremental   file=f3.dmp
周四:       增量备份(f4)       exp xxx/xxx inctype=incremental   file=f4.dmp
周五:       累积备份(f5)       exp xxx/xxx inctype=cumulative   file=f5.dmp
周六:       增量备份(f6)       exp xxx/xxx inctype=incremental   file=f6.dmp
周日:       增量备份(f7)       exp xxx/xxx inctype=incremental   file=f7.dmp
比如数据库在周日被破坏,则可用以下方式恢复:
1.创建空的数据库,同之前的结构。
2.imp xxx/xxx inctype=RESTORE FULL=y FILE=f1.dmp
3.imp xxx/xxx inctype=RESTORE FULL=y FILE=f5.dmp
4.imp xxx/xxx inctype=RESTORE FULL=y FILE=f6.dmp
说明:
完全导出:对整个数据库的备份
增量导出:是备份上一次完全导出后改变的数据。
累积导出:是备份自上次完全导出后改变的数据。
EXAMPLE:LINUX下备份数据库
BACKUP_DIR=/home/oracle/backups
if [ ! -d $BACKUP_DIR ]; then
     mkdir -p $BACKUP_DIR
fi
DAYS=(Sun Mon Tue Wed Thu Fri Sat) #创建数组
TYPES=(incremental complete incremental incremental incremental cumulative incremental)
day=`date +%w`                     #取得本周天数,0代表周日,1代表周一
DAY_NAME=${DAYS[$day]}             #取得数组的值
TYPE=${TYPES[$day]}
DATE_NAME=`date +%F`
FILE_NAME=${DATE_NAME}-${DAY_NAME}-${TYPE}.dmp #2008-12-8-Mon-complete.dmp
exp xxx/xxx inctype=$TYPE file=${BACKUP_DIR}/${FILE_NAME} > /dev/null
gzip ${BACKUP_DIR}/${FILE_NAME}
find $BACKUP_DIR -mtime +7 -delete           #删除七天前更改过的文件

原创粉丝点击