易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 3393|回复: 0
收起左侧

openstack 创建快照介绍

[复制链接]
发表于 2017-12-7 11:51:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
openstack而言,虚拟机的快照即是镜像,快照做完后以镜像形式存于glance。虽然openstack的快照是基于libvirt(qemu-kvm),但是二者在实现上有很大区别:
( x0 B: Z' ?6 _  zlibvirt 主流快照实现: 采用virDomainSnapshotCreateXML()函数(CLI为virsh snapshot-create)。 新建的快照与虚拟机有关联:若为内置快照,快照信息和虚拟机存在同一个qcow2镜像中;若为外置快照,新建一个qcow2文件,原虚拟机的disk将变为一个read only的模板镜像,新qcow2镜像仅记录与2.模板镜像的差异数据。这种快照包含快照链信息,可保留disk和ram信息,可回滚至快照点。0 g! W% q+ W8 i
openstack快照实现:openstack并未采用virDomainSnapshotCreateXML()来实现快照,而是单纯的对虚拟机镜像做转换和拷贝,生成一个与虚拟机无关联的镜像,最后上传至glance中。这种快照不包含快照链信息,只保留disk信息,无法回滚至快照点,只能采用该快照镜像创建一个新的虚拟机。1 b5 I: I0 n8 I+ G( Z: q
/ D# K5 I* M5 U% |
2. cold snapshot and live snapshot! D, I- g3 Y3 C- f5 J# w
cold snapshot:  创建snapshot时,需暂停虚拟机。
. q4 C& S' J0 N" B& C0 ~live snapshot:   创建snapshot时,无需暂停虚拟机。' u6 o) S& U$ b

. |7 h+ ^3 ]) @+ F3. cold snapshot 流程:
% D% ~( M3 c; @) ~# Save the state and stop a running guest, then detach pci devices% ^/ T; }+ I+ h
      $ virsh   managedsave   vm5 }4 V: g1 h  u& F
# Create a qemu internal snapshot1 `# G! P" x: d8 O' R
      $ qemu-img    snapshot   -c   snap1   vm_snapshot
) C4 p7 I2 ?. P) f' }# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance9 m" N) T( ^2 m3 c$ K
      $ qemu-img    convert   -f   qcow2   vm   -O   qcow2   vm_snapshot
1 S- _/ |. T9 U5 `2 @  L* U# Start the guest again
8 B6 {; B1 B) k# G) W4 y      $ virsh   start   vm, g9 U9 D/ R( J) n+ h7 e9 M" V  b
- n( h3 w8 `; X/ b$ J
4. live snapshot 流程
/ ]7 i# M8 y, A" {# Abort any failed/finished block operations:2 V- }! W9 k$ i% k. H
     $ virsh blockjob vm vda --abort0 ^' a# P$ @! L/ s: h9 w& o
# Undefine a running domain. (Note: Undefining a running domain does not _kill_ the domain, it just converts it from persistent to transient.)) {; c. p* Q* S- f. w& A
     $ virsh undefine vm, e: g! X. s& c6 a1 v/ ~
# create a destination image with the original backing file and matching size of the instance root disk.
) O' h+ z# v. t( O8 Q     $ qemu-img create -f qcow2 vm_copy --backing_file=backing_file --size=root_disk_size
7 v6 E7 W* o/ W  a#Invoke 'virsh blockcopy' (This will take time, depending on the size of disk image vm1):- F1 g* P3 c$ e4 C+ y( o
     $ virsh blockcopy --domain vm vda vm_copy --wait --verbose
3 Y# |) _9 A- U- p7 M/ ^#Abort any failed/finished block operations:
# P9 Z" f1 Y. l# N9 W' \* n    $ virsh blockjob vm vda --abort
! s  k  q* q: B3 }/ A7 X#Define the guest again (to make it persistent):: o" Q& e6 Q+ `/ s
    $ virsh define vm
' u; E  V  b! T$ @3 T#From the obtained new copy, convert the QCOW2 with a backing file to a qcow2 image with no backing file, then upload to glance:) C& F5 B- e: g9 T) h
    $ qemu-img convert -f qcow2 -O raw vm_copy vm_convert
: V( D% O/ f7 t& ^9 w2 D0 m; w4 w& y4 h+ g0 R
5. virsh snapshot-create-as/snapshot-create 快照简析 ) Z, x0 m* u$ \: {8 l0 _
    默认为内置快照,支持快照链,支持快照回滚,支持内存信息。  Q6 T( }/ P3 }
    快照过程中,虚拟机短暂卡顿。
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 点击这里给我发消息

GMT+8, 2026-4-8 15:20 , Processed in 0.132389 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表