linux系统中创建逻辑卷快照步骤
逻辑卷快照相当于对某一个逻辑卷(挂载点)进行了拷贝,快照可以实现逻辑卷(挂载点)的快速恢复。
逻辑卷快照的两个特点:
快照劵容量必须等同于逻辑卷的大小(相当于拷贝)
快照劵仅一次有效,一旦执行还原操作则会被自动删除
实验:对逻辑卷lv2拍摄快照,在拍摄快照前后分别在lv2挂载点创建文件,解除lv2的挂载,然后恢复快照,观察lv2挂载点的文件是否仅保留拍摄快照前的文件。
1、快照劵容量必须等同于逻辑卷大小,查看lv2逻辑卷大小
[root@PC1linuxprobe /]# lvscan
ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit
ACTIVE '/dev/rhel/root' [17.51 GiB] inherit
ACTIVE '/dev/vg1/lv1' [100.00 MiB] inherit
ACTIVE '/dev/vg1/lv2' [300.00 MiB] inherit
2、拍摄快照前向lv2挂载点写入文件
[root@PC1linuxprobe /]# 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 140K 994M 1% /dev/shm
tmpfs 994M 8.8M 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/vg1-lv2 283M 2.1M 262M 1% /lvmounttest
[root@PC1linuxprobe /]# echo "before snap" > /lvmounttest/beforesnap
[root@PC1linuxprobe /]# ls /lvmounttest/
beforesnap lost+found
3、拍摄快照
[root@PC1linuxprobe /]# lvcreate -s -n snap -L 300M /dev/vg1/lv2
Logical volume "snap" created
[root@PC1linuxprobe /]# lvscan
ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit
ACTIVE '/dev/rhel/root' [17.51 GiB] inherit
ACTIVE '/dev/vg1/lv1' [100.00 MiB] inherit
ACTIVE Original '/dev/vg1/lv2' [300.00 MiB] inherit
ACTIVE Snapshot '/dev/vg1/snap' [300.00 MiB] inherit
4、拍摄快照后向lv2挂载点写入文件
[root@PC1linuxprobe /]# echo "after snap" > /lvmounttest/aftersnap
[root@PC1linuxprobe /]# ls /lvmounttest/
aftersnap beforesnap lost+found
5、解除逻辑卷lv2的挂载
[root@PC1linuxprobe /]# 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 140K 994M 1% /dev/shm
tmpfs 994M 8.8M 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/vg1-lv2 283M 2.1M 262M 1% /lvmounttest
[root@PC1linuxprobe /]# umount /lvmounttest/
[root@PC1linuxprobe /]# 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 140K 994M 1% /dev/shm
tmpfs 994M 8.8M 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、查看此时逻辑卷lv2挂载点
[root@PC1linuxprobe /]# ls /lvmounttest/
7、恢复逻辑卷lv2的快照
[root@PC1linuxprobe /]# lvconvert --merge /dev/vg1/snap
Merging of volume snap started.
lv2: Merged: 100.0%
Merge of snapshot into logical volume lv2 has finished.
Logical volume "snap" successfully removed
8、挂载、查看逻辑卷lv2挂载点
[root@PC1linuxprobe /]# mount /dev/vg1/lv2 /lvmounttest/
[root@PC1linuxprobe /]# ls /lvmounttest/
beforesnap lost+found
总结:
逻辑卷快照创建步骤:
- 查看逻辑卷大小,示例:lvscan
- 创建逻辑卷快照,示例:lvcreate -L xxxM -s -n snapname /dev/vgname/lvname
- 解除逻辑卷挂载,示例:umount /mountpoint
- 恢复逻辑卷快照,示例:lvconvert --merge /dev/vgname/snapname
- 挂载,示例:mount /dev/vgname/lvname /mountpoint
注:
- 逻辑卷快照需要与逻辑卷大小一致,逻辑卷大时可能耗时
- 逻辑卷快照是一次性产品