修改/etc/my.cnf下面四个配置,没有的话就加入这四个。
log-bin=mysql-bin
binlog_format=mixed
expire_logs_days=7
binlog-do-db=your_db
查看binlog
mysqlbinlog --no-defaults mysql-bin.000001 | more
恢复binlog
./mysqlbinlog --start-date="yyyy-MM-dd HH:mm:ss" --stop-date="yyyy-MM-dd HH:mm:ss" /usr/local/mysql/data/mysql-bin.xxxxx /usr/local/mysql/data/mysql-bin.xxxxxx |mysql -u root -ppassword
mysql定时备份脚本
#!/bin/bash
#Name:bakmysql.sh#This is a ShellScript For Auto DB Backup and Delete old Backupbakpath=/data/bakmysqltime=·`date +%Y%m%d%H `mysqldump -uxxxx -pxxxx database_xxxx | gzip > $bakpath/backname$time.sql.gz#find $bakpath -name "backname_*.sql.gz" -type f -mtime +7 -exec rm {} \; > /dev/null 2>&1
修改crontab
5 3 * * * root /usr/sbin/bakmysql.sh
/etc/init.d/crond restart