11.7. 跟踪并显示已删除的精简快照卷

这个步骤描述了如何显示和管理已删除的历史逻辑卷。

流程

  1. 通过在 lvm.conf 文件中设置 record_lvs_history=1 来确保保留了历史逻辑卷。默认不启用这个元数据选项。
  2. 可选:以秒为单位设置 lvs_history_retention_time 选项的值。这是记录自动销毁历史逻辑卷的时间间隔。自动默认值为 0,它会禁用此功能。如果没有设置这个选项,也可以手动删除单独的历史卷。
  3. 显示精简调配的快照链:

    在本例中:

    • lvol1 是一个原始卷,是链中的第一个卷。
    • lvol2lvol1 的快照。
    • lvol3lvol2 的快照。
    • lvol4lvol3 的快照。
    • lvol5 也是 lvol3 的快照。

      # lvs -H -o name,full_ancestors,full_descendants
        LV    FAncestors        FDescendants
        lvol1                   lvol2,lvol3,lvol4,lvol5
        lvol2 lvol1             lvol3,lvol4,lvol5
        lvol3 lvol2,lvol1       lvol4,lvol5
        lvol4 lvol3,lvol2,lvol1
        lvol5 lvol3,lvol2,lvol1
        pool

      请注意,虽然使用带有 -H 选项的 lvs 工具,但不会删除精简快照卷,且没有要显示的历史逻辑卷。

  4. 从快照链中删除逻辑卷 lvol3

    # lvremove -f vg/lvol3
      Logical volume "lvol3" successfully removed
  5. 运行 lvs 工具来查看历史逻辑卷的详情,以及它们的 ancestors 和 descendants:

    # lvs -H -o name,full_ancestors,full_descendants
      LV     FAncestors         FDescendants
      lvol1                     lvol2,-lvol3,lvol4,lvol5
      lvol2  lvol1              -lvol3,lvol4,lvol5
      -lvol3 lvol2,lvol1        lvol4,lvol5
      lvol4  -lvol3,lvol2,lvol1
      lvol5  -lvol3,lvol2,lvol1
      pool
  6. 另外,显示历史卷的删除时间戳:

    # lvs -H -o name,full_ancestors,full_descendants,time_removed
      LV     FAncestors         FDescendants              RTime
      lvol1                     lvol2,-lvol3,lvol4,lvol5
      lvol2  lvol1              -lvol3,lvol4,lvol5
      -lvol3 lvol2,lvol1        lvol4,lvol5               2016-03-14 14:14:32 +0100
      lvol4  -lvol3,lvol2,lvol1
      lvol5  -lvol3,lvol2,lvol1
      pool
  7. 您可以通过指定 vgname/lvname 格式在 display 命令中单独引用历史逻辑卷:

    # lvs -H vg/-lvol3
      LV     VG   Attr       LSize
      -lvol3 vg   ----h-----    0

    请注意,lv_attr 字段中的第五个位被设置为 h,表示该卷是历史的。

  8. 如果卷没有实时子卷(后代),LVM 不会保存历史逻辑卷。就是说,如果您在快照链末尾删除逻辑卷,则不会保留逻辑卷作为历史逻辑卷。

    # lvremove -f vg/lvol5
      Automatically removing historical logical volume vg/-lvol5.
      Logical volume "lvol5" successfully removed
    # lvs -H -o name,full_ancestors,full_descendants
      LV     FAncestors         FDescendants
      lvol1                     lvol2,-lvol3,lvol4
      lvol2  lvol1              -lvol3,lvol4
      -lvol3 lvol2,lvol1        lvol4
      lvol4  -lvol3,lvol2,lvol1
      pool
  9. 删除卷 lvol1lvol2,并查看 lvs 命令在卷被删除后如何显示它们。

    # lvremove -f vg/lvol1 vg/lvol2
      Logical volume "lvol1" successfully removed
      Logical volume "lvol2" successfully removed
    # lvs -H -o name,full_ancestors,full_descendants
      LV     FAncestors           FDescendants
      -lvol1                      -lvol2,-lvol3,lvol4
      -lvol2 -lvol1               -lvol3,lvol4
      -lvol3 -lvol2,-lvol1        lvol4
      lvol4  -lvol3,-lvol2,-lvol1
      pool
  10. 通过指定包含连字符的历史卷名称来完全删除历史逻辑卷,如下例所示

    # lvremove -f vg/-lvol3
    Historical logical volume "lvol3" successfully removed
    # lvs -H -o name,full_ancestors,full_descendants
      LV     FAncestors    FDescendants
      -lvol1               -lvol2,lvol4
      -lvol2 -lvol1        lvol4
      lvol4  -lvol2,-lvol1
      pool