< 4 Thin Provisioning | Commands | 6 Metadata Recovery of a Physical Volume >
30 – 32 Snapshots
https://www.udemy.com/course/a-complete-guide-on-linux-lvm/learn/lecture/13062442#overview
30. Overview
- An LVM Snapshot is an exact copy of an LVM partition that has all the data from the LVM volume from the time the snapshot was created.
- An advantage of LVM snapshots is that they can be used to significantly reduce the amount of time that your services/databases are down during backups because a snapshot is usually created in fractions of a second.
- After a snapshot has been created, you can backup the snapshot while your services and databases are in normal operation.
- LVM snapshots are very space efficient. Only the data and metadata are copied. As the amount of content increases, so will the size of the snapshot.
- Snapshots should not be kept for a long time as they will continue to consume disk space. In these cases, a backup is preferred over a snapshot.
31. Lab 1
https://www.udemy.com/course/a-complete-guide-on-linux-lvm/learn/lecture/13062450#overview
# create logical volume 'data' lvcreate -L 1G -n data VG # mount the LV mkfs -t ext4 /dev/VG/data mkdir /mnt/data mount /dev/VG/data /mnt/data # put some files on it - 100MB total cp 20mb.file /mnt/data cp 30mb.file /mnt/data cp 50mb.file /mnt/data # Create a snapshot (Size Matters! See Note!) lvcreate -L 120M -s -n data_snap /dev/VG/data Logical volume "data_snap" created. # Mount the snapshot to see what is there mkdir /mnt/data_snapshot mount /dev/VG/data_snap /mnt/data_snapshot ls /mnt/data_snapshot 20mb.file 30mb.file 50mb.file
Things to note:
- The snapshot LV size will be the same as the volume you took the snapshot from
- The COW-table size will be the size you allocated for the snapshot volume
- If the used disk space of the ‘source’ LV later increases beyond this volume, the snapshot will become corrupt!
- Watch Lab 32 for more information.
- It may be possible to extend the snapshot volume to match the original’s used disk space to avoid corruption.
# lvdisplay /dev/VG/data_snap --- Logical volume --- LV Path /dev/VG/data_snap LV Name snap_data VG Name system LV UUID NwJSQu-NjIr-7Qn0-Wo0q-ig7d-3apy-eChdWD LV Write Access read/write LV Creation host, time nds18-rdssrv, 2017-09-13 04:23:35 -0400 LV snapshot status INACTIVE destination for data LV Status available # open 0 LV Size 1.00 GiB Current LE 256 COW-table size 120.00 Mib COW-table LE 50 Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:12
How to restore from a snapshot
# delete all files from the original LV cd /mnt/data rm -rf * # Unmount the 'corrupt' LV umount /dev/data # Merge the snapshot into the corrupt LV # * Since we do not tell the snapshot what to merge into, # * it must know from its metadata? lvconvert --merge /dev/VG/data_snap # Mount the original LV back mount /mnt/data /dev/VG/data ls /mnt/data 20mb.file 30mb.file 50mb.file
31. Lab 2 – Updating a snapshot
# show existing files ls /mnt/data 20mb.file 30mb.file 50mb.file # take a new snapshot lvcreate -L120 -s -n data_snap /dev/VG/data # create some new files ???