#!/bin/bash
backupDIR=/opt/dm/dmbak
runTime=`date +%Y%m%d_%H%M`
logFile=${backupDIR}/log/backup_${runTime}.log
deleteTime=30
user=SYSDBA
passwd=SYSDBA
port=5236
#删除30天前的备份文件
find ${backupDIR} -type f -name "*.dmp" -ctime +${deleteTime} -exec rm -f {} \; >> ${logFile} 2>&1
#删除30天前的日志
find ${backupDIR} -type f -name "*.log" -ctime +${deleteTime} -exec rm -f {} \; >> ${logFile} 2>&1
#四种级别:full,owner,schemas,tables
#全库导出full
/opt/dmdbms/bin/dexp ${user}/${passwd}:${port} DIRECTORY=${backupDIR} FILE=fullbak_${runTime}.dmp full=y LOG=exp_fullbak_${runTime}.log >> ${logFile} 2>&1
#owner,schemas,tables
#遍历需要导出的数据库,导出命令中的OWNER也可以是SCHEMAS或TABLES,for循环中写要备份的内容
#for line in user1 user2 user3
#do
#./dexp ${user}/${passwd}:${port} DIRECTORY=${backupDIR} FILE=${line}_${runTime}.dmp OWNER=${line} LOG=exp_${line}_${runTime}.log >> ${logFile} 2>&1
#done
----添加到定时器里每天晚上执行
service crond restart
30 23 * * * /opt/back_up_data.sh