#!/bin/bash logfile='/alidata1/bak/bakdata.log' bakdir='/alidata1/bak/' year=`date "+%Y"` today=`date "+%j"` prev7date=`date -d "-8 day" "+%Y%m%d"`; bakdate=`date "+%Y%m%d"` bakfile=${bakdir}${bakdate}.dbname.sql bakprevfile=${bakdir}${prev7date}.dbname.sql if [[ -f $bakprevfile ]]; then echo "删除一周前的文件" >> $logfile rm -f $bakprevfile fi mysqldump -uroot -p'password' dbname > $bakfile