设为首页 收藏本站
查看: 1919|回复: 0

[经验分享] kvm虚拟机快照备份

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-2-15 14:38:06 | 显示全部楼层 |阅读模式
kvm虚拟机默认使用raw格式的镜像格式,性能最好,速度最快,它的缺点就是不支持一些新的功能,如支持镜像,zlib磁盘压缩,AES加密等。  要使用镜像功能,磁盘格式必须为qcow2。下面开始kvm虚拟机快照备份的过程1,查看现有磁盘镜像格式与转换
  (1)查看现有磁盘的格式
1
2
3
4
5
[iyunv@KVM test]# qemu-img info hadoop3.img
image: hadoop3.img
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 877M



把raw格式转换成qcow2格式
  (2)关闭需要转换磁盘的虚拟机
1
2
3
4
5
6
7
8
9
10
[iyunv@KVM test]# virsh destroy hadoop3
Domain hadoop3 destroyed
[iyunv@KVM test]# virsh list --all     
Id    Name                           State
----------------------------------------------------
1     win7                           running
6     hadoop2                        running
-     hadoop1                        shut off
-     hadoop3                        shut off
-     hadoop4                        shut off



  (3)转换磁盘的格式
1
[iyunv@KVM test]# qemu-img convert -f raw -O qcow2 hadoop3.img hadoop3.qcow2



-f 源镜像的格式
-o 目标镜像的格式
查看转换后的格式,已经转换成了qcow2, 这里是拷贝一份,并将格式转成qcow2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@KVM test]# qemu-img convert -f raw -O qcow2 hadoop3.img hadoop3.qcow2
[iyunv@KVM test]# ll
total 14975352
-rwxr-xr-x 1 root root 10737418240 Feb  4 14:38 hadoop1.img
-rwxr-xr-x 1 qemu qemu 10737418240 Feb  4 16:51 hadoop2.img
-rwxr-xr-x 1 root root 10737418240 Feb  4 16:48 hadoop3.img
-rw-r--r-- 1 root root   923926528 Feb  4 16:51 hadoop3.qcow2
-rwxr-xr-x 1 root root 10737418240 Feb  4 15:11 hadoop4.img
-rwxr-xr-x 1 qemu qemu  8589934592 Feb  2 15:03 win7.img
[iyunv@KVM test]# qemu-img info hadoop3.qcow2
image: hadoop3.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 881M
cluster_size: 65536



2,修改虚拟机配置文件

1
[iyunv@KVM qemu]# virsh edit hadoop3




<domain type='qemu'>
  <name>hadoop3</name>
  <uuid>586b3cae-943f-e283-d8e7-ed72b01bfa34</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='/images/test/hadoop3.qcow2'/>
      <target dev='hda' bus='ide'/>
QQ截图20160215143745.png
3,对虚拟机进行快照管理
(1)对hadoop3虚拟机创建快照

1
2
[iyunv@KVM qemu]# virsh snapshot-create hadoop3
Domain snapshot 1454577228 created



(2)查看虚拟机快照的版本
1
2
3
4
[iyunv@KVM qemu]# virsh snapshot-list hadoop3  
Name                 Creation Time             State
------------------------------------------------------------
1454577228           2016-02-04 17:13:48 +0800 shutoff



(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
[iyunv@KVM qemu]# virsh snapshot-current hadoop3
<domainsnapshot>
  <name>1454577442</name>
  <state>shutoff</state>
  <parent>
    <name>1454577228</name>
  </parent>
  <creationTime>1454577442</creationTime>
  <memory snapshot='no'/>
  <disks>
    <disk name='hda' snapshot='internal'/>
    <disk name='hdc' snapshot='no'/>
  </disks>
  <domain type='qemu'>
    <name>hadoop3</name>
    <uuid>586b3cae-943f-e283-d8e7-ed72b01bfa34</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='/images/test/hadoop3.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='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='network'>
        <mac address='52:54:00:fe:f5:a3'/>
        <source network='default'/>
        <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='5913' 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='0x05' function='0x0'/>
      </memballoon>
    </devices>
  </domain>
</domainsnapshot>



(4)查看当前虚拟机镜像文件,快照文件的路径在/var/lib/libvirt/qemu/snapshot/ 下
1
2
3
4
[iyunv@KVM qemu]# ll /var/lib/libvirt/qemu/snapshot/hadoop3/
total 8
-rw------- 1 root root 3402 Feb  4 17:17 1454577228.xml
-rw------- 1 root root 3453 Feb  4 17:17 1454577442.xml




4,恢复虚拟机快照
(1)恢复虚拟机快照必须关闭虚拟机
1
2
3
4
5
6
7
8
[iyunv@KVM qemu]# virsh list --all
Id    Name                           State
----------------------------------------------------
1     win7                           running
6     hadoop2                        running
-     hadoop1                        shut off
-     hadoop3                        shut off
-     hadoop4                        shut off



(2)确认恢复快照的时间,这里是恢复到1454577442
1
2
3
4
5
[iyunv@KVM qemu]# virsh snapshot-list hadoop3      
Name                 Creation Time             State
------------------------------------------------------------
1454577228           2016-02-04 17:13:48 +0800 shutoff
1454577442           2016-02-04 17:17:22 +0800 shutoff



(3)执行恢复,并确认恢复版本
1
2
[iyunv@KVM qemu]# virsh snapshot-revert hadoop3 1454577442
[iyunv@KVM qemu]# virsh snapshot-current hadoop3



QQ截图20160215143758.png
5,删除虚拟机快照
(1)查看虚拟机快照
1
2
3
4
5
6
7
8
9
10
[iyunv@KVM test]# qemu-img info hadoop3.qcow2
image: hadoop3.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 881M
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         1454577228                0 2016-02-04 17:13:48   00:00:00.000
2         1454577442                0 2016-02-04 17:17:22   00:00:00.000



(2)删除快照
1
2
3
4
5
6
7
8
9
10
11
[iyunv@KVM test]# virsh snapshot-delete hadoop3 1454577228
Domain snapshot 1454577228 deleted
[iyunv@KVM test]# qemu-img info hadoop3.qcow2            
image: hadoop3.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 881M
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
2         1454577442                0 2016-02-04 17:17:22   00:00:00.000




至此虚拟机快照从创建,查看,删除。如果有报错,再一一的进行拍错。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-178328-1-1.html 上篇帖子: kvm虚拟机时间配置 下篇帖子: kvm虚拟机扩充磁盘空间 虚拟机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表