LVM snapshots/clone as an alternative to ZFS
Goal
Sometimes, ZFS cannot be used. In this case, let's provide an alternative way: LVM.
Cons:
- We expect that this method will be less performant (especially, for large number of snapshots and/or having old snapshots with continuously working "sync" Postgres instance).
Pros:
- Some people cannot use ZFS so they will be able to choose LVM
- In the case of LVM, the filesystem is "usual", ext4 or xfs.
- Might be the only in managed Kubernetes setups.
TODO / How to implement
Example:
sudo su -
mkdir /opt/{one,two,test}
pvcreate /dev/nvme0n1
vgcreate testgroup /dev/nvme0n1
pvscan
vgs
lvmdiskscan
lvcreate -L 29G -n test testgroup
mount /dev/testgroup/test /opt/test
echo 12345 > /opt/test/xoxo
lvcreate -L 12m -s /dev/testgroup/test -n test_snap1
mount /dev/testgroup/test_snap1 /opt/one
cat /opt/one/xoxo
echo 11111 > /opt/one/xoxo
df -hT
cat /opt/one/xoxo
cat /opt/test/xoxo
# Create LV.
sudo su -
mkdir /var/lib/dblab-lvm/clones/{1,2,3,4}
pvcreate /dev/disk/by-id/google-dblab-dev1-lvm1
vgcreate testgroup /dev/disk/by-id/google-dblab-dev1-lvm1
lvcreate -l 50%FREE -n test testgroup
mkfs.ext4 /dev/testgroup/test
# Mount to initial dir.
mount /dev/testgroup/test /var/lib/dblab-lvm/clones/1
echo 12345 > /var/lib/dblab-lvm/clones/1/xoxo
# Create snapshot.
lvcreate -l 10%FREE -s /dev/testgroup/test -n test_snap1
mount /dev/testgroup/test_snap1 /var/lib/dblab-lvm/clones/2
cat /var/lib/dblab-lvm/clones/2/xoxo
echo 11111 > /var/lib/dblab-lvm/clones/2/xoxo
df -hT
cat /var/lib/dblab-lvm/clones/1/xoxo
cat /var/lib/dblab-lvm/clones/2/xoxo
# Remove LV.
umount /dev/testgroup/test
lvremove /dev/testgroup/test
Extend/reduce:
lvreduce -L -2.5G -r /dev/vg00/vol_projects
lvextend -l +100%FREE -r /dev/vg00/vol_backups
https://www.tecmint.com/manage-and-create-lvm-parition-using-vgcreate-lvcreate-and-lvextend/
One more example: http://www.voleg.info/lvm2-clone-logical-volume.html
Good reference for lvs: https://www.systutorials.com/docs/linux/man/8-lvs/
lvs --reportformat json --units b
About snapshot oversize: https://www.golinuxhub.com/2017/09/understanding-lvm-snapshots-create.html
https://serverfault.com/questions/41020/is-this-how-lvm-snapshots-work
Thin-clones on LVM (using dd for snapshots mostly suggested):
- http://www.andybotting.com/how-do-you-clone-an-lvm-partition
- https://serverfault.com/questions/702971/cloning-lvm-partitions
- http://www.voleg.info/lvm2-clone-logical-volume.html
TODO:
-
Separate ZFS "lib" package -
Docker container volumes works fine with LVM (?) -
Determine volume size. It's required option to create a LVM clone. -
Clone removal policies (?) (e.g. can we stop removal of clone on volume size exceed?)
Depends on #92 #95 #96 #97 (closed) #98
Acceptance criteria
As a user, I can choose a method for thin cloning, ZFS (default) or LVM.
As a developer, I know that the abstraction interface/layer is mature and when needed, I can implement my own thin cloning method.