#! /bin/bash
FILEDIR=/data/mysql_backup
MYSQLUSER=user
MYSQLPASS=pass
MYSQLHOST=127.0.0.1
cd $FILEDIR
YESTODAY=`date -d "-1 days" +%Y-%m-%d`
mysqldump -u$MYSQLUSER -p$MYSQLPASS -h$MYSQLHOST db1 > $FILEDIR/db1-$YESTODAY.sql
mysqldump -u$MYSQLUSER -p$MYSQLPASS -h$MYSQLHOST db2 > $FILEDIR/db2-$YESTODAY.sql
mysqldump -u$MYSQLUSER -p$MYSQLPASS -h$MYSQLHOST db3 > $FILEDIR/db3-$YESTODAY.sql
tar czvf dbBackUp-$YESTODAY.tar.gz ./*.sql
rm -f ./*.sql
上面是可以备份的文件.大概就是,备份打包.
接下来,可以使用crontab 添加一个任务.每天定时执行该脚本
crontab -e
10 * * * * /data/mysql_backup/back.sh //back.sh为备份的shell脚本