What is the best way to do incremental backups in MySQL?

You can dump your schemas regularly with mysqldump, using always the same file name and path for each schema (i.e. replacing the latest one)

Then combine that with any backup tool that supports incremental/delta backup, for example rdiff-backup, duplicity, Duplicati or Areca Backup. An example from duplicity docs:

Because duplicity uses librsync, the incremental archives are space efficient and only record the parts of files that have changed since the last backup

That way your first backup would be the compressed copy of the 1st full dump, and the second would contain the compressed differences from the 1st and 2nd dump and so on. You can restore the mysqldump file of any point in time and then restore that file into MySQL.


AFAIK the only way of doing incremental backups is by using the binary-log. You have other options if you want to do full backups (InnoDB hotcopy), but incremental means that you need to log all transactions made.

You need to ask yourself why you're backing up data. Since you have a slave for replication, I assume the backup is primarly for reverting data in case of accidental deletion?

I would probably rotate the logs every 1 hour and take a backup of it. Meaning, restoring would leave the data at most 1 hour old, and you can restore to any point in time since the last full snapshot.


A lot of time has passed since the last answer, and during this time several solutions and tools have appeared for implementing incremental backups.

Two main ones:

  • Percona XtraBackup - is an open-source hot backup utility for MySQL - based servers that doesn’t lock your database during the backup. It also allows you to create incremental backups. More details here.

    It's pretty simple and looks something like this:

    xtrabackup --backup --target-dir=/data/backups/inc1 --incremental-basedir=/data/backups/base
    
  • mysqlbackup is an utility, that is included in the mysql enterprise edition. It is a lot like percona xtrabackup. A detailed comparison
    can be found here
    It has the parameter --incremental which allows you to make incremental backups. More details here

    mysqlbackup --defaults-file=/home/dbadmin/my.cnf --incremental --incremental-base=history:last_backup --backup-dir=/home/dbadmin/temp_dir --backup-image=incremental_image1.bi backup-to-image
    

These two utilities make physical backups (copy database files), but you can still make logical backups of binlog files.

You can either write a script by yourself or use a ready-made script from github:

macournoyer/mysql_s3_backup

Abhishek-S-Patil/mysql-backup-incremental

There are also paid solutions that are, in fact, beautiful wrappers for these tools:

SqlBak

databasethink

What are the best practices when doing incremental backups?

It all depends on your architecture, the amount of data, the maximum allowable downtime interval that is acceptable for you. The maximum allowable data loss interval. Consider these things before setting up backups.

I would like to mention only one good practice, but very important, and which is very often forgotten. Test and run the recovery script regularly on another unrelated server.