- 积分
- 16840
在线时间 小时
最后登录1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?开始注册
x
对openstack而言,虚拟机的快照即是镜像,快照做完后以镜像形式存于glance。虽然openstack的快照是基于libvirt(qemu-kvm),但是二者在实现上有很大区别:3 C% B. z" h$ f8 c" H q
libvirt 主流快照实现: 采用virDomainSnapshotCreateXML()函数(CLI为virsh snapshot-create)。 新建的快照与虚拟机有关联:若为内置快照,快照信息和虚拟机存在同一个qcow2镜像中;若为外置快照,新建一个qcow2文件,原虚拟机的disk将变为一个read only的模板镜像,新qcow2镜像仅记录与2.模板镜像的差异数据。这种快照包含快照链信息,可保留disk和ram信息,可回滚至快照点。
1 A$ e @1 @+ i+ sopenstack快照实现:openstack并未采用virDomainSnapshotCreateXML()来实现快照,而是单纯的对虚拟机镜像做转换和拷贝,生成一个与虚拟机无关联的镜像,最后上传至glance中。这种快照不包含快照链信息,只保留disk信息,无法回滚至快照点,只能采用该快照镜像创建一个新的虚拟机。) M: q9 X( y, m- F( x
( A3 j/ R2 ]" [5 `; l
2. cold snapshot and live snapshot7 u$ Z2 j; w, v* g% s4 N
cold snapshot: 创建snapshot时,需暂停虚拟机。# h" E. u4 R k& ~
live snapshot: 创建snapshot时,无需暂停虚拟机。9 |' q" F9 R: g
4 O; C9 }9 \$ K3 J) A3. cold snapshot 流程:% F, h9 R( D6 q: c j. Z
# Save the state and stop a running guest, then detach pci devices- n% n% ^3 Y' ]% T6 Y
$ virsh managedsave vm
' a* @: J m0 y5 \( @; e# Create a qemu internal snapshot- I) j6 U4 M3 y3 ~5 n2 U
$ qemu-img snapshot -c snap1 vm_snapshot
+ ?. A* h" q+ F% d# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance
( O z8 N5 |( ?. \2 n5 n $ qemu-img convert -f qcow2 vm -O qcow2 vm_snapshot
- P7 E2 d8 v7 Q% [- F) W% s( [# Start the guest again& b% T4 Y$ [9 c
$ virsh start vm
& T/ R' }6 \, W9 B
7 M6 B1 D* Z* D! m+ B% v; p* O4. live snapshot 流程0 ?" j- w, m* O2 E
# Abort any failed/finished block operations:( k: S, O5 O2 U" H6 K' j. x
$ virsh blockjob vm vda --abort
/ R" \: c, H! m6 W# Undefine a running domain. (Note: Undefining a running domain does not _kill_ the domain, it just converts it from persistent to transient.)
- b( b# ?$ g0 v9 j1 v4 M+ _( z $ virsh undefine vm
, a* d/ w& v, m& B# create a destination image with the original backing file and matching size of the instance root disk.$ ?, d# j: g3 E7 i" x
$ qemu-img create -f qcow2 vm_copy --backing_file=backing_file --size=root_disk_size
8 r, x- P3 F h o8 i#Invoke 'virsh blockcopy' (This will take time, depending on the size of disk image vm1): D; g& H* S* Z N) V5 v/ |
$ virsh blockcopy --domain vm vda vm_copy --wait --verbose. G1 k6 s3 g$ [
#Abort any failed/finished block operations:
) X; U. b' O5 T6 S) t; z3 [ $ virsh blockjob vm vda --abort
! n1 l# r a; n! I* o& a u#Define the guest again (to make it persistent):+ _) N' c4 V, ^
$ virsh define vm* U4 ]( Y5 O% t( ?3 |
#From the obtained new copy, convert the QCOW2 with a backing file to a qcow2 image with no backing file, then upload to glance:
0 r' r& b1 g$ W2 e d6 ? $ qemu-img convert -f qcow2 -O raw vm_copy vm_convert
2 Z9 \9 O- v. R* |2 j/ n% F# k5 q6 b
) Z9 N+ T: r, R) O1 n+ f, d0 D5. virsh snapshot-create-as/snapshot-create 快照简析
, I; E: ]' T7 T9 ? 默认为内置快照,支持快照链,支持快照回滚,支持内存信息。
Y0 \+ U( N9 J9 ]7 c" \; w8 J/ h 快照过程中,虚拟机短暂卡顿。 |
|