Backing up binary log files with mysqlbinlog

Backing up binary logs are essential part of creating good backup infrastructure as it gives you the possibility for point in time recovery. After restoring a database from backup you have the option to recover changes that happend after taking a backup. The problem with this approach was that you had to do periodic filesystem level backups of the binary log files which could still lead to data loss depending on the interval you back them up. Recently in MySQL 5.6, mysqlbinlog got a new feature addition that supports connecting to remote MySQL instances and dumping binary log data to local disks ( http://dev.mysql.com/doc/refman/5.6/en/mysqlbinlog-backup.html ). This can be used as a foundation of our live binary log backups.

The wrapper script below will connect to the remote server specified in the config and ensure mysqlbinlog utility is up and running. By default if you do not supply the binary log file, mysqlbinlog deletes and overwrites them all that is undesired behaviour in our case, so we have to supply the name of the last binary log. This last file will be still overwritten hence we make a backup first.

Many thanks for this add, i have tried this on my production system all went well with one exception, once all the binlogs has been backed up and we re remained with the last one we start having multiple backups of the same binlog just identified with timestamp is this how its men’t to do?

Two questions about this line $MBL –raw –read-from-remote-server –stop-never –host $MYSQLHOST –port $MYSQLPORT -u $MYSQLUSER -p$MYSQLPASS $LASTFILE 1 At start ,$LASTFILE would be null,and the script wouldn’t work as you don’t specify the binlog file 2 If I ran this command ,the bin log would be in the script dir, not in the $BACKUPDIR

@jadd I agree with your $LASTFILE statement, this should be populated by looking at the binlog folder instead of the backup folder, or by running show binary logs on the server. The $BACKUPDIR would contain the backup files, as the script does a cd $BACKUPDIR on line 4 before doing anything else.