kvm虚拟机快照备份

摘要:
kvm虚拟机默认使用原始图像格式,该格式具有最佳性能和最快速度。它的缺点是不支持一些新功能,例如映像、zlib磁盘压缩、AES加密等。接下来,启动kvm虚拟机快照备份的过程。查看虚拟机映像快照的版本查看当前虚拟机映像snapshot的版本。您可以看到它是最新的快照版本。

kvm虚拟机默认使用raw格式的镜像格式,性能最好,速度最快,它的缺点就是不支持一些新的功能,如支持镜像,zlib磁盘压缩,AES加密等。   
要使用镜像功能,磁盘格式必须为qcow2。下面开始kvm虚拟机快照备份的过程。

本文出自:http://koumm.blog.51cto.com

进一步的学习参考:kvm+libvirt虚拟机快照浅析 http://itxx.sinaapp.com/blog/content/130

1.  查看现有磁盘镜像格式与转换

(1) 查看磁盘格式

# qemu-img info test01.img

raw格式需要转换成qcow2

image

(2) 关闭虚拟机并转换磁盘

# virsh shutdown oeltest01

image

(3) 转换磁盘格式

# qemu-img convert -f raw -O qcow2 test01.img test01.qcow2 

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

image

查看转换后的格式,已经转换成了qcow2, 这里是拷贝一份,并将格式转成qcow2

# qemu-img info test01.qcow2

image

2. 修改虚拟机配置文件

修改磁盘格式,与新qcow2格式的磁盘。

image

3. 对虚拟机进行快照管理 

(1) 对oeltest01虚拟机创建快照

也可以virsh snapshot-create as oeltest01 snap1 创建后个快照别名。

image

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

image

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

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

[root@node1 data]#    
[root@node1 data]# virsh snapshot-current oeltest01    
<domainsnapshot>    
  <name>1378579737</name>    
  <state>shutoff</state>    
  <creationTime>1378579737</creationTime>    
  <memory snapshot='no'/>    
  <disks>    
    <disk name='hda' snapshot='internal'/>    
    <disk name='hdc' snapshot='no'/>    
  </disks>    
  <domain type='kvm'>    
    <name>oeltest01</name>    
    <uuid>8f2bb4a7-c7ed-32aa-3676-9fb05923269d</uuid>    
    <memory unit='KiB'>524288</memory>    
    <currentMemory unit='KiB'>524288</currentMemory>    
    <vcpu placement='static'>1</vcpu>    
    <os>    
      <type arch='x86_64' machine='rhel6.4.0'>hvm</type>    
      <boot dev='hd'/>    
    </os>    
    <features>    
      <acpi/>    
      <apic/>    
      <pae/>    
    </features>    
    <clock offset='localtime'/>    
    <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='/data/test01.qcow2'/>    
        <target dev='hda' bus='ide'/>    
        <address type='drive' controller='0' bus='0' target='0' unit='0'/>    
      </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='bridge'>    
        <mac address='52:54:00:82:39:01'/>    
        <source bridge='br0'/>    
        <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='tablet' bus='usb'/>    
      <input type='mouse' bus='ps2'/>    
      <graphics type='vnc' port='5910' autoport='no' listen='0.0.0.0'>    
        <listen type='address' address='0.0.0.0'/>    
      </graphics>    
      <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='0x04' function='0x0'/>    
      </memballoon>    
    </devices>    
  </domain>    
</domainsnapshot> 

[root@node1 data]# 

(4) 查看当前虚拟机镜像文件

又创建了一个,快照的版本也记录在镜像文件中了。

image

快照配置文件在/var/lib/libvirt/qemu/snapshot/虚拟机名称/下

image

4. 恢复虚拟机快照

(1) 恢复虚拟机快照必须关闭虚拟机。

image

确认虚拟机是关机状态

image

(2) 确认需要恢复的快照时间,这里恢复到1378579737

image

(3) 执行恢复,并确认恢复版本

# virsh snapshot-revert oeltest01 1378579737 

image

5. 删除虚拟机快照

(1) 查看虚拟机快照

# qemu-img info test01.qcow2

image

这里删除第一个快照1378579737

(2) 删除快照

image

到此kvm虚拟机快照测试完毕。kvm虚拟化学习笔记进行到这里了,感觉到kvm虚拟化的内容真的很多。水是越来越深了。

免责声明:文章转载自《kvm虚拟机快照备份》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇django的优缺点(非原创)解决安卓手机连接wifi总弹出“已登录到Wlan网络”下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Docker容器数据卷[4]

 是什么 先来看看Docker的理念: 将运用与运行的环境打包形成容器运行,运行可以伴随着容器,但是我们对数据的要求希望是持久化的 容器之间希望有可能共享数据 Docker容器产生的数据,如果不通过docker commit生成新的镜像,使得数据做为镜像的一部分保存下来, 那么当容器删除后,数据自然也就没有了。 为了能保存数据在docker中我们使用卷...

java基础-构建命令行运行的java程序简要注意

 今天编写了一个运行在服务端的java工具类,才发现自己以前很少关注运营方面的内容,导致在服务端部署一个java的工具变得异常困难,其实这也是自己对java的了解不够造成的。   首先,当代码编写完成之后,在主类中必须要有main函数,其中的参数非常重要。根据一位同事的说法,除正常的执行程序之外,其中至少要包含两种参数:-v(软件版本,以及作者等介绍信息...

coreos安装

cloud-config-bootstrap.sh #!/bin/bash cat > "cloud-config.yaml" <<EOF #cloud-config ssh_authorized_keys: - ssh-rsa ... EOF sudo coreos-install -d /dev/vd...

HP(惠普)服务器 修复 Intelligent Provisioning(摘录)

摘录自:https://www.xxshell.com/1219.html 我们在给惠普服务器安装操作系统和配置RAID最常用的就是通过F10(Intelligent Provisioning)进行,本身Intelligent Provisioning就是服务器上的一个软件,我们可以通过Intelligent Provisioning对服务器进行图形化自动...

Mac-VM迁移注意事项

1.迁移之后首先查看mac的网关是多少: 先cd /Library/Preferences/VMware Fusion/vmnet8 然后 cat nat.conf ip 172.16.190.2就是我的网关,你的和我的应该不一致 2.配置虚拟机中的网络 点击系统-首选项-网络连接。 配置你的网卡,我的是eth1. 地址就是你的这台虚拟机ip,网关和dn...

webpack使用的心得

1 . 我们需要使用打包工具,首先第一步就得 执行 npm install进行安装,可是很多时候 加载速度很慢,这个时候我们可以 用淘宝镜像源,参考地址: https://npm.taobao.org/ 使用方法如下: npm install --registry=https://registry.npm.taobao.org 全局配置镜像源: 淘宝镜像:...