查看虛擬機所在主機和虛擬機名稱:
[root@node-1 ~]# nova show a88dcf5d-c8b2-46a5-af27-a176d8235c9d|grep hyper
| OS-EXT-SRV-ATTR:hypervisor_hostname | node-5.evecom.net |
[root@node-1 ~]# nova show a88dcf5d-c8b2-46a5-af27-a176d8235c9d|grep instance_name
| OS-EXT-SRV-ATTR:instance_name | instance-000006b7 |
[root@node-1 ~]#
[root@node-1 ~]# ssh 168.5.23.8
查看虛擬機的磁盤掛載狀況:
[root@node-5 ~]# virsh domblklist instance-000006b7 --details
Type Device Target Source
------------------------------------------------
file disk vda /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk
若是是掛載了Cinder卷的虛擬機:
[root@node-5 ~]# virsh domblklist instance-000006a8 --details
Type Device Target Source
------------------------------------------------
file disk vda /var/lib/nova/instances/406e6d64-9ccf-44a5-a0d4-027ee4de3d24/disk
file disk vdb /var/lib/nova/mnt/348597c68c44fd4c679cd81c3989af6f/volume-b827d6fb-cb61-4b40-97e5-4574f9877abb
對磁盤作快照:
[root@node-5 ~]# virsh snapshot-create-as instance-000006b7 snapshot1 "just for test snapshot" --disk-only --atomic
Domain snapshot snapshot1 created
[root@node-5 ~]#
觀察到虛擬機建立快照後,磁盤引用路徑已經指向快照文件:
[root@node-5 ~]# virsh domblklist instance-000006b7 --details
Type Device Target Source
------------------------------------------------
file disk vda /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk.snapshot1
qemu-img命令能夠看出快照文件的源文件:
[root@node-5 ~]# qemu-img info /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk.snapshot1
image: /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk.snapshot1
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 384K
cluster_size: 65536
backing file: /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk
backing file format: qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
查看快照文件大小:
[root@node-5 ~]# du -ms /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk.snapshot1
1 /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk.snapshot1
此時可對源文件進行備份。
登陸虛擬機,設置不一樣顏色的桌面背景以示區別,再正常關閉虛擬機,並使用「nova start <instance_id>」命令從新啓動虛擬機:
[root@node-5 ~]# virsh domuuid instance-000006b7
a88dcf5d-c8b2-46a5-af27-a176d8235c9d
[root@node-5 ~]# exit
logout
Connection to 168.5.23.8 closed.
[root@node-1 ~]# nova get-vnc-console a88dcf5d-c8b2-46a5-af27-a176d8235c9d novnc
+-------+---------------------------------------------------------------------------------+
| Type | Url |
+-------+---------------------------------------------------------------------------------+
| novnc | http://168.5.24.2:6080/vnc_auto.html?token=9161bc2d-6d2c-4825-801c-51b50e2862bf |
+-------+---------------------------------------------------------------------------------+
[root@node-1 ~]# nova start a88dcf5d-c8b2-46a5-af27-a176d8235c9d
經「nova start <instance_id>」命令啓動虛擬機,虛擬機的磁盤又引用到了初始的磁盤文件:
[root@node-5 ~]# virsh domblklist instance-000006b7 --details Type Device Target Source
------------------------------------------------
file disk vda /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk
刪除快照:
[root@node-5 ~]# virsh snapshot-delete instance-000006b7 --metadata snapshot1
[root@node-5 ~]# virsh snapshot-list instance-000006b7
快照文件仍殘留在磁盤,可手動刪除:
[root@node-5 ~]# du -ms /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/*
0 /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/console.log
49 /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk
1 /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk.info
28 /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/disk.snapshot1
1 /var/lib/nova/instances/a88dcf5d-c8b2-46a5-af27-a176d8235c9d/libvirt.xml
快照的升級版使用參考:
https://kashyapc.fedorapeople.org/virt/lc-2012/snapshots-handout.html
學習了以上連接後,瞭解到QEMU的快照還分紅內部快照和外部快照。上文建立的是外部快照,如今嘗試建立內部快照,內部快照可以保存內存狀態。
[root@node-1 ~]# ssh 168.5.23.7
root@168.5.23.7's password:
Last login: Tue Mar 29 11:06:48 2016 from node-1.evecom.net
[root@node-4 ~]# virsh snapshot-create-as instance-000006ba snapshot1 "Just For Test"
Domain snapshot snapshot1 created
(SUSE官網的文章是:virsh snapshot-create-as --domain admin_server --name "Snapshot 2" --description "First live snapshot" --live)
內部快照建立完後,並無在原來的磁盤目錄生成快照文件:
[root@node-4 ~]# ls -l /var/lib/nova/instances/31b56c19-5789-4407-b350-e83b043f1165
total 471177
-rw-rw---- 1 root root 0 Mar 29 11:05 console.log
-rw-r--r-- 1 root root 482476032 Mar 29 2016 disk
-rw-r--r-- 1 nova nova 79 Mar 29 11:05 disk.info
-rw-r--r-- 1 nova nova 2595 Mar 29 11:05 libvirt.xml
[root@node-4 ~]#
也沒有改變磁盤文件的引用:
[root@node-4 ~]# virsh domblklist instance-000006ba
Target Source
------------------------------------------------
vda /var/lib/nova/instances/31b56c19-5789-4407-b350-e83b043f1165/disk
[root@node-4 ~]#
查看快照清單:
[root@node-4 ~]# virsh snapshot-list instance-000006ba
Name Creation Time State
------------------------------------------------------------
snapshot1 2016-03-29 11:22:23 +0800 running
修改虛擬機的桌面背景顏色,而後還原快照:
[root@node-4 ~]# virsh snapshot-revert --domain instance-000006ba snapshot1
桌面背景色的修改隨着還原快照被還原。
刪除快照:
[root@node-4 ~]# virsh snapshot-delete --domain instance-000006ba snapshot1
Domain snapshot snapshot1 deleted
[root@node-4 ~]# virsh snapshot-list instance-000006ba
Name Creation Time State
------------------------------------------------------------
[root@node-4 ~]#
官網又一文檔,展現了使用blockcommit合併快照:
http://wiki.libvirt.org/page/Live-merge-an-entire-disk-image-chain-including-current-active-disk
文章太多,很亂,須要系統梳理。因時間有限,暫不考慮續寫。
html