centos6.5虚拟机快照技术

一、查看现有磁盘镜像格式与转换

查看磁盘格式

[root@localhost ~]# qemu-img info /var/lib/libvirt/images/centos7.img 
image: /var/lib/libvirt/images/centos7.img
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 8.0G

 安装电源服务

# yum install acpid -y

关闭虚拟机

#virsh shutdown centos7

转换磁盘格式

# qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/centos7.img /var/lib/libvirt/images/centos7.qcow2

-f-------源镜像的格式

-O-----目标镜像的格式

查看转换后的磁盘大小

[root@localhost ~]# du -sh /var/lib/libvirt/images/centos7.qcow2 
1.4G    /var/lib/libvirt/images/centos7.qcow2

 

查看转换后的磁盘格式

[root@localhost ~]# qemu-img info /var/lib/libvirt/images/centos7.qcow2 
image: /var/lib/libvirt/images/centos7.qcow2
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 1.4G
cluster_size: 65536

 

二、修改虚拟机配置文件

修改磁盘格式

# virsh edit centos7

 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/var/lib/libvirt/images/centos7.qcow2'/>
      <target dev='hda' bus='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <disk type='block' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>

三、对虚拟机进行快照管理

创建centos7虚拟机快照

注意:需要修改磁盘格式

[root@localhost ~]# virsh snapshot-create-as centos7 centos7_snaphshot
Domain snapshot centos7_snaphshot created
[root@localhost ~]# 

 

查看虚拟机镜像快照的版本

# virsh snapshot-list centos7

查看当前虚拟机镜像快照的版本

可以看到为当前最新的快照版本

[root@localhost ~]# virsh snapshot-current centos7
<domainsnapshot>
  <name>centos7_snaphshot</name>
  <state>shutoff</state>
  <creationTime>1547653724</creationTime>
  <memory snapshot='no'/>
  <disks>
    <disk name='hda' snapshot='internal'/>
    <disk name='hdc' snapshot='no'/>
  </disks>
  <domain type='kvm'>
    <name>centos7</name>
    <uuid>92827f3a-d304-dc83-5ad1-d62f2a755ca3</uuid>
    <memory unit='KiB'>1048576</memory>
    <currentMemory unit='KiB'>1048576</currentMemory>
    <vcpu placement='static'>1</vcpu>
    <os>
      <type arch='x86_64' machine='rhel6.5.0'>hvm</type>
      <boot dev='hd'/>
    </os>
    <features>
      <acpi/>
      <apic/>
      <pae/>
    </features>
    <clock offset='utc'/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <devices>
      <emulator>/usr/libexec/qemu-kvm</emulator>
      <disk type='file' device='disk'>
        <driver name='qemu' type='qcow2' cache='none'/>
        <source file='/var/lib/libvirt/images/centos7.qcow2'/>
        <target dev='hda' bus='ide'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
      </disk>
      <disk type='block' device='cdrom'>
        <driver name='qemu' type='raw'/>
        <target dev='hdc' bus='ide'/>
        <readonly/>
        <address type='drive' controller='0' bus='1' target='0' unit='0'/>
      </disk>
      <controller type='ide' index='0'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
      </controller>
      <controller type='usb' index='0'/>
      <interface type='network'>
        <mac address='52:54:00:07:f7:16'/>
        <source network='default'/>
        <model type='virtio'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
      </interface>
      <serial type='pty'>
        <target port='0'/>
      </serial>
      <console type='pty'>
        <target type='serial' port='0'/>
      </console>
      <input type='mouse' bus='ps2'/>
      <graphics type='vnc' port='-1' autoport='yes' keymap='en-us'/>
      <sound model='ich6'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
      </sound>
      <video>
        <model type='cirrus' vram='9216' heads='1'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
      </video>
      <memballoon model='virtio'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
      </memballoon>
    </devices>
  </domain>
</domainsnapshot>

查看快照

# virsh snapshot-info centos7 centos7_snaphshot

四、恢复虚拟机快照

1、恢复虚拟机快照必须关闭虚拟机

查看虚拟机是否是关闭状态

# virsh domstate centos7

确认需要恢复的快照时间,恢复到centos7_snaphshot

# virsh snapshot-list centos7

3、执行恢复并确认恢复版本

# virsh snapshot-revert centos7 centos7_snaphshot

查看当前虚拟机镜像快照的版本

[root@localhost ~]# virsh snapshot-current centos7
<domainsnapshot>
  <name>centos7_snaphshot</name>
  <state>shutoff</state>
  <creationTime>1547653724</creationTime>
  <memory snapshot='no'/>
  <disks>
    <disk name='hda' snapshot='internal'/>
    <disk name='hdc' snapshot='no'/>
  </disks>
  <domain type='kvm'>
    <name>centos7</name>
    <uuid>92827f3a-d304-dc83-5ad1-d62f2a755ca3</uuid>
    <memory unit='KiB'>1048576</memory>
    <currentMemory unit='KiB'>1048576</currentMemory>
    <vcpu placement='static'>1</vcpu>
    <os>
      <type arch='x86_64' machine='rhel6.5.0'>hvm</type>
      <boot dev='hd'/>
    </os>

 

五、 删除虚拟机快照

1、查看虚拟机快照

# qemu-img info /var/lib/libvirt/images/centos7.qcow2 

2、删除快照

# virsh snapshot-delete centos7 centos7_snaphshot

# virsh snapshot-delete centos7 centos7_snaphshot

转载于:https://www.cnblogs.com/djlsunshine/p/10277694.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值