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.
Alternatively, instead of tar, you may use rsync. This process is nearly identical, with the exception that the file suffix is not used. rsync backup is primarily developed for performing local backups. The rsync backup can perform both local backups as well as backing up to a remote server using rsyncd or rsync via SSH.
mylvmbackup also supports creating backups by using rsnap, which is a wrapper around rsync to automatically maintain and rotate a given number of last backups (7 by default). It utilizes hard links to link to unchanged files for saving disk space.
Additionally, a backup type "none" is provided for cases where the user wants to use mylvmbackup only for creating the snapshots and intends to perform the actual backup by using the appropriate hooks. (Or for cases where the snapshot itself is considered to be the backup).
It is required to run mylvmbackup on the same host where the MySQL server runs. If your MySQL daemon is not listening on localhost or using the default socket location, you must specify --host or --socket. Even though mylvmbackup communicates with the server through a normal client connection to obtain the read lock and flush data, it performs the actual backup by accessing the file system directly. It is also a requirement that the MySQL server data directory resides on an LVM volume. (It is, however, a good idea to do the LVM backup to a different partition than the one where the data directory resides. Otherwise, there is a good chance that LVM will run out of undo space for LVM snapshot maintenance and the backup will fail.)
The user who invokes mylvmbackup must have sufficient filesystem permissions to create the LVM snapshot and mount it. This includes read/write access to the backup directory.
For proper operation mylvmbackup requires Perl 5 with the DBI and DBD::mysql modules. It also needs the Config::IniFiles to read the global configuration file of the program and Sys::Syslog in case you want to enable the syslog log facility. Date::Format (part of the TimeDate package) is required to create the time stamp used in the backup file names. In addition, it utilizes Getopt::Long, File::Basename and File::Temp which usually are part of the default Perl 5 distribution.
It also requires several other external programs: GNU tar and gzip to back up and compress the data, LVM utilities (lvcreate, lvremove and lvs) to create and remove the LVM snapshot, and the system utilities mount and umount. rsync may be used in place of tar and gzip.
Optionally, rsync or rsnap may be required instead of tar and gzip, depending on which backup type you choose.
If you want to discuss the usage of mylvmbackup, propose patches or ask for help, there is a mailinglist hosted on Launchpad. You can subscribe and view the mailing list archive via the mylvmbackup Discussion page.
In previous times, we used a mailing list on freelists.org. The old discussions are archived here.
If you want to report a bug, please use the bug tracker on Launchpad.net.
In addition to the packages listed below, I also provide RPM packagages for a number of additional Linux distributions via my home:LenzGr repository on the fabolous openSUSE Build Service.
A package for Debian/Ubuntu Linux is kindly provided and maintained by Norbert Tretkowski. It is now available for Debian "Sid" (Unstable), but the package works fine on stable (Etch) as well.
Robin H. Johnson maintains an ebuild of mylvmbackup for Gentoo Linux.
The latest version of the package can always be obtained by downloading the file mylvmbackup-current.tar.gz.
On June 25th 2008, the source tree has been moved from Subversion to Bazaar.
The main development branch is now hosted on LaunchPad.net. From there you can browse the bzr tree or create your own branch by using the following command:
bzr branch lp:mylvmbackup
Note: The old Subversion repository has been removed, to avoid confusion. However, the history of changes has been preserved in the bzr repository.
The following links provide additional background information about LVM on Linux and how to utilize it for performing snapshot backups, particularly with MySQL: