|
Last blog posts
Login |
Viewing blog post - My-Ess-Que-EllReturn to blogFree hot backups for MySQL on Linux
"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.
|