zoukankan      html  css  js  c++  java
  • linux系统中逻辑卷快照

    LVM还具备有“快照劵”功能,该功能类似于虚拟机软件的还原时间点功能。例如,可以对某一个逻辑卷设备做一次快照,如果日后发现数据被改错了,就可以

    利用之前做好的快照劵进行覆盖还原。LVM的快照劵功能有两个特点:

    快照劵的容量必须等同于逻辑卷的容量。

    快照劵仅一次有效,一旦执行还原操作后则会被立即自动删除。(linux就该这么学p150)

    1、首先查看卷组信息

    [root@linuxprobe dev]# vgdisplay  ## 卷组中已经使用了100MB的容量,空闲容量还有39.89G
      --- Volume group ---
      VG Name               vgtest1
      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       25 / 100.00 MiB
      Free  PE / Size       10213 / 39.89 GiB
      VG UUID               iPlgk3-b3h6-K3XB-X4vS-ep0B-TL5x-CpjClo
    ………………

    2、向逻辑卷挂载点的目录中写入一个文件

    [root@linuxprobe dev]# ls /linuxprobe/
    lost+found
    [root@linuxprobe dev]# echo "welcome to linuxprobe" > /linuxprobe/readme.txt
    [root@linuxprobe dev]# ls /linuxprobe/
    lost+found  readme.txt

    3、使用-s参数生成一个快照劵

    [root@linuxprobe dev]# lvcreate -L 100M -s -n SNAPTEST /dev/vgtest1/lvtest1  ## -L 指定快照大小,-n制动快照名称
      Logical volume "SNAPTEST" created
    [root@linuxprobe dev]# lvdisplay  ## 显示详细信息
    ……………………
      --- Logical volume ---
      LV Path                /dev/vgtest1/SNAPTEST
      LV Name                SNAPTEST
      VG Name                vgtest1
      LV UUID                yfjyWC-uAbi-NBxh-fqCA-XiXq-9Paf-mvzofR
      LV Write Access        read/write
      LV Creation host, time linuxprobe.com, 2020-10-29 17:47:49 +0800
      LV snapshot status     active destination for lvtest1
      LV Status              available
      # open                 0
      LV Size                100.00 MiB
      Current LE             25
      COW-table size         100.00 MiB
      COW-table LE           25
      Allocated to snapshot  0.01%
      Snapshot chunk size    4.00 KiB
      Segments               1
      Allocation             inherit
    ………………………………

    4、在逻辑卷所挂载的目录中创建一个50MB的垃圾文件,然后在查看快照劵的状态。可以发现存储空间占用量上升了??

    [root@linuxprobe dev]# dd if=/dev/zero bs=50M count=1 of=/linuxprobe/rubbish.txt  ## 创建垃圾文件
    1+0 records in
    1+0 records out
    52428800 bytes (52 MB) copied, 1.44275 s, 36.3 MB/s
    [root@linuxprobe dev]# lvdisplay  ## 查看详细信息
    ………………
     --- Logical volume ---
      LV Path                /dev/vgtest1/SNAPTEST
      LV Name                SNAPTEST
      VG Name                vgtest1
      LV UUID                yfjyWC-uAbi-NBxh-fqCA-XiXq-9Paf-mvzofR
      LV Write Access        read/write
      LV Creation host, time linuxprobe.com, 2020-10-29 17:47:49 +0800
      LV snapshot status     active destination for lvtest1
      LV Status              available
      # open                 0
      LV Size                100.00 MiB
      Current LE             25
      COW-table size         100.00 MiB
      COW-table LE           25
      Allocated to snapshot  45.32%
      Snapshot chunk size    4.00 KiB
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
    ……………………

    5、先卸载逻辑卷设备的挂载

    [root@linuxprobe dev]# df -h
    Filesystem                   Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root         18G  2.9G   15G  17% /
    devtmpfs                     985M     0  985M   0% /dev
    tmpfs                        994M   80K  994M   1% /dev/shm
    tmpfs                        994M  8.9M  986M   1% /run
    tmpfs                        994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1                    497M  119M  379M  24% /boot
    /dev/sr0                     3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64
    /dev/mapper/vgtest1-lvtest1   93M   52M   35M  61% /linuxprobe
    [root@linuxprobe dev]# umount /linuxprobe/  ## 卸载
    [root@linuxprobe dev]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root   18G  2.9G   15G  17% /
    devtmpfs               985M     0  985M   0% /dev
    tmpfs                  994M   80K  994M   1% /dev/shm
    tmpfs                  994M  8.9M  986M   1% /run
    tmpfs                  994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1              497M  119M  379M  24% /boot
    /dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64

    6、为了校验SNAPTEST快照劵的效果,需要对逻辑卷进行快照还原操作。

    [root@linuxprobe dev]# lvconvert --merge /dev/vgtest1/SNAPTEST  ## 还原
      Merging of volume SNAPTEST started.
      lvtest1: Merged: 65.9%
      lvtest1: Merged: 100.0%
      Merge of snapshot into logical volume lvtest1 has finished.
      Logical volume "SNAPTEST" successfully removed

    6、快照被自动删除了,rubbish.txt也被删除了

    [root@linuxprobe dev]# mount -a  ## 挂载
    [root@linuxprobe dev]# ls /dev/vgtest1/
    lvtest1
    [root@linuxprobe dev]# ls /linuxprobe/
    lost+found  readme.txt
  • 相关阅读:
    json学习系列(1)-使用json所要用到的jar包下载
    Java 时间架构图
    时间纪元与时区介绍
    HTML5 Canvas 绘制库存变化折线
    HTML5 Canvas 笛卡尔坐标系转换尝试
    像孩童一样欣喜的看着自己的成长
    《老炮儿》结尾貌似历史上的一幕
    很多人还在守着金饭碗要饭
    还是用文本编辑器编程让人愉悦
    Node.js 网页爬虫再进阶,cheerio助力
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13898383.html
Copyright © 2011-2022 走看看