-
-
Save junxie6/f7c0c278d02e63e1c62b7a462a0f3836 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mysqlbinlog56=/store/mysql-5.6.23-linux-glibc2.5-x86_64/bin/mysqlbinlog | |
mysqlclient=/store/mysql-5.6.23-linux-glibc2.5-x86_64/bin/mysql | |
pidfile=/var/run/binlogstream.pid | |
binlogdir=/store/binlogstreamer/binlogs | |
binlogprefix=mysql-bin | |
mysqluser=tester | |
mysqlpass=tester | |
mysqlmaster=10.72.100.236 | |
daystokeep=10 # will in fact be one day more if compression is used | |
compress=1 | |
streamer_slave_id=384596821 | |
# Remove old files | |
/bin/find $binlogdir -ctime +$daystokeep | grep $binlogprefix | /usr/bin/xargs /bin/rm -f | |
# Compress files that are done, not the last one | |
if [ "$compress" -eq 1 ]; then | |
ls ${binlogdir}/${binlogprefix}.* | grep -v bz2 | head -n -1 | /usr/bin/xargs bzip2 | |
fi | |
/bin/kill -0 `cat $pidfile` | |
if [ "$?" -eq "0" ]; then | |
#echo "running" | |
exit | |
else | |
#echo "not running" | |
cd $binlogdir | |
lastfile=`ls $binlogprefix* | sort -n | tail -1` | |
if [ -z "$lastfile" ]; then | |
lastfile=`$mysqlclient -BN -u $mysqluser --password=$mysqluser --host=$mysqlmaster -e 'show master status;' 2> /dev/null | awk '{ print $1 }'` | |
fi | |
$mysqlbinlog56 --stop-never-slave-server-id=$streamer_slave_id --read-from-remote-master=BINLOG-DUMP-NON-GTIDS --host=$mysqlmaster --raw --stop-never -u $mysqluser --password=$mysqluser $lastfile 2> /dev/null & | |
echo -n $! > $pidfile | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment