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

Files

Permalink
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
NOTES.md
README.md Update blog post Jun 30, 2019
syncbinlog.sh updated readme Mar 10, 2019

README.md

About

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

Features

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

Usage

Clone the repository and run:

chmod +x syncbinlog.sh
./syncbinlog.sh --help

This will output:

Usage: syncbinlog.sh [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

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

Notes

  • 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

Resources

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

License

MIT

You can’t perform that action at this time.