kevin lvm snapshots

LVM snapshotting, linux undo fileystem

Undo and redo are life-savers in any app... here is how to undo a fileystem using LVM. Key points * The snapshot 'snap_lv' captured all filesystem changes on the original logical volume when the snapshot was created.…

Undo and redo are life-savers in any app... here is how to undo a fileystem using LVM.

Key points

  • The snapshot 'snap_lv' captured all filesystem changes on the original logical volume when the snapshot was created. Any file created AFTER this snapshot would remain on the original logical volume and not be reflected onto the snapshot volume.
  • It is possible to both revert to the snapshot/restore point or mount the snapshot as another mountpoint and copy files from it.
  • If an upgrade works as expected one can delete the snapshot.

1. Create an initial restore point/snapshot to revert back to

lvcreate -L 10G -s -n snap_lv /dev/vg1/lv1

lvcreate = create logical volumes ('man lvcreate' for more details)
-L 10G = create a 10 gigabyte large logical volume 
-s = create a snapshot
-n = name the snapshot
/devv/vg1/lv1 = create the snapshot from this logical volume

2. If the upgrade works as expected delete the snapshot/restore point

lvremove /dev/vg1/snap_lv

3.1 If an upgrade fails mount the restore point and copy individual files

mount /dev/vg1/snap_lv /mnt/snap_lv

3.2 If an upgrade fails revert back to the restore point and undo all file changes

lvconvert --merge /dev/vg1/snap_lv
reboot
lvchange --refresh /dev/vg1/lv1

manpages

man lvcreate
man lvconvert
man lvchange 


Full example

 # after reboot, before refresh
 # Notice the "LV Snapshot status 'source of' "
 lvdisplay /dev/vg1/lv1

  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                u4yKnO-UOMw-vdTC-xxxxx
  LV Write Access        read/write
  LV Creation host, time fivehost, 2022-07-08 21:05:15 +0200
  LV snapshot status     source of
                         snap_lv [active]
  LV Status              available
  # open                 1
  LV Size                <93.13 GiB
  Current LE             23841
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
  
  
  lsblk
  
  nv1                       259:0    0 465.8G  0 disk
└─nv1pX                   259:4    0 464.8G  0 part
  └─md2                         9:2    0 464.7G  0 raid1
    ├─vg1-lv1Rootfs   253:0    0  46.6G  0 lvm    /
    ├─vg1-lv1Vms-real 253:1    0  93.1G  0 lvm
    │ └─vg1-lv1Vms    253:3    0  93.1G  0 lvm    /vm
    ├─vg1-lv_snap-cow  253:2    0    10G  0 lvm
    │ └─vg1-lv1Vms    253:3    0  93.1G  0 lvm    /vm
    ├─vg1-lv1Var      253:5    0  23.3G  0 lvm    /var
    ├─vg1-lv1Swap     253:6    0  23.3G  0 lvm    [SWAP]
    └─vg1-lv1Home    253:7    0  46.6G  0 lvm    /home
lvchange --refresh /dev/VG1/LV1

  # After refresh
  lvdisplay /dev/vg1/lv1
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                u4yKnO-UOMw-vdTCxxxx
  LV Write Access        read/write
  LV Creation host, time FIVEHOST, 2022-07-08 21:05:15 +0200
  LV Status              available
  # open                 1
  LV Size                <93.13 GiB
  Current LE             23841
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
  
  
  
  
  lsblk
  
  nv1                       259:0    0 465.8G  0 disk
└─nv1pX                   259:4    0 464.8G  0 part
  └─md2                         9:2    0 464.7G  0 raid1
    ├─vg1-lv1Rootfs   253:0    0  46.6G  0 lvm    /
    ├─vg1-lv1Vms      253:3    0  93.1G  0 lvm    /vm
    ├─vg1-lv1Var      253:5    0  23.3G  0 lvm    /var
    ├─vg1-lv1Swap     253:6    0  23.3G  0 lvm    [SWAP]
    └─vg1-lv1Home     253:7    0  46.6G  0 lvm    /home