{"id":2962,"date":"2014-03-29T09:17:24","date_gmt":"2014-03-29T01:17:24","guid":{"rendered":"http:\/\/rmohan.com\/?p=2962"},"modified":"2014-03-29T09:17:24","modified_gmt":"2014-03-29T01:17:24","slug":"logical-volume-snapshots","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2962","title":{"rendered":"Logical Volume Snapshots"},"content":{"rendered":"<div><b>Environment:\u00a0<\/b>CentOS release 6.3 (32-bit).<\/div>\n<div><\/div>\n<div><b>Descriptions:<\/b><\/div>\n<div>By LV snapshot you will be able to freeze your logical volumes. In other words, you can easily backup and rollback to a original logical volume state. This is almost similar to VMware where you can the snap shot of the VM and revert\u00a0in-case\u00a0if anything goes wrong.<\/div>\n<div><\/div>\n<div>\n<div>Concept of snapshot are just like the symbolic links, where you don&#8217;t create a file, instead you only reference to it. Here, two essential parts are<\/div>\n<div>1. Metadata.<\/div>\n<div>2. Data blocks.<\/div>\n<div><\/div>\n<div>When a snapshot is created Logical Volume Manager simply creates a copy of all Metadata pointers to a separate logical volume, snapshot volume only starts grow once you start altering data of the original logical volume.<\/div>\n<div><\/div>\n<div><b>Implementation:<\/b><\/div>\n<div>Since my server was not created using LVM, I have created two partitions and changed them to LVM.<\/div>\n<div><\/div>\n<div><b>Change plan:<\/b><\/div>\n<div>1. Create two partitions on \/dev\/sda drive.<\/div>\n<div>2. Create physical volumes on the two drives.<\/div>\n<div>3. Create volume group.<\/div>\n<div>4. Create a single logical volume using ext3 file system.<\/div>\n<div>5. Take snapshot and remove data<\/div>\n<div>6. Rollback logical volume snapshot<\/div>\n<div><\/div>\n<div><b>Technical Implementation:<\/b><\/div>\n<div><b>\u00a0<\/b><\/div>\n<div>1. Created two physical partitions:<\/div>\n<div><\/div>\n<div>\n<div>tux#fdisk -l | tail -2<\/div>\n<div>\/dev\/sda5 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a02305 \u00a0 \u00a0 \u00a0 \u00a02366 \u00a0 \u00a0 \u00a0497983+ \u00a08e \u00a0Linux LVM<\/div>\n<div>\/dev\/sda6 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a02367 \u00a0 \u00a0 \u00a0 \u00a02428 \u00a0 \u00a0 \u00a0497983+ \u00a08e \u00a0Linux LVM<\/div>\n<div>tux#<\/div>\n<div><\/div>\n<div>2. Created Physical Volumes:<\/div>\n<div><\/div>\n<div>\n<div>tux#pvcreate \/dev\/sda[5-6]<\/div>\n<div>\u00a0 Physical volume &#8220;\/dev\/sda5&#8221; successfully created<\/div>\n<div>\u00a0 Physical volume &#8220;\/dev\/sda6&#8221; successfully created<\/div>\n<div>tux#<\/div>\n<div><\/div>\n<div>3.\u00a0Created volume groups:<\/div>\n<div>\n<div>tux#vgcreate vol_grp \/dev\/sda5 \/dev\/sda6<\/div>\n<div>\u00a0 \/dev\/hdc: open failed: No medium found<\/div>\n<div>\u00a0 Volume group &#8220;vol_grp&#8221; successfully created<\/div>\n<div>tux#<\/div>\n<div><\/div>\n<div>4. Created single logical volume of 100Mb with ext3 file system.<\/div>\n<div><\/div>\n<div>\n<div>tux#lvcreate -L 100M -n lv1 vol_grp<\/div>\n<div>\u00a0 Logical volume &#8220;lv1&#8221; created<\/div>\n<div>tux#<\/div>\n<div><\/div>\n<div>tux#mkfs.ext3 \/dev\/vol_grp\/lv1<\/div>\n<div>\n<div>mke2fs 1.39 (29-May-2006)<\/div>\n<div>.<\/div>\n<div>.<\/div>\n<div>tux#<\/div>\n<div><\/div>\n<div>Finally, we have come to the point where we can take a snapshot of our logical volume, for this we will also need some sample data on our Logical Volume, so once we revert from the snapshot we can confirm entire process by comparing original data with data recovered from the snapshot.<\/div>\n<div><\/div>\n<div>\n<div>Create a mount directory for the logical volume and mount it.<\/div>\n<div><\/div>\n<div>tux#mkdir \/mnt\/lv1<\/div>\n<div>tux#mount \/dev\/vol_grp\/lv1 \/mnt\/lv1<\/div>\n<div>tux#<\/div>\n<div><\/div>\n<div>tux:\/mnt\/lv1#cp -r \/sbin\/ .<\/div>\n<div>tux:\/mnt\/lv1#cp -r \/bin\/ .<\/div>\n<div>tux:\/mnt\/lv1#du -s .<\/div>\n<div>39312 \u00a0 .<\/div>\n<div>tux:\/mnt\/lv1#<\/div>\n<div><\/div>\n<div>5. Creating the LV snapshot.<\/div>\n<div><\/div>\n<div>\n<div>tux:\/mnt\/lv1]#lvcreate -s -L 30M -n lv1_snapshot \/dev\/vol_grp\/lv1<\/div>\n<div>\u00a0 Rounding up size to full physical extent 32.00 MB<\/div>\n<div>\u00a0 Logical volume &#8220;lv1_snapshot&#8221; created<\/div>\n<div>tux:\/mnt\/lv1]#<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div><\/div>\n<div>Execute<b>\u00a0lvs<\/b>\u00a0to confirm that new volume snapshot has been created.<\/div>\n<div><\/div>\n<div>\n<div>tux:\/mnt\/lv1]#lvs<\/div>\n<div>\u00a0 LV \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 VG \u00a0 \u00a0 \u00a0Attr \u00a0 LSize \u00a0 Origin Snap% \u00a0Move Log Copy%<\/div>\n<div>\u00a0 lv1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0vol_grp owi-ao 100.00M<\/div>\n<div>\u00a0 lv1_snapshot vol_grp swi-a- \u00a032.00M lv1 \u00a0 \u00a0 \u00a00.07<\/div>\n<div>tux:\/mnt\/lv1]#<\/div>\n<div><\/div>\n<div>\n<div>Since the snapshot was already created, now you can alter the data on the volume group.<\/div>\n<div><\/div>\n<div>tux:\/mnt\/lv1]#rm -rf .\/bin\/<\/div>\n<div>tux:\/mnt\/lv1]#rm -rf .\/sbin\/<\/div>\n<div>tux:\/mnt\/lv1]#du -s .<\/div>\n<div>13 \u00a0 \u00a0 \u00a0.<\/div>\n<div>tux:\/mnt\/lv1]#<\/div>\n<div><\/div>\n<div>6. Rollback logical volume snapshot.<\/div>\n<div><\/div>\n<div>\n<div>tux:\/mnt\/lv1]# lvconvert &#8211;merge \/dev\/vol_grp\/lv1_snapshot<\/div>\n<div>\u00a0 Can&#8217;t merge over open origin volume<\/div>\n<div>\u00a0 Merging of snapshot lv1_snapshot will start next activation.<\/div>\n<div>tux:\/mnt\/lv1]#<\/div>\n<div><\/div>\n<div>tux#umount \/mnt\/lv1<\/div>\n<div><\/div>\n<div>Deactivate and activate you volume:<\/div>\n<div><\/div>\n<div>\n<div>tux# lvchange -a n \/dev\/vol_grp\/lv1<\/div>\n<div>tux# lvchange -a y \/dev\/vol_grp\/lv1<\/div>\n<div><\/div>\n<div>\n<div>As a last step mount again your logical volume &#8220;lv1&#8221; and confirm that data all has been recovered:<\/div>\n<div><\/div>\n<div>tux# mount \/dev\/vol_grp\/lv1 \/mnt\/lv1<\/div>\n<div>tux:\/mnt\/lv1]# ls<\/div>\n<div>\n<div>bin \u00a0lost+found \u00a0sbin<\/div>\n<div>tux:\/mnt\/lv1]#<\/div>\n<\/div>\n<div>\n<div>tux# du -s \/mnt\/lv1\/<\/div>\n<div>39312 \u00a0 .<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Environment: CentOS release 6.3 (32-bit). Descriptions: By LV snapshot you will be able to freeze your logical volumes. In other words, you can easily backup and rollback to a original logical volume state. This is almost similar to VMware where you can the snap shot of the VM and revert in-case if anything goes wrong. [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2962"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2962"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2962\/revisions"}],"predecessor-version":[{"id":2963,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2962\/revisions\/2963"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}