批量清除过期的binlog日志释放磁盘空间的shell脚本
问题描述:
大量dml操作导致N多binlog产生,需要清除已sync过的binlog日志,12组nodes MySQL DB,每组2台Master-Master,需要批量清除过期的binlog释放磁盘空间。
创建一个shell脚本,进行批量清除操作,方案思路大概如下:
1,建立双master列表masterlist; 一个master一行。
2,远程获取master db上面的binlog位置以及对应master的master主机名(也许是ip地址)
3,拿到binlog位置以及master主机名,然后ssh远程清理掉远程master上面的binlog
4,采用shell for循环操作step 2以及step 3。
clearbinlog.sh脚本:
#
#site:www.jiaochengji.com
for masterdb in `cat master.db.full`;do
#1 echo get the binlog position infomation
str_log_files=`ssh $masterdb "/opt/mysql/product/5.5.25a/bin/mysql -uroot --password="" -e \"show slave status\G;\" |grep -i master_Log_File "`
echo $str_log_files;
log_file=`echo $str_log_files | awk '{print $2}'`;
echo $log_file;
#2 echo get the master ip address or master hostname
db01tmp=`ssh $masterdb " /opt/mysql/product/5.5.25a/bin/mysql -uroot --password="" -e \"show slave status\G;\" |grep -i Master_Host "`;
db01=`echo $db01tmp | awk '{print $2}'`
#3 begin to clear the old binlog
ssh $db01 "/opt/mysql/product/5.5.25a/bin/mysql -uroot --password="" -e \"purge master logs to '$log_file';\""
#4 check the disk space for master
ssh $db01 "df -h"
echo " "
echo " -- -- -- ";
done;
运行sh脚本:
sh clearbinlog.sh
开始清理所有db的binlog。
最后,再次check disk space,执行check_disk.sh脚本。
脚本内容:
ssh $masterdb "df -h" |grep -i mysqldatadir;
done;
执行sh check_disk.sh开始check检测。
猜你喜欢:
清理多台MySQL数据库的过期binlog日志的shell脚本
mysql binlog 自动清理脚本
批量清除128组节点db上过期的binlog释放磁盘空间的shell脚本
您可能感兴趣的文章:
批量清除过期的binlog日志释放磁盘空间的shell脚本
批量清除128组节点db上过期的binlog释放磁盘空间的shell脚本
自动与手动清理mysql-binlog日志的方法
mysql删除binlog日志及使用日志恢复数据的方法
清理多台MySQL数据库的过期binlog日志的shell脚本
MySQL数据库二进制日志备份和恢复步骤
mysqldump使用binlog二进制日志进行备份的例子
mysql的binlog日志删除与限制大小
mysql 主从同步一例
自动清理binlog日志与手动删除binlog日志的方法