Linux LVM快照功能

测试环境:
# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.5 (Santiago)
# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00081365

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         287     2097152   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             287        5222    39640064   83  Linux


Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa976011c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         200     1606468+  83  Linux
/dev/sdb2             201         400     1606500   83  Linux
/dev/sdb3             401         652     2024190   83  Linux


(1)使用预分配的磁盘创建vg及lv
# vgcreate vghgdb01 /dev/sdb3
  Volume group "vghgdb01" successfully created
# lvcreate -n lvhgdb01 vghgdb01 -L 200M

  Logical volume "lvhgdb01" created


(2)格式化lv为文件系统
# mkfs.ext4  /dev/vghgdb01/lvhgdb01 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

(3)挂载文件系统
# mount /dev/vghgdb01/lvhgdb01 /hgdata/

(4)创建测试目录IAMTEST
# cd /hgdata/
# mkdir IAMTEST
# ls
IAMTEST  lost+found

(5)创建LVM快照
# lvcreate -s -n snap20170919 vghgdb01/lvhgdb01 -L 500M
  Reducing COW size 500.00 MiB down to maximum usable size 204.00 MiB.
  Logical volume "snap20170919" created
检查确认创建的快照:
# lvs
  LV           VG       Attr       LSize   Pool Origin   Data%  Move Log Cpy%Sync Convert
  lvhgdb01     vghgdb01 owi-aos--- 200.00m                                               
  snap20170919 vghgdb01 swi-a-s--- 204.00m      lvhgdb01   0.02  
  
(6)第二次创建测试目录Iamtest2
# mkdir Iamtest2
# ls
IAMTEST  Iamtest2  lost+found

(7)将快照作为文件系统挂载至/hgbackup目录下
# mount  /dev/mapper/vghgdb01-snap20170919 -t ext4 /hgbackup/
# df -h
Filesystem                         Size  Used Avail Use% Mounted on
/dev/sda3                           38G   15G   21G  42% /
tmpfs                              495M   72K  495M   1% /dev/shm
/dev/sda1                          194M   30M  155M  16% /boot
/dev/mapper/vghgdb01-lvhgdb01      194M  5.6M  179M   4% /hgdata
/dev/mapper/vghgdb01-snap20170919  194M  5.6M  179M   4% /hgbackup
验证快照中的数据仅有IAMTEST,而没有Iamtest2:
# cd /hgbackup/
# ls
IAMTEST  lost+found

(8)确认快照信息无用时,可以使用如下方式删除LVM快照
卸载快照挂载的文件系统:

# umount /hgbackup/
# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/sda3                       38G   15G   21G  42% /
tmpfs                          495M   72K  495M   1% /dev/shm
/dev/sda1                      194M   30M  155M  16% /boot
/dev/mapper/vghgdb01-lvhgdb01  194M  5.6M  179M   4% /hgdata
确认快照名称:
# lvs
  LV           VG       Attr       LSize   Pool Origin   Data%  Move Log Cpy%Sync Convert
  lvhgdb01     vghgdb01 owi-aos--- 200.00m                                               
  snap20170919 vghgdb01 swi-a-s--- 204.00m      lvhgdb01   0.02  
删除快照:  
# lvremove /dev/vghgdb01/snap20170919 
Do you really want to remove active logical volume snap20170919? [y/n]: y
  Logical volume "snap20170919" successfully removed
确认快照已删除:
# lvs
  LV       VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lvhgdb01 vghgdb01 -wi-ao---- 200.00m    

你可能感兴趣的:(Linux)