mysql备份与binlog
修改/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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。