#!/bin/bash
# 10 23 * * * /bin/bash /data/script/backup_mysqldump.sh
BDATE=`date +%Y%m%d%H%M%S`
BPATH=/data/backup
LOGFILE=${BPATH}/log_${BDATE}.log
mysqldump -uroot -pchengce243 -S /var/lib/mysql/mysql.sock trade_history -P3306 --single-transaction > ${BPATH}/trade_history_${BDATE}.sql
echo > ${LOGFILE}
for tfile in $(find $BPATH/ -mtime +7)
do
if [ -d $tfile ];then
rm -rf $tfile
elif [ -f $tfile ];then
rm -rf $tfile
fi
echo -e "---- Delete backup file: $tfile ------" >> ${LOGFILE}
done
echo -e "\n====== Backup Jobs end at `date +%F' '%T' '%w` =====\n">> ${LOGFILE}