binlogserver build

In MySQL 5.7.x version, mysqlbinlog tool to resolve any of the binlog or a local relay log, will not be an additional rollback statement at the end of execution mysqlbinlog command,

When mysqlbinlog command exits will be added rollback statement but when the MySQL 5.6.x version, mysqlbinlog tool parses each local relay log and binlog
 
binlog incremental backup is one of the essential, and in some scenarios, real-time or scheduled backup binlog is necessary.
In fact, the official mysqlbinlog comes with this feature.
MySQL Binlog Server: is the use of a tool, the active online library to pull logs for backup. After MySQL 5.6, mysqlbinlog can use this command to the remote machine's log backup to a local directory, so as to achieve incremental backup or log security.

Common parameters:
-R & lt | --read-from-Remote-Server indicates turning binlog backup request to the local binlog on a corresponding master node.
--raw be copied binlog stored in binary format, if not the argument was text format.
-r | --result-file in the specified directory or file name: --raw if the parameter is specified, the value of the specified binlog -r storage directory and file name prefix; if you do not specify --raw parameter, the value of the specified text -r store directory and file name.
-t This option represents the beginning pulled from the specified binlog, until the current master binlog last.
--stop-never sustained continuously pulled from the master node the binlog, continuous backup to a last current, and continue. The parameter contains -t
--stop-Never-Slave-Server-ID 65535 default values for a plurality of processes or mysqlbinlog from the server, the ID to avoid conflicts.
 
After mysqlbinlog open back up until the connection is closed or is forced to kill it will end.
You can view the backup process has been opened by ps.
Example usage: full and remain as the remote server's local binlog pulled, and stored in / data / backup_binlog directory.
Note, -r specified directory must be written, otherwise you will be placed in the / data directory and to "backup_binlog" as the prefix name binlog
such as: -r / data / backup_binlog appears as / data / backup_binlog / mysql-bin .000008
 
mkdir -p /data/backup_binlog
mysqlbinlog -h$ip -P$port -u$user -p$password -R --raw --stop-never mysql-bin.000008 -r /data/backup_binlog/ &
 

# cat bakbinlog.sh
#!/bin/bash
MBL=/usr/local/mysql/bin/mysqlbinlog
MYB=/usr/local/mysql/bin/mysql
MYSQLHOST=192.168.1.101
MYSQLPORT=3306
MYSQLUSER=dba_user
MYSQLPASS=msds007
BACKUPDIR=/data/backup_binlog/$MYSQLHOST/
RESPAWN=10
FIRSTBINLOG=`$MYB -u$MYSQLUSER -p$MYSQLPASS -h$MYSQLHOST -P$MYSQLPORT -e "show master status;" | grep bin | awk '{print $1}'`
mkdir -p $BACKUPDIR
while :
do
    if [ `ls -A "$BACKUPDIR" | wc -l` -eq 0 ];then
        LASTFILE=$FIRSTBINLOG
    else
        LASTFILE=`ls -al "$BACKUPDIR" | tail -n 1 | awk '{print $9}'`
    fi
    echo 'Starting live binlog backup'
    $MBL -h$MYSQLHOST -P$MYSQLPORT -u$MYSQLUSER -p$MYSQLPASS -R --raw --stop-never $LASTFILE -r $BACKUPDIR
    echo 'mysqlbinlog exited with $? trying to reconnect in $RESPAWN seconds'
    sleep $RESPAWN
done
 
# sh bakbinlog.sh > mybakbinlog.log 2>&1 &
 

 

Guess you like

Origin www.cnblogs.com/allenhu320/p/11365659.html