5.1 执行恢复操作

执行恢复操作 的mysqlbackupcopy-back-and-apply-log命令是 和copy-back(仅用于目录备份;参见第 5.1.7 节,“高级:准备和恢复目录备份”)。通常,恢复过程需要数据库服务器已经关闭(或者,至少不在您要将数据恢复到的目录上运行),除了恢复使用--use-tts选项创建的备份;请参阅 下面的解释。该过程将数据文件、日志和其他备份文件从备份目录复制回其原始位置,并对它们执行任何所需的后处理。

示例 5.1 恢复数据库

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

copy-back-and-apply-log命令实现了两件事:

  • 从映像文件中提取备份并将其复制到要还原的服务器上的数据目录中。

  • 对恢复的数据执行应用日志操作以使它们保持最新。

请参阅第 4.2.4 节 “恢复数据库”,了解恢复操作中使用的重要选项,如 --defaults-file--datadir--backup-image--backup-dir

还原的数据包括backup_history 表,MySQL Enterprise Backup 记录了每个备份的详细信息。该表允许您使用该 选项执行未来的增量备份。 --incremental-base=history:{last_backup | last_full_backup}

重要的
  • When performing a restore, make sure the target directories for restore data are all clean, containing no old or unwanted data files (this might require manual removal of files at the locations specified by the --datadir, --innodb_data_home_dir, --innodb_log_group_home_dir, and --innodb_undo_directory options). The same cleanup is not required for restoring backups created with the--use-tts option (in which case other requirements described in Section 5.1.4, “Restoring Backups Created with the --use-tts Option” apply though).

  • After a full restore, depending on how you are going to start the restored server, you might need to adjust the ownership of the restored data directory. For example, if the server is going to be started by the user mysql, use the following command to change the owner attribute of the data directory and the files under it to the mysql user, and the group attribute to the mysql group.

    $ chown -R mysql:mysql /path/to/datadir
  • Because mysqlbackup does not support MySQL server's online DDL feature feature, a backup might become corrupted if, during the backup process, a DDL operation that took advantage of the feature occurred. To avoid the issue, mysqlbackup turns the server's system variable old_alter_table to 1 at the beginning of a backup if it is 0, so that any DDL operations that take place during the backup are handled with the old table copy method. mysqlbackup then turns the variable back to 0 near the end of the backup operation.

    Notice that in cases where mysqlbackup quits unexpectedly and does not turn old_alter_table back to its original value, the user will have to turn the value back to 0 manually on the server, in order to return the server to its original configuration. This should be performed if the statement Server system variable 'old_alter_table' was set to '0'. Setting it to '1' appears in the early output of mysqlbackup, but the statement Setting server system variable 'old_alter_table' back to '0'在mysqlbackup退出之前不会出现 。

以下小节描述了用于恢复备份的许多不同场景。