>LVM Snapshots

By | February 16, 2011

>

First of all some of important facts about LVM Snapshots
  • A snapshot volume does not have to be as large as the source volume
  • LVM snapshots use a copy on write (CoW) technology
  • The snapshot volume only needs to be large enough to accommodate the maximum number of changes that might occur to the source volume during the life of the snapshot.
  •  Snapshot is really just a copy of the inode tree at the point in time you created it
Let us understand this with an example. 

Suppose you have a 20GB Logical Volume where you storing your data. Now suppose in normal circumstance approx 500MB of data get some changes daily. In this case you need to create 500MB  LVM snapshot for your 20GB LVM.  The modified data of LVM stored  on snapshot instead of LVM. So when it is time to read from the snapshot , any changed blocks are read from the snapshot area. But any blocks that haven’t changed since the snapshot are read from the original. 


LVM snapshots can be used for taking data backup of  live system. You can keep snapshot for a given period of time after that you can take backup of snapshot for its further uses. It you need to recover data from snapshot you need to mount it separately and get data from it. 

Command to create snapshot:

 root# lvcreate -L 500M -s -n databackup /dev/vg1/lv1

Here databackup is name of snapshot and its size will be 500MB. This is snapshot of Logical Volume lv1. 

To recover data from snapshot, you need to mount it as following and then perform recovery

root# mount -t ext3 /dev/vg1/databackup /mnt

To take backup of LVM snapshot for further references, you may use following command

root#tar -cf /mybackup/lv1backup /mnt

  After taking it is advisable to remove snapshot, for that you can use following command

root#umount /mnt

root#lvremove /dev/vg1/databackup


Share itShare on FacebookEmail this to someoneTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

8 thoughts on “>LVM Snapshots

  1. Anonymous

    >Good article, but I need more info. I'm new to this. The name "databackup" is that a directory or the name of another LVM? When I try it I get the following errors:
    lvcreate -L 500M -s -n databackup /dev/VolGroup01/LogVol01
    Insufficient free extents (0) in volume group VolGroup01: 125 required

    /dev/VolGroup01/LogVol01 is the volume I'm trying to get a snapshot of. I have another volume with 225GB of free space that I'd like to put the snapshot on. Can you explain your steps for newbies like me.

    Reply
  2. vishesh

    >Thanks for comment,
    in example databack is another LVM, the error says that in VolumeGroup there is no free space to create lvm(databackup) of size 500M, execute vgdisplay to check how much space is free in volume group

    Reply
  3. Anonymous

    >It would be nice if you can give the procedure for recovering the data from the snapshot as well

    Reply
  4. Anonymous

    >Hi Great article, thanks!

    I am new to this stuff…
    Can the lvm snapshot and backup procedure be automated?
    For example, If i want to take a backup of a database every one hour, how to proceed with that?
    Do i need to create a new snapshot after every backup or what?

    Reply
  5. Atom

    >yes, this LVM snapshot can be used by accumulating all the steps mentioned above in script. And that script can be run using crontab as per requirement i.e. 1 hour.

    I think so, if any changes took place since the last backup snapshot ran, it will create new snapshot every hour.

    Reply
  6. Gajender Kumar

    >yes, this LVM snapshot can be used by accumulating all the steps mentioned above in script. And that script can be run using crontab as per requirement i.e. 1 hour.

    I think so, if any changes took place since the last backup snapshot ran, it will create new snapshot every hour.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Current month ye@r day *