MySQL Snapshots in Linux using LVM

Table of Contents

Intro

Say that you are working with some data that is constantly changing, like some MySQL databases, and you are charged to take a valid backup without any data inconsistency or downtime. You may consider using mysqldump; however, this utility will lock tables during the duration of the backup and can cause down time (especially if using MyISAM table engine which performs Table level locking). Then, you think you may just copy or archive the MySQL table files (/var/lib/mysql/DB), however, this can cause data inconsistent as during the copy some of the data may of changed. Not to mention, if it is InnoDB table engine all table data is stored in the ibdata files.

At this point you may be scratching your head not knowing what to do. You could stand up another server and setup MySQL replication. Unfortunately, you do not have any available server's or workstation to setup for this purpose. Fortunately, for you, this server will setup by default with LVM (Logical Volume Management) by your distribution. Using LVM, we are able to create a snapshot of an existing Logical Volume using free space on the Volume Group. Lets go ahead and see some of the syntax and examples below.

Setup

Author: Jeffrey Ness <jness@flip-edesign.com>

Date: 2010-03-22 10:11:27 CDT

HTML generated by org-mode 6.21b in emacs 23