9

Steps to reproduce

  • create a snapshot of a volume using lvm

lvcreate -L 200GB -s -n snapshotname /dev/hostname-vg/root

  • make changes to the filesystem

  • restore the filesystem to the state it was in when the snapshot was made

lvconvert --merge /dev/hsotname-vg/snapshottorestore

  • reboot (since I'm restoring the root volume)
  • show list of snapshots lvs -a

Desired behaviour

The original snapshot still exists

Actual behaviour

The original snapshot was deleted when the system was restored to the snapshot

Question

Is there an alternative to lvconvert, or a flag I can add to it, so that the original snapshot is not deleted?

Use case

  • I take a snapshot of a working system
  • I make changes
  • The changes fail
  • I restore to the working system
  • I want to retry the changes in a slightly different way, leaving open the possibility of restoring to a working system again

Using the lvconvert command above, I need to remember to manually recreate the same snapshot again after restoring. Since this is a large volume with many changes, I need to wait half an hour before making the snapshot. (You can't take a snapshot of a volume still merging)

The volume is restored immediately. So I have a clean system I could use immediately, but I don't want to proceed without a backup. So I need to twiddle my thumbs for half an hour, then make a backup, then make the changes.

falsePockets
  • 195
  • 5
  • Unfortunately this is the expected result. As per redhat documentation `When the merge finishes, the merged snapshot is removed.`. Please find more info [Here](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/snapshot_merge). – Manuel Florian Jan 03 '19 at 04:01
  • Initially creating thin provisionning (`man lvmthin.7`) makes easy the creation of multiple, cheap, snapshots including snapshot of snapshot. Those snapshots are r/w. One different thing is about reverting to a previous snapshot: for your purpose you'd remove the original lv and create a new snapshot of the not-any-longer-snapshot (not-any-longer: that just means it will again auto activate). Of course there are also drawbacks (eg: need to monitor space, fragmentation). – A.B Jun 15 '21 at 19:20

1 Answers1

1

There is no way you can keep the snapshot unless you would implement this as a feature in LVM.

When writing to a logical volume that has a snapshot, it first copies the current block from the origin into the snapshot and marks the block as changed. (Source)

After the lvconvert merge is initiated it stops copying data over to the snapshot (Copy on Write). If it would continue to do so, it would copy the data merged from the snapshot, back into the snapshot itself.

When the lvconvert merge is finished, it calls for the deletion of the snapshot here. This is because the snapshot still contains a copy of the data that it received while data from the origin was being overwritten.

It would be new feature to mark a snapshot merge action to "keep a snapshot", which would trigger a snapshot creation after merging is finished and deletion is done.

In your case, you might already be satisfied by creating a snapshot with a certain name, then have an @reboot cronjob that will check if the snapshot exists and create one if not.

Marco
  • 287
  • 1
  • 2
  • 12