就两个文件, 本人学识尚浅,不解释,怕大佬喷。
back.sh
#/bin/bash MYSQLUSER=root MYSQLPWD=lizhenghua DATABASES=zskdb MYSQLDATASAVEDIR=/home/mysql DATAFILENAME=zskdb.sql DATETIME=`date "+%Y-%m-%d"` mysqldump -u ${MYSQLUSER} -p${MYSQLPWD} --databases ${DATABASES} > ${MYSQLDATASAVEDIR}/${DATAFILENAME} echo "**************压缩***************" zip -r -9 -q -o ${DATETIME}.zip ./*.sql /usr/bin/sleep 3 echo echo "**************清理*************" if [[ "${DATETIME}.zip" != "" ]] then echo "数据库已备份,准备删除多于文件" /usr/bin/sleep 2 rm -rf ${DATAFILENAME} echo else echo "数据库未备份,准备重新备份" /usr/bin/sleep 2 zip -r -9 -q -o ${DATETIME}.zip ./*.sql echo fi
cron.sh
#/bin/bash PATH=`pwd` FILE=back.sh echo "0 0 * * * ${PATH}/${FILE}" > /var/spool/cron/${USER}
两个文件放在一起。