7.2. Creating a snapshot of the original volume
Use lvcreate command with the -s or --size argument followed by the required size to create a snapshot of the original volume (the origin). A snapshot of a volume is writable. By default, a snapshot volume is activated with the origin during normal activation commands as compared to the thinly-provisioned snapshots. LVM does not support creating a snapshot volume that is larger than the sum of the origin volume’s size and the required metadata size for the volume. If you specify a snapshot volume that is larger than this, LVM creates a snapshot volume that is required for the size of the origin.
The nodes in a cluster do not support LVM snapshots. You cannot create a snapshot volume in a shared volume group. However, if you need to create a consistent backup of data on a shared logical volume you can activate the volume exclusively and then create the snapshot.
The following procedure creates an origin logical volume named origin and a snapshot volume of this original volume named snap.
Conditions préalables
- You have created volume group vg001. For more information, see Creating LVM volume group.
Procédure
Create a logical volume named origin from the volume group vg001:
lvcreate -L 1G -n origin vg001
# lvcreate -L 1G -n origin vg001 Logical volume "origin" created.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a snapshot logical volume named snap of /dev/vg001/origin that is 100 MB in size:
lvcreate --size 100M --name snap --snapshot /dev/vg001/origin
# lvcreate --size 100M --name snap --snapshot /dev/vg001/origin Logical volume "snap" created.Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the original logical volume contains a file system, you can mount the snapshot logical volume on an arbitrary directory in order to access the contents of the file system to run a backup while the original file system continues to get updated.
Display the origin volume and the current percentage of the snapshot volume being used:
lvs -a -o +devices
# lvs -a -o +devices LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices origin vg001 owi-a-s--- 1.00g /dev/sde1(0) snap vg001 swi-a-s--- 100.00m origin 0.00 /dev/sde1(256)Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can also display the status of logical volume /dev/vg001/origin with all the snapshot logical volumes and their status, such as active or inactive by using the
lvdisplay /dev/vg001/origincommand.AvertissementSince the snapshot increases in size as the origin volume changes, it is important to monitor the percentage of the snapshot volume regularly with the
lvscommand to be sure it does not become full. A snapshot that is 100% full is lost completely, as a write to unchanged parts of the origin would be unable to succeed without corrupting the snapshot.You can configure LVM to automatically extend a snapshot when its usage exceeds the
snapshot_autoextend_thresholdvalue to avoid the snapshot becoming invalid when it is 100% full. View the existing values for thesnapshot_autoextend_thresholdandsnapshot_autoextend_percentoptions from the/etc/lvm.conffile and edit them as per your requirements.The following example, sets the
snapshot_autoextend_thresholdoption to value less than 100 andsnapshot_autoextend_percentoption to the value depending on your requirement to extend the snapshot volume:vi /etc/lvm.conf
# vi /etc/lvm.conf snapshot_autoextend_threshold = 70 snapshot_autoextend_percent = 20Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can also extend this snapshot manually by executing the following command:
lvextend -L+100M /dev/vg001/snap
# lvextend -L+100M /dev/vg001/snapCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis feature requires unallocated space in the volume group. An automatic extension of a snapshot does not increase the size of a snapshot volume beyond the maximum calculated size that is necessary for the snapshot. Once a snapshot has grown large enough to cover the origin, it is no longer monitored for automatic extension.