[root@yangcan Desktop]# pvcreate /dev/sda5 Writing physical volume data to disk "/dev/sda5" Physical volume "/dev/sda5" successfully created
[root@yangcan Desktop]# vgcreate vg5 /dev/sda5 Volume group "vg5" successfully created [root@yangcan Desktop]# vgs VG #PV #LV #SN Attr VSize VFree vg5 1 0 0 wz--n- 10.00g 10.00g vg_yangcan 1 2 0 wz--n- 19.51g 0
[root@yangcan Desktop]# lvcreate -L 6G -n ftp vg5 Logical volume "ftp" created [root@yangcan Desktop]# mkdir /ftp [root@yangcan Desktop]# mke2fs -T ext4 /dev/mapper/vg5-ftp mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 393216 inodes, 1572864 blocks 78643 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1610612736 48 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@yangcan /]# mount /dev/mapper/vg5-ftp /ftp/ [root@yangcan /]# mount|grep ftp /dev/mapper/vg5-ftp on /ftp type ext4 (rw) [root@yangcan /]# df -h |grep ftp /dev/mapper/vg5-ftp 6.0G 140M 5.5G 3% /ftp
[root@yangcan /]# cd /ftp/ [root@yangcan ftp]# ll total 16 drwx------. 2 root root 16384 Aug 2 21:12 lost+found
[root@yangcan ftp]# cp /etc/*.conf . [root@yangcan ftp]# cp /usr/share/dict/linux.words . [root@yangcan ftp]# ll total 5112 -rw-r--r--. 1 root root 148 Aug 2 21:18 asound.conf -rw-------. 1 root root 232 Aug 2 21:18 autofs_ldap_auth.conf -rw-r--r--. 1 root root 1780 Aug 2 21:18 cas.conf -rw-r--r--. 1 root root 21214 Aug 2 21:18 dnsmasq.conf -rw-r--r--. 1 root root 559 Aug 2 21:18 dracut.conf -rw-r--r--. 1 root root 20 Aug 2 21:18 fprintd.conf -rw-r--r--. 1 root root 0 Aug 2 21:18 gai.conf -rw-------. 1 root root 821 Aug 2 21:18 grub.conf ..........................
[root@yangcan ~]# lvcreate -L 500M -n snap-ftp -s /dev/vg5/ftp Logical volume "snap-ftp" created
我们查看一下逻辑卷和快照的信息!
[root@yangcan ~]# lvdisplay --- Logical volume --- LV Name /dev/vg5/ftp VG Name vg5 LV UUID tRDd7b-jYiA-bxA3-KtUx-mYZW-xwHL-21SSVk LV Write Access read/write LV snapshot status source of /dev/vg5/snap-ftp [active] LV Status available # open 1 LV Size 6.00 GiB Current LE 1536 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Name /dev/vg5/snap-ftp VG Name vg5 LV UUID 0y8tuc-GdFu-duvd-fSDt-wsLQ-fYWa-q6hOd3 LV Write Access read/write LV snapshot status active destination for /dev/vg5/ftp LV Status available # open 0 LV Size 6.00 GiB Current LE 1536 COW-table size 500.00 MiB COW-table LE 125 Allocated to snapshot 0.00% --此时的使用率为0 Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3
[root@yangcan ftp]# watch -n 0.5 "lvdisplay /dev/vg5/snap-ftp |grep %"
我们在开一个控制台,用于增加ftp文件的大小,此刻我们用的是ls的定向输出到文件ls.txt.因为此过程较长,我们我们有充分的时间看Allocated to snapshot大小的变化
[root@yangcan ftp]# (ls -lR / ;ls -lR /)&>./ls.txt
t1时刻--ls还未完成
t2时刻--ls已经完成!!
[root@yangcan ~]# lvdisplay --- Logical volume --- LV Name /dev/vg5/snap-ftp VG Name vg5 LV UUID 0y8tuc-GdFu-duvd-fSDt-wsLQ-fYWa-q6hOd3 LV Write Access read/write LV snapshot status active destination for /dev/vg5/ftp LV Status available # open 0 LV Size 6.00 GiB Current LE 1536 COW-table size 500.00 MiB COW-table LE 125 Allocated to snapshot 5.86% Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3
我们在t3时刻DD新建一下文件10M-t1
[root@yangcan ftp]# dd if=/dev/zero of=./10M-t1 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.0276569 s, 379 MB/s
[root@yangcan ftp]# dd if=/dev/zero of=./20M-t2 bs=1M count=20 20+0 records in 20+0 records out 20971520 bytes (21 MB) copied, 0.0647524 s, 324 MB/s
[root@yangcan ftp]# mkdir /snap-ftp [root@yangcan ftp]# mount /dev/mapper/vg5-snap--ftp /snap-ftp/
/dev/vg5/ftp挂载目录/ftp的文件! [root@yangcan ftp]# ll -nt total 65512 -rw-r--r--. 1 0 0 20971520 Aug 2 21:35 20M-t2 -rw-r--r--. 1 0 0 10485760 Aug 2 21:31 10M-t1 -rw-r--r--. 1 0 0 30389219 Aug 2 21:26 ls.txt -rw-r--r--. 1 0 0 4953699 Aug 2 21:18 linux.words -rw-r--r--. 1 0 0 969 Aug 2 21:18 yum.conf -rw-r--r--. 1 0 0 585 Aug 2 21:18 yp.conf -rw-r--r--. 1 0 0 3001 Aug 2 21:18 warnquota.conf -rw-r--r--. 1 0 0 480 Aug 2 21:18 updatedb.conf -rw-r--r--. 1 0 0 45 Aug 2 21:18 Trolltech.conf -rw-r--r--. 1 0 0 1314 Aug 2 21:18 tpvmlp.conf -rw-r--r--. 1 0 0 1148 Aug 2 21:18 sysctl.conf -rw-r--r--. 1 0 0 260 Aug 2 21:18 sos.conf -rw-r--r--. 1 0 0 1272 Aug 2 21:18 smi.conf -rw-r--r--. 1 0 0 6463 Aug 2 21:18 smartd.conf -rw-r--r--. 1 0 0 216 Aug 2 21:18 sestatus.conf -rw-r--r--. 1 0 0 2741 Aug 2 21:18 rsyslog.conf -rw-r--r--. 1 0 0 103 Aug 2 21:18 resolv.conf ..........................
快照 /dev/mapper/vg5-snap--ftp 挂载的/snap-ftp/ [root@yangcan ftp]# cd /snap-ftp/ [root@yangcan snap-ftp]# ll -nt total 5112 --和最初的大小一样 -rw-r--r--. 1 0 0 4953699 Aug 2 21:18 linux.words -rw-r--r--. 1 0 0 969 Aug 2 21:18 yum.conf -rw-r--r--. 1 0 0 585 Aug 2 21:18 yp.conf -rw-r--r--. 1 0 0 3001 Aug 2 21:18 warnquota.conf -rw-r--r--. 1 0 0 480 Aug 2 21:18 updatedb.conf -rw-r--r--. 1 0 0 45 Aug 2 21:18 Trolltech.conf -rw-r--r--. 1 0 0 1314 Aug 2 21:18 tpvmlp.conf -rw-r--r--. 1 0 0 1148 Aug 2 21:18 sysctl.conf -rw-r--r--. 1 0 0 260 Aug 2 21:18 sos.conf -rw-r--r--. 1 0 0 1272 Aug 2 21:18 smi.conf -rw-r--r--. 1 0 0 6463 Aug 2 21:18 smartd.conf -rw-r--r--. 1 0 0 216 Aug 2 21:18 sestatus.conf -rw-r--r--. 1 0 0 2741 Aug 2 21:18 rsyslog.conf -rw-r--r--. 1 0 0 103 Aug 2 21:18 resolv.conf -rw-r--r--. 1 0 0 1484 Aug 2 21:18 request-key.conf ...................................
[root@yangcan ftp]# rm -rf ./* [root@yangcan ftp]# ll total 0 [root@yangcan ftp]# lvdisplay |grep % Allocated to snapshot 11.92%
--没有什么变化,当我们删除数据的时候.真正存放数据的block区块并没有变化,真正变化的是inode节点表的信息被删了
[root@yangcan ~]# dump -0u /tmp/ftpdata.bak.dump /snap-ftp [root@yangcan yum.repos.d]# mkdir /ftpdata [root@yangcan yum.repos.d]# cd /ftpdata/ [root@yangcan ftpdata]# restore -rf /tmp/ftpdata.bak.dump