2 为镜像test.qcow2创建快照,创建快照并没有产生新的镜像,虚拟机镜像大小增加,快照应属于镜像。
[root@nc1 boss]#qemu-img snapshot -c snapshot01
test.qcow2
[root@nc1 boss]#qemu-img snapshot -c snapshot02
test.qcow2
快照名 镜像名
3 列出某个镜像的所有快照
[root@nc1 boss]#qemu-img snapshot -l test.qcow2
Snapshot list:
ID
TAG
VM
SIZE
DATE VM CLOCK
1
snapshot01
0 2011-09-07 15:39:25 00:00:00.000
2
snapshot02
0 2011-09-07 15:39:29 00:00:00.000
4 使用快照
[root@nc1 boss]#qemu-img snapshot -a snapshot01
test.qcow2
5 删除快照
[root@nc1 boss]#qemu-img snapshot -d snapshot01
test.qcow2
附:
'snapshot' is the name of the snapshot to create, apply or
delete
'-a' applies a snapshot (revert disk to saved state)
'-c' creates a snapshot
'-d' deletes a snapshot
'-l' lists all snapshots in the given image
实例二 利用libvirt使用快照
1 同样先确认镜像的格式为qcow2
[root@nc1 boss]#qemu-img info test.qcow2
image: test.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.1G
cluster_size: 65536
2
创建并启动以test.qcow2作为镜像的虚拟机,假设虚拟机名称为testsnp,如果虚拟机没有启动,也可创建快照,但是意义不大,快照size为0
开始使用配置文件来创建指定虚拟机的快照
保存为snp.xml,开始创建
[root@nc1 boss]#virsh snapshot-create testsnp snp.xml
//即以snp.xml作为快照的配置文件为虚拟机testsnp创建快照
Domain snapshot snapshot02 created from 'snp.xml'
3 查看虚拟机testsnp已有的快照
[root@nc1 boss]# virsh snapshot-list testsnp
Name
Creation
Time
State
---------------------------------------------------
1315385065
2011-09-07 16:44:25 +0800
running
//1315385065创建时间比snapshot02早
snapshot02
2011-09-07 17:32:38 +0800 running
同样地,也可以通过qemu-img命令来查看快照
[root@nc1 boss]# qemu-img info test.qcow2
image: test.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.2G
cluster_size: 65536
Snapshot list:
ID
TAG
VM
SIZE
DATE VM CLOCK
1
1315385065
149M 2011-09-07 16:44:25 00:00:48.575
2
snapshot02
149M 2011-09-07 17:32:38 00:48:01.341
4 可以通过snapshot-dumpxml命令查询该虚拟机某个快照的详细配置
[root@nc1 boss]# virsh snapshot-dumpxml testsnp 1315385065
查看第二个snapshot
[root@nc1 boss]# virsh snapshot-dumpxml testsnp
snapshot02
5 查看最新的快照信息
[root@nc1 boss]# virsh snapshot-current testsnp
6 使用快照,指定使用哪一个快照恢复虚拟机
[root@nc1 boss]# virsh snapshot-revert testsnp snapshot02
7 删除指定快照
[root@nc1 boss]# virsh snapshot-delete testsnp
snapshot02
Domain snapshot snapshot02 deleted
附:
Snapshot (help keyword 'snapshot')
snapshot-create
Create a snapshot from XML
snapshot-create-as
Create a snapshot from a set of args
snapshot-current
Get the current snapshot
snapshot-delete
Delete a domain snapshot
snapshot-dumpxml
Dump XML for a domain snapshot
snapshot-list
List snapshots for a domain
snapshot-revert
Revert a domain to a snapshot