Oracle数据库定期逻辑备份和删除过期文件shell脚本
#!/bin/bash
# 这个脚本每天3:00执行
# 0 3 * * * /home/oracle/Databakup.sh crm 1>/dev/null 2>&1
export PATH=/home/oracle/app/product/10.2.0/bin:/home/oracle/app/product/10.2.0/bin:/usr/ccs/bin:/home/oracle/app/product/10.2.0/bin:/usr/bin:/usr/sbin:/usr/ucb:/home/oracle/bin:/usr/bin/X11:/sbin:/usr/opt/networker/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin:.
export ORACLE_BASE=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0
YESTERDAY=`date -d "yesterday" "+%Y%m%d"`
BAK_DIR="/home/oracle/orabak"
BAK_FILE=${BAK_DIR}/$1${YESTERDAY}.dmp
LOG_FILE=${BAK_DIR}/$1${YESTERDAY}.log
OlderFile=""
OlderCronFile=""
OlderDate=""
test -d ${BAK_DIR} || mkdir -p ${BAK_DIR}
CycleCount=3
cd ${BAK_DIR}
#删除时间最早的备份
OlderDate=`date -d "-${CycleCount} day" "+%Y%m%d"`
OlderFile="${BAK_DIR}/$1${OlderDate}.dmp"
OlderCronFile="${BAK_DIR}/cron${OlderDate}.txt"
if [ -f ${OlderFile} ]; then
rm -f ${OlderFile}
fi
if [ -f ${OlderCronFile} ]; then
rm -f ${OlderCronFile}
fi
#备份新文件
crontab -l > ${BAK_DIR}/cron${YESTERDAY}.txt
date "+%Y-%m-%d %H:%M:%S" > nohup.out
nohup exp mailto:system/manager@$1]system/manager@$1 parfile=../parfile.ini file=${BAK_FILE} log=${LOG_FILE} 1>/dev/null 2>&1 &