linux lv snapshot
扩展所有可以vg空间给lvlvextend -l +100%free /dev/vg01/lv01# lvcreate -L 300M -s -n lv01_snap /dev/vg01/lv01
# lvscan
ACTIVE Original '/dev/vg01/lv01' inherit
ACTIVE Snapshot '/dev/vg01/lv01_snap' inherit
# lvs
LV VG Attr LSize Origin Snap%Move Log Copy%Convert
lv01 vg01 owi-ao 6.00G
lv01_snap vg01 swi-a- 300.00M lv01 0.00
# lvdisplay
--- Logical volume ---
LV Name /dev/vg01/lv01
VG Name vg01
LV UUID 4tpV09-QXVs-Cw1K-wVh2-GREZ-gPfN-Xxnrsj
LV Write Access read/write
LV snapshot status source of
/dev/vg01/lv01_snap
LV Status available
# open 1
LV Size 6.00 GB
Current LE 1536
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/vg01/lv01_snap
VG Name vg01
LV UUID sZUMpU-o2Bi-euaO-yUBm-cNRT-X13f-SchR61
LV Write Access read/write
LV snapshot status active destination for /dev/vg01/lv01
LV Status available
# open 0
LV Size 6.00 GB
Current LE 1536
COW-table size 300.00 MB
COW-table LE 75
Allocated to snapshot0.00%
Snapshot chunk size 4.00 KB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
#
# mkdir /mnt/lv01_snap
# mount /dev/vg01/lv01_snap /mnt/lv01_snap/
# ls /mnt/lv01
etcetc2loglost+found
#
# ls /mnt/lv01_snap/
etcetc2loglost+found
测试一:修改原始卷:适合使用快照备份
===建议快照卷不要挂载
# umount /mnt/lv01_snap/
# rm -rf /mnt/lv01/etc
# lvs
LV VG Attr LSize Origin Snap%Move Log Copy%Convert
lv01 vg01 owi-ao 6.00G
lv01_snap vg01 swi-a- 300.00M lv01 0.23
#
# lvdisplay vg01/lv01_snap
--- Logical volume ---
LV Name /dev/vg01/lv01_snap
VG Name vg01
LV UUID sZUMpU-o2Bi-euaO-yUBm-cNRT-X13f-SchR61
LV Write Access read/write
LV snapshot status active destination for /dev/vg01/lv01
LV Status available
# open 0
LV Size 6.00 GB
Current LE 1536
COW-table size 300.00 MB
COW-table LE 75
Allocated to snapshot0.23%
Snapshot chunk size 4.00 KB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
# cp -rf /etc/ /mnt/lv01/etc3
示例:脚本
1. 创建快照
2. 建议以只读的方式挂载快照卷
3. 备份软件读取快照卷的挂载点备份,例如需要30分钟
4. 备份结束后
卸载快照卷
删除快照卷
===手工指定快照卷的大小:快照卷的大小要根据原卷的数据增长情况而定
测试二:修改快照卷:适合快速建立虚拟机,测试场景
===建议原卷不要挂载
# umount /mnt/lv01
# lvcreate -L 100M -s -n lv01_snap1 /dev/vg01/lv01
Logical volume "lv01_snap1" created
# lvcreate -L 100M -s -n lv01_snap2 /dev/vg01/lv01
Logical volume "lv01_snap2" created
# lvcreate -L 100M -s -n lv01_snap3 /dev/vg01/lv01
Logical volume "lv01_snap3" created
# mkdir /mnt/lv01_snap1
# mkdir /mnt/lv01_snap2
# mkdir /mnt/lv01_snap3
# mount /dev/vg01/lv01_snap1 /mnt/lv01_snap1/
# mount /dev/vg01/lv01_snap2 /mnt/lv01_snap2
# mount /dev/vg01/lv01_snap3 /mnt/lv01_snap3
# rm -rf /mnt/lv01_snap1/etc
# rm -rf /mnt/lv01_snap2/etc2/
# rm -rf /mnt/lv01_snap3/etc3/
# umount /mnt/lv01_snap1
# umount /mnt/lv01_snap2
# umount /mnt/lv01_snap3
# lvremove /dev/vg01/lv01_snap1
Do you really want to remove active logical volume lv01_snap1? : y
Logical volume "lv01_snap1" successfully removed
# lvremove /dev/vg01/lv01_snap2
Do you really want to remove active logical volume lv01_snap2? : y
Logical volume "lv01_snap2" successfully removed
# lvremove /dev/vg01/lv01_snap3
Do you really want to remove active logical volume lv01_snap3? : y
Logical volume "lv01_snap3" successfully removed
利用快照卷快速建立虚拟机
===虚拟机必须安装在lv上
# virsh list --all
Id 名称 状态
----------------------------------
0 Domain-0 running
1 rhel5_8-1 闲置
2 rhel5_8-2 闲置
- rhel5_8 关闭安装在逻辑卷,母机(不要使用,保留最原始)
- rhel5_8-3 关闭
- rhel5_8-4 关闭
# grep '^disk' /etc/xen/rhel5_8
disk = [ "phy:/dev/myvg/rhel5_8,xvda,w" ]
生成新虚拟机步骤:
1. 快照(生成虚拟机的磁盘文件)
# lvs
LV VG Attr LSizeOriginSnap%Move Log Copy%Convert
rhel5_8 myvg owi-a- 19.53G
# vgs
VG #PV #LV #SN Attr VSizeVFree
myvg 1 5 4 wz--n- 46.57G 19.23G
# lvcreate -L 2G -s -n rhel5_8_snap10 /dev/myvg/rhel5_8
Logical volume "rhel5_8_snap10" created
2。生成新虚拟机的配置文件
# cd /etc/xen/
# ls
auto rhel5_8-2xend-config.sxp xmexample2
qemu-ifuprhel5_8-3xend-pci-permissive.sxpxmexample.hvm
rhel5_8 rhel5_8-4xend-pci-quirks.sxp xmexample.vti
rhel5_8-1scripts xmexample1
# cp rhel5_8 rhel5_8_10
# vim rhel5_8_10
name = "rhel5_8_10"<==修改
uuid = "2e99da65-8298-482a-8c09-3f6a9b3eb5bd"<==修改 uuidgen
maxmem = 512
memory = 512
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
vfb = [ "type=vnc,vncunused=1,keymap=en-us" ]
disk = [ "phy:/dev/myvg/rhel5_8_snap10,xvda,w" ]<==修改成快照卷
vif = [ "mac=00:16:3e:0e:d1:7f,bridge=virbr0,script=vif-bridge" ]<==修改MAC (16进制 0-9,a-f)
# virsh list --all
Id 名称 状态
----------------------------------
0 Domain-0 running
1 rhel5_8-1 没有状态
2 rhel5_8-2 没有状态
- rhel5_8 关闭
- rhel5_8-3 关闭
- rhel5_8-4 关闭
- rhel5_8_10 关闭
#
# virsh start rhel5_8_10
域 rhel5_8_10 已开始
# virsh destroy rhel5_8_10
域 rhel5_8_10 被删除
# virsh undefine rhel5_8_10
域 rhel5_8_10 已经被取消定义
# lvremove /dev/myvg/rhel5_8_snap10
Do you really want to remove active logical volume rhel5_8_snap10? : y
Logical volume "rhel5_8_snap10" successfully removed
==snapshot自动增长==
# vim /etc/lvm/lvm.conf
snapshot_autoextend_threshold = 70
snapshot_autoextend_percent = 50
# /etc/init.d/lvm2-monitor restart
Stopping monitoring for VG vg01: 1 logical volume(s) in volume group "vg01" unmonitored
[确定]
Starting monitoring for VG vg01: 1 logical volume(s) in volume group "vg01" monitored
[确定]
# lvcreate -L 100M -s -n lv01_snap /dev/vg01/lv01
Logical volume "lv01_snap" created
# lvs
LV VG Attr LSize Origin Snap%Move Log Copy%Convert
lv01 vg01 owi-ao 6.00G
lv01_snap vg01 swi-a- 100.00M lv01 0.01
页:
[1]