LVM Snapshots

What’s purpose of LVM snapshot?

Purpose of LVM snapshots is quite simple. We want “point in time” copy of our LV, and snapshot helps us with that, by writing only differences on the snapshot.

Why would I do that?

It’s ideal for backing up virtual machines or other servers during their operation, since snapshot takes very small amount of time to create itself.

Considerations:
  • Thing to consider is I/O troughput on the device needed for such snapshot. If we have a lot of I/O on this LV, we will double this I/O, since server now has to write to original volume and snapshot at the same time.
  • The other thing to consider is space needed for snapshot. We can set size for snapshot and therefore size of all the changes written on the disk. We should always set snapshot’s size large enough so we won’t bump the limit during backup procedure, otherwise snapshot will be corrupted. It is up to us to decide what size we should set. You must know that snapshot can only reach the size of it’s original LV and no larger. That would happen in worst case scenario, when every file on original LV would change.

As far as I know, you can also write on the snapshot itself. This is especially useful if you want to test an upgrade of certain service/server. Make snapshot, start new VM from the snapshot, upgrade it and see if upgrade went well, then repeat procedure on the original VM.

How to do it?

To make snapshot of LV is faily simple:

lvcreate -L10G -s -n root_snap /dev/VG_RAID10/root

This would create /dev/VG_RAID10/root_snap snapshot LV, which we can simply copy with dd to make backup. Be careful, since size of snaphot may mislead. You will see size of snapshot 10G but when doing backup, your backup will be size of root LV.

Once you finish backing up, or other way manipulating snapshot (you can mount this snapshot and make modifications if you want), you should remove the snapshot.

lvremove /dev/VG_RAID10/root_snap
 

Leave a Reply

help-hint.png
Purpose of the commenting system is to share your experience. I encourage you to post feedback with your own suggestions, ideas or optimizations regarding the topic of a blog post. What commenting system isn't for, is asking questions about similar issues of yours and requesting support for it. Blog post is provided as is and I am not here to solve all your problems. Please bear that in mind and try to avoid posting such comments. I do take privilege to remove comment from my blog for any reason whatsoever. Usually I do it when I sense a comment was posted only for spam/seo reasons or is out of blog post's topic. Thank you for reading this, now you may continue :)
 

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