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 虚拟化
在Hyper-V虚拟化的图形处理中,怎么调整虚拟机的屏幕分辨率?
在Hyper-V虚拟化中,调整虚拟机屏幕分辨率对提升用户体验和确保应用程序兼容性至关重要。高分辨率可提供清晰图像、提高工作效率,并避免显示异常。调整方法包括通过增强会话模式、虚拟机内部设置或手动编辑配置文件。注意事项包括正确安装显卡驱动、避免过高分辨率及及时保存设置。
|
2月前
|
存储 运维 数据挖掘
虚拟化数据恢复—误还原快照导致虚拟机上数据库丢失的数据恢复案例
虚拟化数据恢复环境&故障: vmfs文件系统,存储的数据是SqlServer数据库及其他办公文件。 工作人员误将快照还原,导致了SqlServer数据库数据的丢失,需要恢复原来的SqlServer数据库文件。
96 22
|
5月前
|
存储 SQL 数据库
虚拟化数据恢复—Vmware虚拟机误还原快照的数据恢复案例
虚拟化数据恢复环境: 一台虚拟机从物理机迁移到ESXI虚拟化平台,迁移完成后做了一个快照。虚拟机上运行了一个SQL Server数据库,记录了数年的数据。 ESXI虚拟化平台上有数十台虚拟机,EXSI虚拟化平台连接了一台EVA存储,所有的虚拟机都存放在EVA存储上。 虚拟化故障: 工组人员误操作将数年前迁移完成后做的快照还原了,也就意味着虚拟机状态还原到数年前,近几年数据都被删除了。 还原快照相当于删除数据,意味着部分存储空间会被释放。为了不让这部分释放的空间被重用,需要将连接到这台存储的所有虚拟机都关掉,需要将不能长时间宕机的虚拟机迁移到别的EXSI虚拟化平台上。
193 50
|
4月前
|
存储 数据挖掘 数据库
虚拟化数据恢复—VMFS简介&误删除虚拟机的数据恢复案例
物理区:物理上连续的磁盘空间,即通常意义上的分区。 本地区:VMFS管理的物理区分为保留区和本地区,前面一部分是保留区,后面部分是本地区。本地区又分为元文件区和数据区。 元文件:与NTFS的元文件类似,属于FS的管理用数据。VMFS有6个元文件:.VH.SF/.FBB.SF/.FDC.SF/.SBC.SF/.PBC.SF/.PB2.SF。 元文件区:6个元文件占用的所有空间,在本地区的前面部分。 数据区:用于存放文件数据。 datastore:在ESX服务器上看到的VMFS存储空间。 LV:logical volume,所指的范围其实和本地区一样,即虚拟化卷。 LVM逻辑卷组:用来管理跨dis
|
1月前
|
缓存 Linux 调度
【YashanDB数据库】VMware虚拟机使用默认安装,在掉电之后数据库无法启动
VMware虚拟机使用默认安装,在掉电之后数据库无法启动
|
1月前
|
IDE 测试技术 数据库
【YashanDB知识库】使用vmware虚拟机安装的YashanDB,本机无法访问
在 VMware 虚拟机中安装并测试 YashanDB,数据库及虚拟机运行正常,但本地 IDE 工具无法连接虚拟机中的数据库。问题可能与 VMware 网络适配器配置或网络模式(如 NAT、桥接)有关,导致网络通信异常。需检查虚拟机网络设置、IP 地址配置以及防火墙规则,确保本地与虚拟机间网络连通性。目前无明确修复版本。
|
4天前
|
Linux 虚拟化 iOS开发
Windows Server 2008 R2 OVF (2025 年 4 月更新) - VMware 虚拟机模板
Windows Server 2008 R2 OVF (2025 年 4 月更新) - VMware 虚拟机模板
56 29
Windows Server 2008 R2 OVF (2025 年 4 月更新) - VMware 虚拟机模板
|
24天前
|
安全 Linux 虚拟化
VMware Tools 12.5.1 下载 - 虚拟机必备组件 (驱动和交互式服务)
虚拟机必备组件 (驱动和交互式服务)
104 13
VMware Tools 12.5.1 下载 - 虚拟机必备组件 (驱动和交互式服务)
|
29天前
|
存储 API 虚拟化
VMware vSphere Replication 9.0.2.2 发布 - 虚拟机复制和数据保护
VMware vSphere Replication 9.0.2.2 发布 - 虚拟机复制和数据保护
45 2
VMware vSphere Replication 9.0.2.2 发布 - 虚拟机复制和数据保护
|
17天前
|
API 虚拟化
撤了!6天搬走500台VMware虚拟机
VMware到期在即,这个方案紧急时刻力挽狂澜,帮他们高效完成业务迁移。