This section describes the characteristics of different types of backups.本节介绍不同类型备份的特征。
Physical backups consist of raw copies of the directories and files that store database contents. 物理备份由存储数据库内容的目录和文件的原始副本组成。This type of backup is suitable for large, important databases that need to be recovered quickly when problems occur.这种类型的备份适用于需要在出现问题时快速恢复的大型重要数据库。
Logical backups save information represented as logical database structure (逻辑备份保存表示为逻辑数据库结构(CREATE DATABASE
, CREATE TABLE
statements) and content (INSERT
statements or delimited-text files). CREATE DATABASE
、CREATE TABLE
语句)和内容(INSERT
语句或分隔文本文件)的信息。This type of backup is suitable for smaller amounts of data where you might edit the data values or table structure, or recreate the data on a different machine architecture.这种类型的备份适用于较小数量的数据,您可以编辑数据值或表结构,或者在不同的计算机体系结构上重新创建数据。
Physical backup methods have these characteristics:物理备份方法具有以下特点:
The backup consists of exact copies of database directories and files. 备份由数据库目录和文件的精确副本组成。Typically this is a copy of all or part of the MySQL data directory.通常,这是MySQL数据目录的全部或部分副本。
Physical backup methods are faster than logical because they involve only file copying without conversion.物理备份方法比逻辑备份方法更快,因为它们只涉及文件复制而不涉及转换。
Output is more compact than for logical backup.输出比逻辑备份更紧凑。
Because backup speed and compactness are important for busy, important databases, the MySQL Enterprise Backup product performs physical backups. 因为备份速度和紧凑性对于繁忙、重要的数据库非常重要,所以MySQL Enterprise backup产品执行物理备份。For an overview of the MySQL Enterprise Backup product, see Section 30.2, “MySQL Enterprise Backup Overview”.有关MySQL企业备份产品的概述,请参阅第30.2节,“MySQL企业备份概述”。
Backup and restore granularity ranges from the level of the entire data directory down to the level of individual files. 备份和恢复粒度范围从整个数据目录的级别到单个文件的级别。This may or may not provide for table-level granularity, depending on storage engine. 这可能提供表级粒度,也可能不提供,具体取决于存储引擎。For example, 例如,InnoDB
tables can each be in a separate file, or share file storage with other InnoDB
tables; each MyISAM
table corresponds uniquely to a set of files.InnoDB
表可以分别位于单独的文件中,或者与其他InnoDB
表共享文件存储;每个MyISAM
表唯一地对应于一组文件。
In addition to databases, the backup can include any related files such as log or configuration files.除了数据库之外,备份还可以包括任何相关文件,如日志或配置文件。
Data from MEMORY
tables is tricky to back up this way because their contents are not stored on disk. MEMORY
表中的数据很难用这种方式备份,因为它们的内容不存储在磁盘上。(The MySQL Enterprise Backup product has a feature where you can retrieve data from (MySQL企业备份产品有一个功能,您可以在备份期间从MEMORY
tables during a backup.)MEMORY
表中检索数据。)
Backups are portable only to other machines that have identical or similar hardware characteristics.备份仅可移植到具有相同或类似硬件特征的其他计算机。
Backups can be performed while the MySQL server is not running. 可以在MySQL服务器未运行时执行备份。If the server is running, it is necessary to perform appropriate locking so that the server does not change database contents during the backup. 如果服务器正在运行,则需要执行适当的锁定,以便服务器在备份期间不会更改数据库内容。MySQL Enterprise Backup does this locking automatically for tables that require it.MySQL Enterprise Backup会自动为需要锁定的表执行此锁定。
Physical backup tools include the mysqlbackup of MySQL Enterprise Backup for 物理备份工具包InnoDB
or any other tables, or file system-level commands (such as cp, scp, tar, rsync) for MyISAM
tables.InnoDB
的括MySQL企业版备份或任何其他表的mysqlbackup,或MyISAM
表的文件系统级命令(如cp、scp、tar、rsync)。
For restore:要恢复,请执行以下操作:
MySQL Enterprise Backup restores MySQL企业版备份可恢复其备份的InnoDB
and other tables that it backed up.InnoDB
和其他表。
ndb_restore restores ndb_restore恢复NDB
tables.NDB
表。
Files copied at the file system level can be copied back to their original locations with file system commands.可以使用文件系统命令将在文件系统级别复制的文件复制回其原始位置。
Logical backup methods have these characteristics:逻辑备份方法具有以下特点:
The backup is done by querying the MySQL server to obtain database structure and content information.备份是通过查询MySQL服务器来获得数据库结构和内容信息的。
Backup is slower than physical methods because the server must access database information and convert it to logical format. 备份比物理方法慢,因为服务器必须访问数据库信息并将其转换为逻辑格式。If the output is written on the client side, the server must also send it to the backup program.如果输出是在客户端写入的,服务器还必须将其发送到备份程序。
Output is larger than for physical backup, particularly when saved in text format.输出大于物理备份,尤其是以文本格式保存时。
Backup and restore granularity is available at the server level (all databases), database level (all tables in a particular database), or table level. 备份和恢复粒度在服务器级别(所有数据库)、数据库级别(特定数据库中的所有表)或表级别可用。This is true regardless of storage engine.无论存储引擎如何,这都是正确的。
The backup does not include log or configuration files, or other database-related files that are not part of databases.备份不包括日志或配置文件,或不属于数据库的其他数据库相关文件。
Backups stored in logical format are machine independent and highly portable.以逻辑格式存储的备份独立于机器,并且具有高度的可移植性。
Logical backups are performed with the MySQL server running. 在MySQL服务器运行时执行逻辑备份。The server is not taken offline.服务器未脱机。
Logical backup tools include the mysqldump program and the 逻辑备份工具包括mysqldump程序和SELECT ... INTO OUTFILE
statement. SELECT ... INTO OUTFILE
语句。These work for any storage engine, even 它们适用于任何存储引擎,甚至MEMORY
.MEMORY
。
To restore logical backups, SQL-format dump files can be processed using the mysql client. 要恢复逻辑备份,可以使用mysql客户端处理SQL格式的转储文件。To load delimited-text files, use the 要加载分隔文本文件,请使用LOAD DATA
statement or the mysqlimport client.LOAD DATA
语句或mysqlimport客户端。
Online backups take place while the MySQL server is running so that the database information can be obtained from the server. 在线备份在MySQL服务器运行时进行,以便从服务器获取数据库信息。Offline backups take place while the server is stopped. 脱机备份在服务器停止时进行。This distinction can also be described as “hot” versus “cold” backups; a “warm” backup is one where the server remains running but locked against modifying data while you access database files externally.这种区别也可以描述为“热”备份与“冷”备份;“热”备份是指当您从外部访问数据库文件时,服务器仍在运行,但无法修改数据的备份。
Online backup methods have these characteristics:在线备份方法具有以下特点:
The backup is less intrusive to other clients, which can connect to the MySQL server during the backup and may be able to access data depending on what operations they need to perform.备份对其他客户端的干扰较小,这些客户端可以在备份期间连接到MySQL服务器,并且可以根据需要执行的操作访问数据。
Care must be taken to impose appropriate locking so that data modifications do not take place that would compromise backup integrity. 必须注意实施适当的锁定,以便不会发生会损害备份完整性的数据修改。The MySQL Enterprise Backup product does such locking automatically.MySQL企业备份产品会自动执行这种锁定。
Offline backup methods have these characteristics:脱机备份方法具有以下特点:
Clients can be affected adversely because the server is unavailable during backup. 客户端可能会受到不利影响,因为服务器在备份期间不可用。For that reason, such backups are often taken from a replica that can be taken offline without harming availability.因此,此类备份通常是从一个副本中进行的,该副本可以脱机进行,而不会影响可用性。
The backup procedure is simpler because there is no possibility of interference from client activity.备份过程更简单,因为不可能受到客户端活动的干扰。
A similar distinction between online and offline applies for recovery operations, and similar characteristics apply. 在线和离线之间的类似区别适用于恢复操作,类似的特征也适用于恢复操作。However, it is more likely for clients to be affected by online recovery than by online backup because recovery requires stronger locking. 但是,与在线备份相比,客户端更可能受到在线恢复的影响,因为恢复需要更强的锁定。During backup, clients might be able to read data while it is being backed up. 在备份期间,客户端可能能够在备份数据时读取数据。Recovery modifies data and does not just read it, so clients must be prevented from accessing data while it is being restored.恢复会修改数据,而不仅仅是读取数据,因此必须防止客户端在恢复数据时访问数据。
A local backup is performed on the same host where the MySQL server runs, whereas a remote backup is done from a different host. 本地备份是在运行MySQL服务器的同一台主机上执行的,而远程备份是在不同的主机上执行的。For some types of backups, the backup can be initiated from a remote host even if the output is written locally on the server. host.对于某些类型的备份,即使输出在服务器上本地写入,也可以从远程主机启动备份。
mysqldump can connect to local or remote servers. 可以连接到本地或远程服务器。For SQL output (对于SQL输出(CREATE
and INSERT
statements), local or remote dumps can be done and generate output on the client. CREATE
和INSERT
语句),可以在客户机上完成本地或远程转储并生成输出。For delimited-text output (with the 对于分隔文本输出(使用--tab
option), data files are created on the server host.--tab
选项),将在服务器主机上创建数据文件。
SELECT ... INTO OUTFILE
can be initiated from a local or remote client host, but the output file is created on the server host.可以从本地或远程客户端主机启动,但输出文件是在服务器主机上创建的。
Physical backup methods typically are initiated locally on the MySQL server host so that the server can be taken offline, although the destination for copied files might be remote.物理备份方法通常在MySQL服务器主机上本地启动,这样服务器就可以脱机,尽管复制文件的目标可能是远程的。
Some file system implementations enable “snapshots” to be taken. 一些文件系统实现允许拍摄“快照”。These provide logical copies of the file system at a given point in time, without requiring a physical copy of the entire file system. 它们在给定的时间点提供文件系统的逻辑副本,而不需要整个文件系统的物理副本。(For example, the implementation may use copy-on-write techniques so that only parts of the file system modified after the snapshot time need be copied.) (例如,该实现可以使用写时复制技术,以便只需要复制快照时间之后修改的文件系统的一部分。)MySQL itself does not provide the capability for taking file system snapshots. MySQL本身不提供获取文件系统快照的功能。It is available through third-party solutions such as Veritas, LVM, or ZFS.它可通过第三方解决方案(如Veritas、LVM或ZFS)获得。
A full backup includes all data managed by a MySQL server at a given point in time. 完整备份包括MySQL服务器在给定时间点管理的所有数据。An incremental backup consists of the changes made to the data during a given time span (from one point in time to another). 增量备份包括在给定的时间跨度内(从一个时间点到另一个时间点)对数据所做的更改。MySQL has different ways to perform full backups, such as those described earlier in this section. MySQL有不同的方法来执行完整备份,如本节前面所述。Incremental backups are made possible by enabling the server's binary log, which the server uses to record data changes.通过启用服务器用于记录数据更改的二进制日志,可以实现增量备份。
A full recovery restores all data from a full backup. 完全恢复从完全备份中恢复所有数据。This restores the server instance to the state that it had when the backup was made. 这会将服务器实例恢复到备份时的状态。If that state is not sufficiently current, a full recovery can be followed by recovery of incremental backups made since the full backup, to bring the server to a more up-to-date state.如果该状态不是最新状态,则完全恢复之后可以恢复自完全备份以来进行的增量备份,以使服务器处于更为最新的状态。
Incremental recovery is recovery of changes made during a given time span. 增量恢复是指恢复在给定时间范围内所做的更改。This is also called point-in-time recovery because it makes a server's state current up to a given time. 这也称为时间点恢复,因为它使服务器的状态在给定时间内保持为当前状态。Point-in-time recovery is based on the binary log and typically follows a full recovery from the backup files that restores the server to its state when the backup was made. 时间点恢复基于二进制日志,通常在从备份文件进行完全恢复之后进行,该文件将服务器恢复到备份时的状态。Then the data changes written in the binary log files are applied as incremental recovery to redo data modifications and bring the server up to the desired point in time.然后,二进制日志文件中写入的数据更改将作为增量恢复应用,以重做数据修改,并使服务器达到所需的时间点。
Data integrity can be compromised if tables become corrupt. 如果表损坏,数据完整性可能会受到损害。For 对于InnoDB
tables, this is not a typical issue. InnoDB
表,这不是一个典型的问题。For programs to check 有关检查MyISAM
tables and repair them if problems are found, see Section 7.6, “MyISAM Table Maintenance and Crash Recovery”.MyISAM
表并在发现问题时进行修复的程序,请参阅第7.6节,“MyISAM
表维护和故障恢复”。
Backup scheduling is valuable for automating backup procedures. 备份计划对于自动化备份过程很有价值。Compression of backup output reduces space requirements, and encryption of the output provides better security against unauthorized access of backed-up data. 备份输出的压缩减少了空间需求,输出的加密提供了更好的安全性,可防止未经授权访问备份数据。MySQL itself does not provide these capabilities. MySQL本身不提供这些功能。The MySQL Enterprise Backup product can compress MySQL Enterprise Backup产品可以压缩InnoDB
backups, and compression or encryption of backup output can be achieved using file system utilities. InnoDB
备份,并且可以使用文件系统实用程序实现备份输出的压缩或加密。Other third-party solutions may be available.可能有其他第三方解决方案。