kvm虚拟化学习笔记(十)之kvm虚拟机快照备份

简介:

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

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

(1) 查看磁盘格式

# qemu-img info CentOS6.5-01.img

raw格式需要转换成qcow2

a2a2c732c3afdb4ceab9f5ee84ede195.png-wh_

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

# virsh shutdown CentOS6.5-01

08e89169163ec79311a2d5b2fd8e2eea.png-wh_

(3) 转换磁盘格式

# qemu-img convert -f raw -O qcow2 CentOS6.5-01.img CentOS6.5-01.qcow2 

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

601d1574ea9049f115e0a61fb2cfd413.png-wh_

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

# qemu-img info CentOS6.5-01.qcow2

1f59521f64ac1708c69e2bf6d1d04e34.png-wh_

2. 修改虚拟机配置文件

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

dd11282dc85802cb8efb41d5f3d71122.png-wh_

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

(1) 对CentOS6.5-01虚拟机创建快照

# virsh snapshot-create CentOS6.5-01 

也可以virsh snapshot-create as CentOS6.5-01 snap1 创建后个快照别名。

4ff3bd3f3b5b41c45faab15946013752.png-wh_


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

# virsh snapshot-list CentOS6.5-01

67ad803a5122fdb3b53f813f4c9e2f85.png-wh_



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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
[root@node1 kvm] # virsh snapshot-current CentOS6.5-01
<domainsnapshot>
   <name>1511337772< /name >
   <state>shutoff< /state >
   <creationTime>1511337772< /creationTime >
   <memory snapshot= 'no' />
   <disks>
     <disk name= 'vda'  snapshot= 'internal' />
     <disk name= 'hdc'  snapshot= 'no' />
   < /disks >
   <domain  type = 'kvm' >
     <name>CentOS6.5-01< /name >
     <uuid>7d48f7b5-2fbf-91a9-2c3f-e52ba6079c8e< /uuid >
     <memory unit= 'KiB' >1048576< /memory >
     <currentMemory unit= 'KiB' >1048576< /currentMemory >
     <vcpu placement= 'static' >1< /vcpu >
     <os>
       < type  arch= 'x86_64'  machine= 'rhel6.6.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/kvm/CentOS6.5-01.qcow2' />
         <target dev= 'vda'  bus= 'virtio' />
         <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 = 'usb'  index= '0'  model= 'ich9-ehci1' >
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x7' />
       < /controller >
       <controller  type = 'usb'  index= '0'  model= 'ich9-uhci1' >
         <master startport= '0' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x0'  multifunction= 'on' />
       < /controller >
       <controller  type = 'usb'  index= '0'  model= 'ich9-uhci2' >
         <master startport= '2' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x1' />
       < /controller >
       <controller  type = 'usb'  index= '0'  model= 'ich9-uhci3' >
         <master startport= '4' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x2' />
       < /controller >
       <controller  type = 'ide'  index= '0' >
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x01'  function = '0x1' />
       < /controller >
       <interface  type = 'bridge' >
         <mac address= '52:54:00:56:9a:7f' />
         < 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 = '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= '0x06'  function = '0x0' />
       < /memballoon >
     < /devices >
   < /domain >
< /domainsnapshot >
 
[root@node1 kvm] #

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

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

f21888feb500745ed7b4a2c4fab58166.png-wh_


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

8eebc489bc345e7a8de1daa1f2e5a07b.png-wh_


4. 恢复虚拟机快照

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

f41ff38a6a9b18b5c1a716ca96fe15ce.png-wh_

确认虚拟机是关机状态

d576f5fec37fedad0b2603a4d849d1e6.png-wh_


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

ac6044ce2502cc97f68d98df71b9b06e.png-wh_


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

# virsh snapshot-revert CentOS6.5-01 1511337772

# virsh snapshot-current CentOS6.5-01

4d21adf8852584d9d8fbf1e5fe132450.png-wh_

5. 删除虚拟机快照

(1) 查看虚拟机快照

# qemu-img info CentOS6.5-01.qcow2

fa6cd424dc8ef0febde5618123433983.png-wh_

这里删除第一个快照1511337772

(2) 删除快照

e00c128ac3a4a457448b77efa88d7fe0.png-wh_

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


本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/1984114,如需转载请自行联系原作者

相关文章
|
1天前
|
Linux KVM 数据库
虚拟机数据恢复—误删除KVM虚拟机的数据恢复案例
虚拟化数据恢复环境&故障: KVM是Kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux2.6.20版本之后集成在Linux的各个主要发行版本中。KVM使用Linux自身的调度器进行管理。 本案例中的服务器操作系统为Linux,文件系统为EXT4。操作系统上的部署的几台KVM虚拟机被删除,每台KVM虚拟机包含一个qcow2格式的磁盘文件和一个raw格式的磁盘文件,用户需要恢复的数据是raw格式的磁盘文件。这几台被误删除的虚拟机存放的是数据库,程序代码等数据。
|
1月前
|
存储 KVM 虚拟化
倚天产品介绍|倚天虚拟化:虚拟机热迁移特性介绍
热迁移分为热迁移和冷迁移,冷迁移过程中有一段明显的时间VM的服务不可用,而热迁移的服务的服务暂停时间非常短。热迁移过程中无需关闭或者长时间暂停VM,VM保持正常运行,只有在热迁移临近结束时有一个非常短暂的停机切换时间。热迁移可保证了VM服务的可用性,提升业务的连续性和用户体验。
|
2月前
|
存储 虚拟化 索引
虚拟机数据恢复-虚拟机还原快照原理和误还原快照的数据恢复方案
由一台物理服务器迁移到ESXI上的虚拟机,虚拟机迁移完成后做了一个快照,该ESXI上面一共运行了数十台虚拟机。某天工作人员不小心将快照进行了还原,虚拟机内的数据还原到了数年前刚迁移过来时的状态,迁移过来后的这几年更新的数据全部被删除。
虚拟机数据恢复-虚拟机还原快照原理和误还原快照的数据恢复方案
|
6月前
|
监控 数据挖掘 虚拟化
VMWare 虚拟机 CPU 设置里针对 CPU 的 虚拟化 CPU 性能计数器(U) 选项功能介绍
VMWare 虚拟机 CPU 设置里针对 CPU 的 虚拟化 CPU 性能计数器(U) 选项功能介绍
519 0
|
6月前
|
安全 虚拟化
VMWare 虚拟机 CPU 设置里针对 CPU 的虚拟化 IOMMU(IO 内存管理单元) 选项功能介绍
VMWare 虚拟机 CPU 设置里针对 CPU 的虚拟化 IOMMU(IO 内存管理单元) 选项功能介绍
367 0
|
3月前
|
虚拟化
VMware使用 - 虚拟机快照
VMware使用 - 虚拟机快照
31 0
|
4月前
|
机器学习/深度学习 Ubuntu Linux
如何在Ubuntu 23.10部署KVM并创建虚拟机?
如何在Ubuntu 23.10部署KVM并创建虚拟机?
69 0
|
5月前
|
运维 数据挖掘 数据库
服务器数据恢复—虚拟机误还原快照的数据恢复案例
服务器数据恢复环境: vmfs文件系统,存放的是SqlServer数据库及其他办公文件。 服务器故障: 工作人员误操作还原快照,导致了SqlServer数据库数据丢失。
|
7月前
|
存储 KVM 虚拟化
倚天虚拟化:虚拟机热迁移特性介绍
热迁移分为热迁移和冷迁移,冷迁移过程中有一段明显的时间VM的服务不可用,而热迁移的服务的服务暂停时间非常短。热迁移过程中无需关闭或者长时间暂停VM,VM保持正常运行,只有在热迁移临近结束时有一个非常短暂的停机切换时间。热迁移可保证了VM服务的可用性,提升业务的连续性和用户体验。
|
8月前
|
虚拟化
虚拟化——成功解决ovirt修改ifcfg-ovirtmgmt的ip之后,重启虚拟机没有效果的问题
虚拟化——成功解决ovirt修改ifcfg-ovirtmgmt的ip之后,重启虚拟机没有效果的问题

热门文章

最新文章