1.新建要备份的文件路径并赋予权限
<ol><li><span ><span ><strong>cd /home/oracle</strong></span></span></li><li><span ><span ><strong>mkdir backup</strong></span></span></li><li><span ><span ><strong>chmod 777 backup </strong></span></span></li><li><span ><span ><strong>cd backup</strong></span></span></li><li><span ><span ><strong>mkdir data</strong></span></span></li><li><span ><span ><strong>chmod 777 data </strong></span></span></li><li><span ><span ><strong>mkdir logs</strong></span></span></li><li><span ><span ><strong>chmod 777 logs</strong></span></span></li><li><span ><span ><strong>chmod 777 backup.sh</strong></span></span></li></ol>
2.编写backup.sh文件
<span >#!/bin/sh
export ORACLE_BASE=/home/oracle
export ORACLE_HOME=$ORACLE_BASE/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export DATA_DIR=/home/backup/data
export LOGS_DIR=/home/backup/logs
export DELTIME=$(date -d "7 days ago" +%Y%m%d) //删除七天前的备份
export BAKUPTIME=$(date +%Y%m%d%H%M%S)
mkdir -p $DATA_DIR
mkdir -p $LOGS_DIR
echo "Starting bakup..."
echo "Bakup file path $DATA_DIR/$BAKUPTIME.dmp"
exp dimdb/dbmdb@192.168.1.132/ORCL file=$DATA_DIR/$BAKUPTIME.dmp log=$LOGS_DIR/$BAKUPTIME.log
echo "Delete the file bakup before 7 days..."
rm -rf $DATA_DIR/$DELTIME*.dmp
rm -rf $LOGS_DIR/$DELTIME*.log
echo "Delete the file bakup successfully. "
echo "Bakup completed." </span>
3.修改任务调度文件(root用户)
- 增加oracle用户的任务调度
- crontab -u oracle -e
- */1 * * * * (sh /home/oracle/backup/backup.sh)//每分钟执行一次便于测试
- 查看oracle的任务分配
- crontab -u oracle -l
4.启动crontab服务(root用户)
/sbin/service/ crond start