A snapshot will store copies of your files and configuration at the time of the snapshot. It requires free space in the volume group. The space can be any amount.
It uses Copy-On-Write technology to store the original unchanged data. It will only store the one original copy as follows:
Snapshot created on Monday
File1 edited on Tuesday
File2 deleted Tuesday
File deleted on Friday
You can restore only File1 and File2 from Monday, the edits from Tuesday to Friday are lost forever.
If you wish to have multiple copies of the past, you can create multiple snapshots.
Please note:
Multiple snapshots slows down the filesystem because each snapshot needs updating in turn. Very old snapshot also cause exponential slowdown as it tries to track an increasing number of changes. Generally keep them fresh and a small quantity
lvcreate --size 10G --snapshot --name root_snap /dev/centos/root
lvcreate -L 10G -s -n root_snap /dev/centos/root #same but shorter
lvdisplay vg_tecmint_extra/tecmint_data_snap |grep Allocated Allocated to snapshot 34%
When the “Allocated to snapshot” value reaches 100%, you will be unable to make changes to the source volume. (I/O ERROR) If you have the space to make the snapshot the same size as your original logical volume, you will not have this error. The size should be at least the same as the free space of the source, plus any changes you are likely to make to the exiting files.
You can increase the size as needed using standard tools:
lvextend -L +10G /dev/centos/root_snap #add 10g more to the snapshot
To restore the snapshot, first you must unmount the source filesystem. For root, you will need to use a rescue system.
Then run the following:
lvconvert --merge /dev/centos/root_snap #name of the snapshot, not the source
The snapshot will be gone, and you can create a new snapshot
If you wish to keep some free space in the volume group pool, you can enable a feature that auto extends the snapshot as needed
cat /etc/lvm/lvm.conf snapshot_autoextend_threshold = 75 #Percentage point at which the snapshot will be expanded snapshot_autoextend_percent = 20 #percentage amount it will be expanded by
If you no longer need the data from the time of the snapshot, you can delete is as normal:
lvremove /dev/centos/root_snap #this will not affect the live system