Now, suppose that we have a catastrophic unexpected exit on Wednesday at 8 a.m. that requires recovery from backups. To recover, first we restore the last full backup we have (the one from Sunday 1 p.m.). 现在,假设我们在周三上午8点发生了灾难性的意外退出,这需要从备份中恢复。要恢复,首先我们恢复我们拥有的最后一个完整备份(周日下午1点的备份)。The full backup file is just a set of SQL statements, so restoring it is very easy:完整备份文件只是一组SQL语句,因此还原它非常容易:
shell> mysql < backup_sunday_1_PM.sql
At this point, the data is restored to its state as of Sunday 1 p.m.. 此时,数据已恢复到周日下午1点的状态。To restore the changes made since then, we must use the incremental backups; that is, the 为了恢复自那时以来所做的更改,我们必须使用增量备份;即gbichot2-bin.000007
and gbichot2-bin.000008
binary log files. gbichot2-bin.000007
和gbichot2-bin.000008
二进制日志文件。Fetch the files if necessary from where they were backed up, and then process their contents like this:如有必要,从备份文件的位置获取文件,然后按如下方式处理其内容:
shell> mysqlbinlog gbichot2-bin.000007 gbichot2-bin.000008 | mysql
We now have recovered the data to its state as of Tuesday 1 p.m., but still are missing the changes from that date to the date of the crash. 我们现在已经将数据恢复到周二下午1点的状态,但仍然缺少从该日期到坠机日期的变化。To not lose them, we would have needed to have the MySQL server store its MySQL binary logs into a safe location (RAID disks, SAN, ...) different from the place where it stores its data files, so that these logs were not on the destroyed disk. 为了不丢失它们,我们需要让MySQL服务器将其MySQL二进制日志存储到与存储数据文件的位置不同的安全位置(RAID磁盘、SAN等),这样这些日志就不会在被销毁的磁盘上。(That is, we can start the server with a (也就是说,我们可以使用--log-bin
option that specifies a location on a different physical device from the one on which the data directory resides. That way, the logs are safe even if the device containing the directory is lost.) --log-bin
选项启动服务器,该选项指定与数据目录所在的物理设备不同的物理设备上的位置。这样,即使包含目录的设备丢失,日志也是安全的。)If we had done this, we would have the 如果我们这样做了,我们手头就有gbichot2-bin.000009
file (and any subsequent files) at hand, and we could apply them using mysqlbinlog and mysql to restore the most recent data changes with no loss up to the moment of the crash:gbichot2-bin.000009
文件(以及任何后续文件),我们可以使用mysqlbinlog和mysql应用它们来恢复到崩溃时刻为止的最新数据更改,而不会丢失:
shell> mysqlbinlog gbichot2-bin.000009 ... | mysql
For more information about using mysqlbinlog to process binary log files, see Section 7.5, “Point-in-Time (Incremental) Recovery”.有关使用mysqlbinlog处理二进制日志文件的更多信息,请参阅第7.5节,“时间点(增量)恢复”。