Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

7.2.4 Logical volume snapshot


May 23, 2021 That's what Linux should learn



LVM also has a "snapshot volume" feature, which is similar to the restore point-in-time feature of virtual machine software. F or example, you can take a snapshot of a logical volume device, and if you later find that the data has been changed wrong, you can override the restore with a previously prepared snapshot volume. LVM's snapshot volume feature has two features:

The capacity of the snapshot volume must be equivalent to the capacity of the logical volume;

Snapshot volumes are valid only once and are automatically deleted as soon as a restore operation is performed.

Start by looking at the volume group's information.

[root@linuxprobe ~]# vgdisplay --- Volume group --- VG Name storage System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 30 / 120.00 MiB Free PE / Size 10208 / 39.88 GiB VG UUID CTaHAK-0TQv-Abdb-R83O-RU6V-YYkx-8o2R0e .................. O mit some of the output information... T he output information of the volume group is clearly visible, the volume group has already used 120MB of capacity, and the idle capacity is 39.88GB. The next step is to redirect a file to the directory mounted by the logical volume device.

[root@linuxprobe ~]# echo "Welcome to Linuxprobe.com" > /linuxprobe/readme.txt [root@linuxprobe ~]# ls -l /linuxprobe total 14 drwx------. 2 root root 12288 Feb 1 07:18 lost+found -rw-r--r--. 1 root root 26 Feb 1 07:38 readme.txt Step 1: Create a snapshot volume using the -s parameter and specify the size of the cut using the -L parameter. In addition, you need to write after the command a snapshot of which logical volume you are performing.

[root@linuxprobe ~]# lvcreate -L 120M -s -n SNAP /dev/storage/vo Logical volume "SNAP" created [root@linuxprobe ~]# lvdisplay --- Logical volume --- LV Path /dev/storage/SNAP LV Name SNAP VG Name storage LV UUID BC7WKg-fHoK-Pc7J-yhSd-vD7d-lUnl-TihKlt LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-02-01 07:42:31 -0500 LV snapshot status active destination for vo LV Status available

open 0

  1. LV Size 120.00 MiB
  2. Current LE 30
  3. COW-table size 120.00 MiB
  4. COW-table LE 30
  5. Allocated to snapshot 0.01%
  6. Snapshot chunk size 4.00 KiB
  7. Segments 1
  8. Allocation inherit
  9. Read ahead sectors auto
  10. - currently set to 8192
  11. Block device 253:3
  12. ………………省略部分输出信息………………

Step 2: Create a 100MB junk file in the directory that the logical volume is mounted on, and then view the status of the snapshot volume. You can see that the amount of storage space is up.

[root@linuxprobe ~]# dd if=/dev/zero of=/linuxprobe/files count=1 bs=100M 1+0 records in 1+0 records out 104857600 bytes (105 MB) copied, 3.35432 s, 31.3 MB/s [root@linuxprobe ~]# lvdisplay --- Logical volume --- LV Path /dev/storage/SNAP LV Name SNAP VG Name storage LV UUID BC7WKg-fHoK-Pc7J-yhSd-vD7d-lUnl-TihKlt LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-02-01 07:42:31 -0500 LV snapshot status active destination for vo LV Status available

open 0

  1. LV Size 120.00 MiB
  2. Current LE 30
  3. COW-table size 120.00 MiB
  4. COW-table LE 30
  5. Allocated to snapshot 83.71%
  6. Snapshot chunk size 4.00 KiB
  7. Segments 1
  8. Allocation inherit
  9. Read ahead sectors auto
  10. - currently set to 8192
  11. Block device 253:3

Step 3: In order to verify the effect of the SNAP snapshot volume, a snapshot restore operation is required for the logical volume. Before you do this, remember to uninstall the logical volume device and the directory mount.

[root@linuxprobe ~]# umount /linuxprobe [root@linuxprobe ~]# lvconvert --merge /dev/storage/SNAP Merging of volume SNAP started. v o: Merged: 21.4% vo: Merged: 100.0% Merge of snapshot into logical volume vo has finished. Logical volume "SNAP" successfully removed Step 4: The snapshot volume is automatically deleted, and the 100MB of junk files that have just been created after the logical volume device has been taken for snapshot operations have also been removed.

[root@linuxprobe ~]# mount -a [root@linuxprobe ~]# ls /linuxprobe/ lost+found readme.txt