MySQL incremental backups per database (not global)

backupMySQLreplication

While searching for free/open-source MySQL incremental backups solutions I have found a number of ways to do incremental backups and all of them seem to either rely on "logical" way of backups/restore like mysqldump and binlog (or LSN) or "physical" way (like Percona's xtrabackup). However, in both cases the only scenario implied is backing up the database globally (all databases).

I am looking for the way to provide incremental backups per database: there are two db servers (master and slave) and each handles lots of databases. Each of these databases belong, let's say, to different customers and some of them tend to grow really big. While software upgrades database schema sometimes changes and before the upgrade we must make sure we are on the safe side so backup is a must but full backup is definitely not a way to go due to database sizes.

Please advise how this can be solved or at least suggest some ways to look for solution.

Best Answer

You can read binlogs with the mysqlbinlog tool, and produce a stream of logical changes, like a mysqldump backup. The mysqlbinlog has an option --database=dbname so you can extract only changes pertaining to the named database.

Read more about using this option here: http://dev.mysql.com/doc/refman/5.6/en/mysqlbinlog.html#option_mysqlbinlog_database

Two caveats:

  • This assumes that you have a continuous set of binary logs back either to the last full backup or to the last incremental dump.

  • It's not really a filter for changes to dbname. It's a filter for all binlog events applied to any database while dbname was selected as the default database. So if you have an event where someone updated dbname2.tablename while dbname was the default, then the dump will include that change to dbname2.

    This makes this method unsafe to use this as a per-database incremental backup method, unless you have 100% certainty that no such transactions occurred.

P.S.: Your comments about LSN are a bit incorrect. Mysqldump knows nothing about the LSN, which is a feature of the InnoDB redo log. Mysqldump does examine the binary log position, and can output that position if you use the option --master-data.