抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

[toc]

kvm之快照管理

使用kvm快照,磁盘则必需要使用qcow2的格式

# qemu-img info centos6.test-x86_64.raw 
image: centos6.test-x86_64.raw
file format: raw
virtual size: 80G (85899345920 bytes)
disk size: 1.2G
#

关闭虚拟机并改变磁盘的格式

# virsh list
 Id    名称                         状态
----------------------------------------------------
 2     ubuntu-14.4-n1                 running
 14    ubuntu-14.4-113-pycharm        running
 16    ubuntu-14.4-n2                 running
 20    centos-6.8-grafana             running
 22    centos-6.8-data                running
 24    centos-6.8-test                running
# virsh destroy centos-6.8-test
域 centos-6.8-test 被删除
# virsh  list --all
 Id    名称                         状态
----------------------------------------------------
 2     ubuntu-14.4-n1                 running
 14    ubuntu-14.4-113-pycharm        running
 16    ubuntu-14.4-n2                 running
 20    centos-6.8-grafana             running
 22    centos-6.8-data                running
 -     centos-6.8-n1                  关闭
 -     centos-6.8-test                关闭
 -     renjin-scripts                 关闭
 -     ubuntu-14.4-n3                 关闭
# qemu-img convert -f raw -O qcow2 centos6.test-x86_64.raw centos6.test-x86_64.qcow2
# virsh edit centos-6.8-test
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/media/67cbdcec-6419-4571-9632-c605b3e2b910/data/centos6.test-x86_64.qcow2'/>

查看管理快照的命令有哪些

# virsh --help | grep snap
  iface-begin                    create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)
 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 or set the current snapshot
    snapshot-delete                Delete a domain snapshot
    snapshot-dumpxml               Dump XML for a domain snapshot
    snapshot-edit                  edit XML for a snapshot
    snapshot-info                  snapshot information
    snapshot-list                  List snapshots for a domain
    snapshot-parent                Get the name of the parent of a snapshot
    snapshot-revert                Revert a domain to a snapshot

创建快照

# virsh snapshot-create centos-6.8-test
# virsh snapshot-list centos-6.8-test
 名称               Creation Time             状态
------------------------------------------------------------
 1509359245           2017-10-30 18:27:25 +0800 shutoff
# 其中快照配置文件放到了/var/lib/libvirt/qemu/snapshot/

快照恢复

查看哪些快照需要恢复

# virsh  list --all
 Id    名称                         状态
----------------------------------------------------
 2     ubuntu-14.4-n1                 running
 14    ubuntu-14.4-113-pycharm        running
 16    ubuntu-14.4-n2                 running
 20    centos-6.8-grafana             running
 22    centos-6.8-data                running
 25    centos-6.8-test                running
 -     centos-6.8-n1                  关闭
 -     renjin-scripts                 关闭
 -     ubuntu-14.4-n3                 关闭
# virsh snapshot-list centos-6.8-test
 名称               Creation Time             状态
------------------------------------------------------------
 1509359245           2017-10-30 18:27:25 +0800 shutoff
 # virsh destroy centos-6.8-test
域 centos-6.8-test 被删除
# virsh  snapshot-revert centos-6.8-test 1509359245
# virsh snapshot-current centos-6.8-test
# virsh start centos-6.8-test
#至此,已经恢复完成

快照的删除

# virsh snapshot-list centos-6.8-test
 名称               Creation Time             状态
------------------------------------------------------------
 1509359245           2017-10-30 18:27:25 +0800 shutoff

# virsh snapshot-delete centos-6.8-test  1509359245

补充:在宿主机关机后,启动kvm遇以下问题:

# virsh start  centos-7.2-xxxxxxxx
错误:开始域 centos-7.2-xxxxxxx失败
错误:Unable to read from monitor: Connection reset by peer
# virsh managedsave-remove centos-6.8-grafana
# virsh start centos-7.2-xxxxxxxxx 
域 centos-7.2-xxxxxxxxx 已开始

评论