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.
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.