码迷,mamicode.com
首页 > 数据库 > 详细

mysql备份与binlog

时间:2015-02-09 17:49:41      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

修改/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 Backup
bakpath=/data/bakmysql
time=·`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

 

mysql备份与binlog

标签:

原文地址:http://www.cnblogs.com/yachi/p/4281739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!