日期:2014-05-16  浏览次数:20811 次

linux shell脚本加定时器自动备份mysql
输入命令
vi mysqlAutoBak.sh

输入下面的内容
#!/bin/bash
bakdate=`date -I`
olddate=`date -d'5 days ago' -I`
bakdir=/data/backup
mysqldump=/usr/bin/mysqldump
pass=111111

[ ! -d $bakdir ] && mkdir -p $bakdir
for dbname in roadshow mss
do
        $mysqldump  -p$pass -R $dbname > $bakdir/$dbname.sql
        tar czf $bakdir/$dbname.$bakdate.sql.tar.gz $bakdir/$dbname.sql
        rm -f $bakdir/$dbname.sql
        rm -f $bakdir/$dbname.$olddate.sql.tar.gz
done


输入命令
corntab -e

添加定时任务

15 00 * * * /root/mysqlAutoBak.sh > /var/log/mysqlAutoBak.log 2>&1