Skip to content
A simple script that uses mysqlbinlog to backup and compress mysql binlog files
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore updated readme Mar 10, 2019
LICENSE Initial commit Mar 9, 2019 Update blog post Jun 30, 2019 updated readme Mar 10, 2019


This is a simple bash script that encapsulates mysqlbinlog utility to backup and compress binlog files. See the blog post .


  • Live backup of binlogs (handled by mysqlbinlog already)
  • Compression of backup files
  • Rotation of backup files


Clone the repository and run:

chmod +x
./ --help

This will output:

Usage: [options]
    Starts live binlog sync using mysqlbinlog utility

  --backup-dir=        Backup destination directory (required)
  --log-dir=           Log directory (defaults to '/var/log/syncbinlog')
  --prefix=            Backup file prefix (defaults to 'backup-')
  --mysql-conf=        Mysql defaults file for client auth (defaults to './.my.cnf')
  --compress           Compress backuped binlog files
  --compress-app=      Compression app (defaults to 'pigz -p{number-of-cores - 1}'). Compression parameters can be given as well (e.g. pigz -p6 for 6 threaded compression)
  --rotate=X           Rotate backup files for X days (defaults to 30)
  --verbose=           Write logs to stdout as well

Example: Backup binlog files of last 10 days and compress them

./ --backup-dir=/mnt/backup --prefix="mybackup-" --compress --rotate=10


  • In a production database server, it should be controlled by a process manager such as systemd or supervisord to have more reliable start/restart behaviour.
  • mysqlbinlog utility copies the binlog files in real-time, however compression is only applied for files older than the one being written at the time. This happens when:
    • Mysql flushes the log files after a certain time or certain file size. (See expire_logs_days and max_binlog_size)
    • FLUSH LOGS is executed manually or by mysqldump etc.
  • mysqlbinlog utility requires the user to have REPLICATION SLAVE privilege


Some useful resources about binlog backup and point-in-time-recovery:



You can’t perform that action at this time.