Documentation Home

5.1.3 恢复增量备份

在不同的场景下,使用增量备份来恢复数据库有不同的方式。首选方法是首先恢复完整备份并使用命令将其更新到执行完整备份时的时间 (有关如何执行此 操作的信息,copy-back-and-apply-log请参见 示例 5.1 “恢复数据库”copy-back-and-apply-log ),然后使用再次在刚刚恢复的完整备份之上恢复增量备份映像:

示例 5.6 恢复增量备份映像

mysqlbackup --defaults-file=<my.cnf> -uroot --backup-image=<inc_image_name> \
  --backup-dir=<incBackupTmpDir> --datadir=<restoreDir> --incremental \
  copy-back-and-apply-log


在这个例子中,命名的增量备份映像 <inc_image_name>被恢复到 <restoreDir>服务器上(增量备份映像所基于的完整备份已经被恢复)。该 --backup-dir选项用于指定保存临时输出、状态文件和备份元数据的临时目录。对您拥有的其他增量备份映像重复该步骤,直到数据已恢复到所需的时间点。

高级:恢复增量备份目录

增量目录备份可以通过一系列 copy-back-and-apply-log命令恢复,如上图所示的单文件备份。或者,在进行增量备份之后和恢复数据之前的任何时间,您都可以使完整备份与增量备份保持同步。首先,将备份运行时发生的任何更改应用于完整备份:

$ mysqlbackup --backup-dir=/full-backup/2010-12-08_17-14-11 apply-log
..many lines of output...
101208 17:15:10  mysqlbackup: Full backup prepared for recovery successfully!

101208 17:15:10 mysqlbackup: mysqlbackup completed OK!

然后,我们使用以下 apply-incremental-backup命令应用增量备份中的更改:

$ mysqlbackup --incremental-backup-dir=/incr-backup/2010-12-08_17-14-48 
  --backup-dir=/full-backup/2010-12-08_17-14-11 apply-incremental-backup
...many lines of output...
101208 17:15:12 mysqlbackup: mysqlbackup completed OK!

现在,完整备份目录中的数据文件是完全最新的,截至上次增量备份时。您可以使用更多增量备份不断更新它,以便随时可以恢复它。

二进制日志和中继日志恢复

When an incremental backup is being restored using either the copy-back-and-apply-log or apply-incremental-backup command, the binary log (and also the relay log, in the case of a replica server), if included in the incremental backup, is also restored to the target server by default. This default behavior is overridden when either (1) the --skip-binlog option (or the --skip-relaylog option for the relay log) is used with the restore command, or (2) if the full backup the incremental backup was based on or any prior incremental backup that came in between the full backup and this incremental backup has the binary log (or relay log) missing (in both cases, for MySQL Enterprise Backup 4.1.5 and later, mysqlbackup renamed any binary log (but not relay log) files and their index files that have already been restored onto the server by adding the .old extension to their file names).

For release 4.1.2 and later: Location of the binary log (or relay log) after an incremental backup is restored is, by default, the same as the log's location on the backed-up server when the incremental backup was taken, or as specified by the --log-bin (or --relay-log) option during the restore of the incremental backup.

对于 4.1.1 及更早版本:增量备份恢复后二进制日志(或中继日志)的位置是恢复服务器的数据目录。

有关增量备份的更多详细信息,请参阅第 4.3.3 节“进行差异备份或增量备份”第 16.7 节“增量备份选项”