This is TikiWiki v1.9.7 -Sirius- © 2002–2005 by the Tiki community. Tue 09 of Feb, 2010 [09:08 UTC]
  add
Menu [hide]

Viewing blog post - My-Ess-Que-Ell

Return to blog

Free hot backups for MySQL on Linux

posted by TaneliOtala on Wed 03 of May, 2006 [23:41 UTC]
"Hot Backups" of your MySQL Database on Linux

Would you like to take consistent snapshot backups of your entire database without a SAN or external software, and without slowing or locking your database for the duration?

RedHat? Enterprise Linux (and Centos Linux) install an LVM by default.
LVM, Logical Volume Manager is a layer that sits on top of any file system (default ext3).

You can tell if you're already running on an LVM, by checking your file system with "df -h" — an entry like "/dev/mapper/VolGroup01-LogVol00" shows that your disk is mapped through the LVM.

LVM brings you features such as the ability to grow and shrink volumes, add hard disks without migrating data, RAID0, and for the purpose of this article: file system SNAPSHOTS.

FLUSH TABLES WITH READ LOCK;
\! lvcreate --size 100m --snapshot --name snap /dev/VolGroup01/LogVol00
UNLOCK TABLES;


Will lock and flush all tables in the current database to disk.
As soon as lock and flush is acquired, a snapshot called "snap" is created (instantaneously), and table locks are released.

You can use lvdisplay(8) to look at active volumes.
Remember, that you must have dm-snapshot.ko module loaded (modprobe dm-snapshot)

Next mount the new snapshot volume, backup it up, and release the snapshot
mkdir /snap
mount /dev/VolGroup01/snap /snap
# This is where you back up whatever you need from /snap, I prefer using rsync(1)
umount /snap
lvremove /dev/VolGroup01/snap
rmdir /snap


While you back up the snapshot, your database is running its normal business, slowing down only as much as you read from the file system, i.e. the disk access is the only slowing factor — meaning that you can back up at file system speed!

Snapshotting is also a handy undo feature, when doing schema changes (ALTER TABLE), or other database maintenance work, such as upgrades.


Permalink (referenced by: 0 posts references: 0 posts) print email this post

Posted messages

Hide all
author message
bt
is retroactively implementing snapshots possible?
on: Sat 28 of Oct, 2006 [21:05 UTC] score: 0.00
even if the machine is already using lvm you may not be able to take advantage of snapshots. for more info, see my comment on mike kruckenberg's post about using lvm for backups
http://mike.kruckenberg.com/archives/2006/05/mysql_backups_u.html