The default installation of RedHat Enterprise Linux and CentOS 5 will create all mount points (including the root mount point, /
) on Logical Volume Manager's (LVM) Logical Volumes (LVs).
LVM brings about many benefits. With particular relevance for MySQL high availability is the snapshot feature. This allows you to take a consistent snapshot of a logical volume (for example, the logical volume with the ext3
filesystem mounted on /var/lib/mysql
) without affecting the currently mounted volume.
LVM then allows for this snapshot to be mounted somewhere else (/mnt/mysql-3pmtoday
) and a backup can then be run against this snapshot without affecting the MySQL instance running on the original logical volume.
The actual process of creating a snapshot takes a very short period of time, normally fractions of a second. Therefore, to take a fully-consistent backup of your MySQL database, you only need to flush all the transactions and caches to disk for that short period of time and then the database can continue as normal.
This is useful for the following reasons:
The time during which your main database is down will be significantly reduced
It is possible to get consistent backups of multiple database servers at the same time easily
While it is possible to carry out this backup process manually, there is a Perl script mylvmbackup
available at http://lenzg.net/mylvmbackup/, which carries this out automatically. mylvmbackup
was created by Aleksey "Walrus" Kishkin and was released under the GNU Public License.
The definition for mylvmbackup
from the website at http://lenzg.net/mylvmbackup/ states:
mylvmbackup is a tool for quickly creating backups of a MySQL server's data files. To perform a backup, mylvmbackup obtains a read lock on all tables and flushes all server caches to disk, creates a snapshot of the volume containing the MySQL data directory, and unlocks the tables again. The snapshot process takes only a small amount of time. When it is done, the server can continue normal operations, while the actual file backup proceeds.
The LVM snapshot is mounted to a temporary directory and all data is backed up using the tar program. By default, the archive file is created using a name of the form
backup-YYYYMMDD_hhmmss_mysql.tar.gz
, where YYYY, MM, DD, hh, mm, and ss represent the year, month, day, hour, minute, and second of the time at which the backup occurred. The default prefixbackup
, date format and file suffix can be modified. The use of timestamped archive names allows you to run mylvmbackup many times without danger of overwriting old archives.