Course contentsShow
← Linux
Lesson 670 of 1,8197. Storage Management and Logical VolumesFree lesson

Snapshot merging and restoration

Revert logical volumes to previous states using differential snapshot snapshots.

Reverting to the Past: Snapshot Merging and Restoration

In this lesson, you will learn how to use LVM snapshots to revert an entire logical volume back to a previously saved state, effectively "undoing" changes made to your data.

The Mechanism of Merging

When you create an LVM snapshot, you are essentially creating a "copy-on-write" record of your logical volume. As you continue to work on the original volume, any data you change is preserved in the snapshot. If you realize that your recent changes were a mistake—or if a software update corrupted your files—you can initiate a snapshot merge.

Merging is a powerful operation that instructs the LVM subsystem to take the original data stored within the snapshot and write it back onto the primary logical volume, effectively overwriting current data with the version that existed at the moment the snapshot was created.

How to Perform a Merge

Before merging, you must ensure the logical volume is unmounted to prevent filesystem corruption. Once unmounted, you use the lvconvert command.

Suppose you have a logical volume named data_vol and a snapshot named data_snap. You can revert data_vol to the state of data_snap by running:

# Unmount the volume first for safety
umount /mnt/data

# Merge the snapshot back into the origin
lvconvert --merge /dev/vg0/data_snap

Once the command is executed, LVM begins the process of synchronizing the data. If the system is still running, the merge will finish automatically as soon as the volume is reactivated (usually upon the next mount).

Why Use Merging?

Merging is an "all-or-nothing" recovery tool. Unlike manually copying individual files, a merge restores the entire block-level state of the volume. Because this is a destructive operation—meaning your current, post-snapshot data is replaced by the old data—it should be used carefully. However, it is an incredibly efficient way to recover from system-wide configuration errors or accidental deletions across an entire partition.

Key Takeaway: Snapshot merging allows you to atomically restore a logical volume to a previous state by copying block-level data from a snapshot back onto the original volume, effectively rolling back all changes made since the snapshot was taken.