Snapshots can be useful if you need to roll back or restore data on a volume to a previous state. For example, you might need to revert data changes that resulted from an administrator error or a failed or undesirable package installation or upgrade.
You can use the lvconvert --merge command to revert the changes made to an LVM logical volume. The merging begins as follows:
If both the source logical volume and snapshot volume are not open, the merge begins immediately.
If the source logical volume or snapshot volume are open, the merge starts the first time either the source logical volume or snapshot volume are activated and both are closed.
If the source logical volume cannot be closed, such as the root file system, the merge is deferred until the next time the server reboots and the source logical volume is activated.
If the source logical volume contains a virtual machine image, you must shut down the virtual machine, deactivate the source logical volume and snapshot volume (by dismounting them in that order), and then issue the merge command. Because the source logical volume is automatically remounted and the snapshot volume is deleted when the merge is complete, you should not restart the virtual machine until after the merge is complete. After the merge is complete, you use the resulting logical volume for the virtual machine.
After a merge begins, the merge continues automatically after server restarts until it is complete. A new snapshot cannot be created for the source logical volume while a merge is in progress.
While the merge is in progress, reads or writes to the source logical volume are transparently redirected to the snapshot that is being merged. This allows users to immediately view and access the data as it was when the snapshot was created. They do not need to wait for the merge to complete.
When the merge is complete, the source logical volume contains the same data as it did when the snapshot was taken, plus any data changes made after the merge began. The resulting logical volume has the source logical volume’s name, minor number, and UUID. The source logical volume is automatically remounted, and the snapshot volume is removed.
Open a terminal console, log in as the root user, then enter
lvconvert --merge [-b] [-i <seconds>] [<snap_volume_path>[...<snapN>]|@<volume_tag>]
You can specify one or multiple snapshots on the command line. You can alternatively tag multiple source logical volumes with the same volume tag then specify @<volume_tag> on the command line. The snapshots for the tagged volumes are merged to their respective source logical volumes. For information about tagging logical volumes, see Section 4.7, Tagging LVM2 Storage Objects.
The options include:
Run the daemon in the background. This allows multiple specified snapshots to be merged concurrently in parallel.
Report progress as a percentage at regular intervals. Specify the interval in seconds.
For more information about this command, see the lvconvert(8) man page.
lvconvert --merge /dev/lvmvg/linux01-snap
This command merges /dev/lvmvg/linux01-snap into its source logical volume.
lvconvert --merge @mytag
If lvol1, lvol2, and lvol3 are all tagged with mytag, each snapshot volume is merged serially with its respective source logical volume; that is: lvol1, then lvol2, then lvol3. If the --background option is specified, the snapshots for the respective tagged logical volume are merged concurrently in parallel.
(Optional) If both the source logical volume and snapshot volume are open and they can be closed, you can manually deactivate and activate the source logical volume to get the merge to start immediately.
umount <original_volume> lvchange -an <original_volume> lvchange -ay <original_volume> mount <original_volume> <mount_point>
umount /dev/lvmvg/lvol01 lvchange -an /dev/lvmvg/lvol01 lvchange -ay /dev/lvmvg/lvol01 mount /dev/lvmvg/lvol01 /mnt/lvol01
(Optional) If both the source logical volume and snapshot volume are open and the source logical volume cannot be closed, such as the root file system, you can restart the server and mount the source logical volume to get the merge to start immediately after the restart.