Friday, April 16, 2010

How to create a snapshot of a Logical Volume in linux rhel5 / Centos

Sponsored Links

Creating SNAPSHOT (Backup):

We can take the back up of any particular Logical Volumes. Snapshot will be stored in the Same volume group. Snapshot will take only 3-5% of the original size of Logical Volume.
This is the current status of our machine:

[root@vm4 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvm1 linux -wi-a- 200.00M
lvm2 linux -wi-a- 40.00M
[root@vm4 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
linux 2 2 0 wz--n- 576.00M 336.00M
redhat 2 0 0 wz--n- 576.00M 576.00M
[root@vm4 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 lvm2 -- 290.21M 290.21M
/dev/sda6 linux lvm2 a- 288.00M 248.00M
/dev/sda7 linux lvm2 a- 288.00M 88.00M
/dev/sda8 redhat lvm2 a- 288.00M 288.00M
/dev/sda9 redhat lvm2 a- 288.00M 288.00M

We have two Logical Volumes lvm1 and lvm2 mounted on /linux1 and /linux2 respectively.
We'll take the SNAPSHOT of the LV lvm1 which is mounted on /linux1
currently there are following files in /linux1 [ie in lvm1]

[root@vm4 ~]# cd /linux1
[root@vm4 linux1]# ls

a b c lost+found

Step1:
Snapshot is actually a Logical Volume only. It will be saved in the same VG. We can create lvm snapshot using command #lvcreate with options for snapshot.

The syntax is as follows

#lvcreate --size SIZE --snapshot --name Name_Of_Snapshot Path_of_the_LV

[root@vm4 linux1]# lvcreate --size 10M --snapshot --name snap /dev/linux/lvm1
Rounding up size to full physical extent 12.00 MB
Logical volume "snap" created

[root@vm4 linux1]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvm1 linux owi-ao 200.00M
lvm2 linux -wi-ao 40.00M
snap linux swi-a- 12.00M lvm1 0.10

[root@vm4 linux1]# vgs
VG #PV #LV #SN Attr VSize VFree
linux 2 3 1 wz--n- 576.00M 324.00M
redhat 2 0 0 wz--n- 576.00M 576.00M




Now lets mount the Snapshpot and check whether it has everything from lvm1.
Mounting snap to /snapshot

[root@vm4 linux1]# mkdir /snapshot
[root@vm4 linux1]# mount /dev/linux/snap /snapshot
[root@vm4 linux1]# cd /snapshot
[root@vm4 snapshot]# ls
a b c lost+found
It has the same and all the contents of lvm1
Sponsored Links

No comments:

Post a Comment

Be nice. That's all.