#!/bin/bash
binlog=$(mysql -uroot --execute="SHOW MASTER STATUS\G" | grep 'File:' | cut -d: -f2 | sed 's/^ //')

# binlog++
base=$(echo $binlog | cut -d. -f1)
number=$(echo $binlog | cut -d. -f2 | sed 's/^0*//')
number=$(($number+1))
binlog=$base.$(printf "%06d" $number)

echo 'FLUSH'
mysql -uroot --execute="FLUSH /*!50503 BINARY */ LOGS"

echo 'SLEEP'
mysql -uroot --execute="DO SLEEP(10)"

echo "PURGE TO $binlog"
mysql -uroot --execute="PURGE BINARY LOGS TO '$binlog'"
