Monday, May 9, 2011

Simple Script for Autorotate the mysqld-slow-query.log

This script is for Autorotate the mysqld-slow-query.log

#Start script
#!/bin/bash

SERVER=`hostname`

DATE=`date +%Y%m%d_%H%M`

logsize=`ls -l /mysql/mysqld-slow-query.log | awk -F" " '{print $5}'`
echo "LogSizeNow = $logsize";

limit=100000000
#Limit 100MB log file auto rotate

if [ $logsize -gt $limit ];

then


        echo "Rotating MYSQL Slow Queries";

        #Actions
        cp /mysql/mysqld-slow-query.log /home/mysql-slow-query/mysqld-slow-query.log-$DATE
        echo "" > /mysql/mysqld-slow-query.log
        bzip2 /home/mysql-slow-query/mysqld-slow-query.log*

        echo "Done Zipping mysql slow queries";

else

        echo "The Log file still not big enough";

fi



#End of Script

dont forget to "chmod +x <your_script.sh>" and put it in the Cron jobs :)
Cheers!!!

Author : IndraSusanto

No comments:

Post a Comment