1、备份脚本:
#!/bin/sh
export ORACLE_BASE=/home/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export DATA_DIR=/home/bakup/data
export LOGS_DIR=/home/bakup/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 shop/lyisABC0987@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."
2、添加到任务调度
crontab -u oracle -e
* 3 * * * /home/bakup/bakup.sh
即每天凌晨3点进行备份
如需每天备份多次,可设置不同时间段备份:
例如:* 3,13,18 * * * /home/bakup/bakup.sh,即每天3点、13点、18点进行备份。
说明:文件备份目录,用户oracle必须有更改权限,否则无法备份。
#!/bin/sh
export ORACLE_BASE=/home/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export DATA_DIR=/home/bakup/data
export LOGS_DIR=/home/bakup/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 shop/lyisABC0987@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."
2、添加到任务调度
crontab -u oracle -e
* 3 * * * /home/bakup/bakup.sh
即每天凌晨3点进行备份
如需每天备份多次,可设置不同时间段备份:
例如:* 3,13,18 * * * /home/bakup/bakup.sh,即每天3点、13点、18点进行备份。
说明:文件备份目录,用户oracle必须有更改权限,否则无法备份。