1、Linux 下 oracle 自动备份:实现功能:第一:每天自动备份当天的数据库的数据信息 。第二:把当天备份的数据和日志一起打成.tar.gz 包,这样会减少硬盘的容量。第三:每天的数据日益增加,硬盘的容量有限。所以只保留前五天的数据备份,删除五天前的数据备份。自动备份实现步骤:1. 创建备份目录:rootoracle # mkdir backup2. 创建并编写:jw_autobak 文件rootoracle backup# vi jw_autobak脚本内容如下:export ORACLE_BASE=/db/u01export ORACLE_HOME= /db/u01/oracle/pr
2、oduct/10.2.0/db_1export ORACLE_SID=jwexport NLS_LANG=“simplified chinese“_china.zhs16gbk;export PATH=$PATH:/usr/sbin:/$ORACLE_HOME/binexport DATE=$(date +%y%m%d)cd /dbbak/oraclebackup/backupexp newjw/newjw file=newjw$DATE.dmp log=newjw$DATE.logtar -cf newjw$DATE.tar newjw$DATE.dmp newjw$DATE.loggzip
3、 newjw$DATE.tarrm -f newjw$DATE.dmprm -f newjw$DATE.logrm -f newjw$(date -d -5day +%y%m%d).tar.gz3. 在数据库服务器的 crontab 来定时执行 shell:用 oracle 用户启动一个终端,输入命令进行编写: crontab e内容如下:rootoracle backup# crontab e00 21 * * * /backup/jw_autobak4. 重启 crontab 定时服务:rootoracle backup# /etc/init.d/crond restartStopping
4、 crond: OK Starting crond: OK 首都师范大学办公系统备份脚本:export ORACLE_BASE=/u01/export ORACLE_HOME=/u01/oracleexport ORACLE_SID=cnuoaexport NLS_LANG=AMERICAN_AMERICA.AL32UTF8export PATH=$PATH:/usr/sbin:/$ORACLE_HOME/binexport DATE=date +%Y%m%d%H%Mcd /backup/databaseexp v3xuserbak/v3xuser file=v3xuserbak$DATE.d
5、mp log=v3xuserbak$DATE.log owner=v3xuserbaktar -cf v3xuserbak$DATE.tar v3xuserbak$DATE.dmp v3xuserbak$DATE.loggzip v3xuserbak$DATE.tarrm -f v3xuserbak$DATE.dmprm -f v3xuserbak$DATE.logrm -f v3xuserbak$(date -d -30day +%Y%m%d%H%M).tar.gz注意事项:脚本要授可执行权限备份的目录授权给 oracle 用户可写入权限用 oracle 用户测试是否能够成功导出,root
6、用户无法完成。Crontab 中的命令:00 5 * * * su - oracle -c /backup/database/oa_autobak.sh00 04 * * * /dbbak/oraclebackup/backup.shexport ORACLE_BASE=/db/u01export ORACLE_HOME= /db/u01/oracle/product/10.2.0/db_1export ORACLE_SID=jwexport NLS_LANG= AMERICAN_AMERICA.ZHS16GBKexport PATH=$PATH:/usr/sbin:/$ORACLE_HOME
7、/binexport DATE=date +%Y%m%d%H%Mcd /dbbak/oraclebackup/backupexp system/v3xuser file=v3xuserbak$DATE.dmp log=v3xuserbak$DATE.log owner=v3xuserbaktar -cf v3xuserbak$DATE.tar v3xuserbak$DATE.dmp v3xuserbak$DATE.loggzip v3xuserbak$DATE.tarrm -f v3xuserbak$DATE.dmprm -f v3xuserbak$DATE.logrm -f v3xuserb
8、ak$(date -d -30day +%Y%m%d%H%M).tar.gz. /home/oracle/.bash_profile 可以直接引用 Oracle 环境变量。不需要加入前面:export ORACLE_BASE=/db/u01export ORACLE_HOME= /db/u01/oracle/product/10.2.0/db_1export ORACLE_SID=jwexport NLS_LANG= AMERICAN_AMERICA.ZHS16GBKexport PATH=$PATH:/usr/sbin:/$ORACLE_HOME/binexport DATE=date +%
9、Y%m%d%H%M经典脚本:#!/bin/sh. /home/oracle/.bash_profile#define variable.backup_date=date +%Y%m%d%H%MDATE15=date -d “15 days ago“ +%Y%m%dbackup_dest=/u01/orabakbackup_log=/u01/orabak#-开始备份#starting exp backup.exp datacenter/datacenter file=$backup_dest/datacenter_$backup_date.dmp log=$backup_log/datacent
10、er_$backup_date.log owner=datacenterexp mhxxpt_thaus1/mhxxpt_thaus1 file=$backup_dest/mhxxpt_thaus1_$backup_date.dmp log=$backup_log/mhxxpt_thaus1_$backup_date.log owner=mhxxpt_thaus1exp mhxxpt_mh/mhxxpt_mh file=$backup_dest/mhxxpt_mh_$backup_date.dmp log=$backup_log/mhxxpt_mh_$backup_date.log owner
11、=mhxxpt_mhexp exchange/exchange file=$backup_dest/exchange_$backup_date.dmp log=$backup_log/exchange_$backup_date.log owner=exchangetar cvfz $backup_dest/datacenter_$backup_date.tar.gz $backup_dest/datacenter_$backup_date.dmprm -rf $backup_dest/datacenter_$backup_date.dmptar cvfz $backup_dest/mhxxpt
12、_thaus1_$backup_date.tar.gz $backup_dest/mhxxpt_thaus1_$backup_date.dmprm -rf $backup_dest/mhxxpt_thaus1_$backup_date.dmptar cvfz $backup_dest/mhxxpt_mh_$backup_date.tar.gz $backup_dest/mhxxpt_mh_$backup_date.dmprm -rf $backup_dest/mhxxp_mh_$backup_date.dmptar cvfz $backup_dest/exchange_$backup_date.tar.gz $backup_dest/exchange_$backup_date.dmprm -rf $backup_dest/exchange_$backup_date.dmp#删除 15 天前的备份#rm -rf $backup_dest/full_$DATE15*.tar.gz#rm -rf $backup_dest/full_$DATE15*.dmp#rm -rf $backup_log/full_$DATE15*.log