用于批量清除过期的binlog日志,以释放磁盘空间,检测磁盘用量使用df命令。
问题描述: 创建一个shell脚本,进行批量清除操作,方案思路大概如下:
1,建立双master列表masterlist; 一个master一行。
clearbinlog.sh脚本:
复制代码代码示例:
#!/bin/bash
# #site:www.it.net.cn 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脚本:
最后,再次check disk space,执行check_disk.sh脚本。
复制代码代码示例:
for masterdb in `master.db.full`;do
ssh $masterdb "df -h" |grep -i mysqldatadir; done; 执行sh check_disk.sh开始check检测。 (责任编辑:IT) |