Reverting LVM snapshots

| 2 Comments
Yesterday I learned that LVM gained the ability to revert snapshots when the 2.6.33 kernel released. While nifty, I hadn't been under the impression that this functionality was lacking. Why that's so is interesting in and of itself.

My first exposure to a copy-on-write filesystem that allowed snapshots was Novell's NSS filesystem. We never used it in production but I did play around with it a fair amount, and it was useful in the terminal stages of migrating off of NetWare. It was very nifty. And also lacked the ability to revert.

Then I started using VMWare Workstation a lot. It has a snapshot ability built into it. It even does a kind of copy-on-write in the form of the differencing disks it uses to support snapshots. Snapshots are golden in that it allows you to undo things to VMs. Repeatedly installing something that can only install once? A snapshot right before you do the install will allow you to back out of it and retry. And a whole bunch of other very nifty usage scenarios. Of COURSE a snapshot facility should have a revert.

Of course, reverting an entire filesystem means that all data changed since the last snapshot is now gone. That's kind of the point. But it does beg the question, what kind of use-cases exist where such a thing is actually desired?
  • If you have a VM product that doesn't do snapshots inside of it (some Xen versions), this is a way to fake it.
  • If you need to take an 'instant backup' before a large application install, this allows a way to return to a known config without having to tar/restore an entire filesystem. Potentially very good time savings.
  • If you have a Time Machine backup going to a dedicated partition and the Time Machine archive keeps getting mysteriously deleted every month or two, this is a way to get the old archive back without having to do a full backup, and it keeps the backup history.
And others, I'm sure. What's the command to revert a snapshot? It's hiding in lvconvert:

lvconvert --merge volumeGroup/TMArchive_snap

Very simple. You'll also need a newer LVM Tools package in order to get the functionality in lvconvert.

2 Comments

My big gripe with LVM snapshots is that you can't roll the deltas back into the "main" volume. If you're creating a snapshot before that big change, you can revert back by remounting the volumes. On the other hand if you don't back out of the change, you can't merge the snapshot delta with the original partition it's based from. This requires that you leave the snap in place indefinitely, or create a new LV and migrate the data over to it, in order to move forward.

Anyone happen to know a better way to accomplish this? If so, I'd love to hear it.

One of the awesomeness of rolling back LVM's snapshot is going to be patching OS and being able to quickly roll back in case of issues -- I think Redhat was going to integrate this into yum :-) .

You know, you don't always have a hardware RAID you can use for roll back (pulling one disk) or being in a virtual env where you can just revert to the latest VM snapshot.