Tuesday, August 4, 2009

MySQL Backups using LVM snapshots

lvcreate -L40G -s -n dbbackup /dev/VolGroup00/LogVol03


lvm> lvremove /dev/VolGroup00/dbbackup
Do you really want to remove active logical volume "dbbackup"? [y/n]:

----------------------------------------------------------------------------

Stapes to Install and configure LVM.
fdisk -l
fdisk /dev/hdb
:p to print partition
:n to Extend partition

:e
Last cylender _______ enter

:n to new partition

Last cylender : +10G

Again create +10G partition
:n
choose: e
Last cylender :+10G

Command:l for list.

---------------------------
Command: t
partition number : 5
hexadecimal number: 8e

again create:
command: t
partition number: 6
hexadecimal number: 8e
command: w to save.
-------------------------
# partprobe

take hdb drive and make two partition if you want 1 is ok.

pvcreate /dev/hdb1 /dev/hdb2
vgcreate test1 /dev/hdb1

mkdir /mnt/Backup_disk/snap0 or
mkdir /snap0

lvcreate -L1000M -s -n /mnt/Backup_disk/snap0 /dev/test1/data

mount /dev/test1/data /mnt/Backup_disk/snap0
or
mount /dev/test1/snap0 /snap0 dependupmon path you can mount any where in disk just


mysql -uroot -p passwd > FLUSH TABLES WITH READ LOCK

create TAR
tar -cvf /mnt/Backup_disk/snap0/mysql`date +%Y%m%d%H`.tar /var/lib/mysql/

login to you mysql
and
mysql > UNLOCK TABLES;

cd /snap0
ls mysql2009080419.tar

tar -xvf mysql2009080419.tar

this is your hot backup.

Now you can umount LVM
root@localhost ~]# umount /mnt/Backup_disk/snap0


Check with command: lvdisplay

--- Logical volume ---
LV Name /dev/test1/snap0
VG Name test1
LV UUID ZCYdo5-RinV-EJ4L-03Tq-Snk1-i1Qt-pkQG1X
LV Write Access read/write
LV snapshot status active destination for /dev/test1/data
LV Status available
# open 0
LV Size 1.00 GB
Current LE 256
COW-table size 1000.00 MB
COW-table LE 250
Allocated to snapshot 0.01%
Snapshot chunk size 8.00 KB
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:3


[root@localhost ~]# lvremove /dev/test1/snap0
Do you really want to remove active logical volume "snap0"? [y/n]: y
Logical volume "snap0" successfully removed

Whenerver you want just crete LVM useing this command:

lvcreate -L1000M -s -n /mnt/Backup_disk/snap0 /dev/test1/data

and mount same process.

0 comments: