简体   繁体   English

在 MySQL 中进行增量备份的最佳方法是什么?

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

We are using MySQL version 5.0 and most of the tables are InnoDB.我们使用的是 MySQL 5.0 版,大多数表都是 InnoDB。 We run replication to a slave server.我们运行复制到从服务器。 We are thinking of backing up the MySQL log files on a daily basis.我们正在考虑每天备份 MySQL 日志文件。

Questions问题

  • Is there any other way of doing an incremental backup without using the log files?有没有其他方法可以在不使用日志文件的情况下进行增量备份?
  • What are the best practices when doing incremental backups?进行增量备份时的最佳做法是什么?

AFAIK the only way of doing incremental backups is by using the binary-log. AFAIK 进行增量备份的唯一方法是使用二进制日志。 You have other options if you want to do full backups (InnoDB hotcopy), but incremental means that you need to log all transactions made.如果要进行完整备份(InnoDB 热复制),您还有其他选择,但增量备份意味着您需要记录所有事务。

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.我可能会每 1 小时轮换一次日志并备份它。 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.意思是,恢复将使数据最多保留 1 小时,并且您可以恢复到自上次完整快照以来的任何时间点。

You can dump your schemas regularly with mysqldump, using always the same file name and path for each schema (ie replacing the latest one)您可以使用 mysqldump 定期转储您的架构,为每个架构始终使用相同的文件名和路径(即替换最新的)

Then combine that with any backup tool that supports incremental/delta backup, for example rdiff-backup, duplicity, Duplicati or Areca Backup.然后将其与任何支持增量/增量备份的备份工具结合使用,例如 rdiff-backup、duplicity、Dupplicati 或 Areca Backup。 An example from duplicity docs: Duplicity 文档中的一个示例:

Because duplicity uses librsync, the incremental archives are space efficient and only record the parts of files that have changed since the last backup由于 duplicity 使用 librsync,增量存档节省空间,并且只记录自上次备份以来更改的文件部分

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.您可以恢复任何时间点的 mysqldump 文件,然后将该文件恢复到 MySQL 中。

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. Percona XtraBackup - 是基于 MySQL 的服务器的开源热备份实用程序,在备份期间不会锁定您的数据库。 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. mysqlbackup是一个实用程序,包含在 mysql 企业版中。 It is a lot like percona xtrabackup.它很像 percona xtrabackup。 A detailed comparison详细对比
    can be found here可以在这里找到
    It has the parameter --incremental which allows you to make incremental backups.它有参数--incremental允许您进行增量备份。 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.这两个实用程序进行物理备份(复制数据库文件),但您仍然可以对 binlog 文件进行逻辑备份。

You can either write a script by yourself or use a ready-made script from github:你可以自己写一个脚本,也可以使用github上现成的脚本:

macournoyer/mysql_s3_backup macournoyer/mysql_s3_backup

Abhishek-S-Patil/mysql-backup-incrementalAbhishek-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.在另一个不相关的服务器上定期测试和运行恢复脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM