一、编辑备份脚本

# vim /opt/script/mysql_backup.sh
#!/bin/bash
#By martin.liu
Today=`date +%Y%m%d`
BackupPath=/usr/local/mysql_backup
BackupLog=bak_$Today.log
BackupFile=$Today.tar.gz

DBUser=root
DBPassword='123456'
DBHost=localhost

mkdir -p $BackupPath/$Today
innobackupex --user=$DBUser --password=$DBPassword  --slave-info --stream=tar $BackupPath/$Today/ 2> $BackupPath/$Today/$BackupLog | gzip 1> $BackupPath/$Today/$BackupFile

其作用是将MySQL内的所有数据进行全量备份。


二、添加计划任务

# crontab -e

加入

45 2 * * * /opt/script/mysql_backup.sh

每天凌晨两点四十五分执行一次脚本,完成全量热备