Create mysql backup using mylvmbackup on CentOS RHEL Debian Ubuntu

Overview

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 prefix backup, 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.

Create mysql backup using mylvmbackup on CentOS RHEL Debian Ubuntu

Install the prerequisites

On Debian Ubuntu

On CentOS/RHEL

First enable rpmforge repo by clicking here

Install the prerequisites

Download the latest version of mylvmbackup, untar it and run make

Now mylvmbackup assumes that your mysql data dir is on a lvm, since its essentially a perl script taking lvm snapshot of the directory. Also make sure sure you have enough space available on the volume group for mylvmbackup to use during the snapshot. Sample from my machine in the screenshot below.

To run backup execute mylvmbackup as shown below. Replace the password, path of my.cnf, vgname, lvname, backuptype and backupdir according to your environment.

You can now access your backup under /opt directory as shown in the screenshot.

mylvmbackup01 300x176 Create mysql backup using mylvmbackup on CentOS RHEL Debian Ubuntu

To check all available options