目录

方式一

思路:以 QCOW2 格式来备份和恢复被保护的 KVM 虚拟机

  • Step1:centos7_0(base qcow2) 以 qcow2 格式写入到 iSCSI 设备
  1. root@h3cas-e306:/vms/images# virsh list --all
  2. Id Name State
  3. ----------------------------------------------------
  4. 33 centos7 running
  5. root@h3cas-e306:/vms/images# virsh domblklist centos7
  6. Target Source
  7. ------------------------------------------------
  8. vda /vms/images/centos7_0
  9. hda /vms/isos/CentOS-7-x86_64-Minimal-1511.iso
  10. root@h3cas-e306:/vms/images# qemu-img convert -f qcow2 /vms/images/centos7_0 -O qcow2 /dev/sdd
  11. root@h3cas-e306:/vms/images# qemu-img info /dev/sdd
  12. image: /dev/sdd
  13. file format: qcow2
  14. virtual size: 20G (21474836480 bytes)
  15. disk size: 0
  16. cluster_size: 262144
  17. Format specific information:
  18. compat: 1.1
  19. lazy refcounts: false
  • Step2:尝试使用 iSCSI 设备手动启动 KVM 虚拟机
  1. # 创建 XML 文件
  2. root@h3cas-e306:/etc/libvirt/qemu# vim centos7_q_0.xml
  3. <domain type='kvm'>
  4. <name>centos7_q_0</name>
  5. <uuid>d668e699-22a4-464b-99c4-1ffdcd6ad4e1</uuid>
  6. <osha>0</osha>
  7. <timesync>0</timesync>
  8. <automem>0</automem>
  9. <memory unit='KiB'>4194304</memory>
  10. <currentMemory unit='KiB'>4194304</currentMemory>
  11. <memorySlots>10</memorySlots>
  12. <maxMemory unit='KiB'>34359738368</maxMemory>
  13. <blkiotune>
  14. <weight>300</weight>
  15. </blkiotune>
  16. <memtune>
  17. <priority>1</priority>
  18. </memtune>
  19. <memoryBacking>
  20. <locked>0</locked>
  21. </memoryBacking>
  22. <vcpu placement='static' current='2'>24</vcpu>
  23. <cputune>
  24. <shares>512</shares>
  25. <period>1000000</period>
  26. <quota>-1</quota>
  27. </cputune>
  28. <os>
  29. <type arch='x86_64' machine='pc-i440fx-2.1'>hvm</type>
  30. <system>linux</system>
  31. <boot dev='hd'/>
  32. <boot dev='cdrom'/>
  33. </os>
  34. <features>
  35. <acpi/>
  36. <apic/>
  37. <pae/>
  38. </features>
  39. <cpu>
  40. <topology sockets='24' cores='1' threads='1'/>
  41. <numa>
  42. <cell cpus='0-1' memory='4194304'/>
  43. </numa>
  44. <gurantee unit='MHz'>0</gurantee>
  45. </cpu>
  46. <clock offset='utc'/>
  47. <on_poweroff>destroy</on_poweroff>
  48. <on_reboot>restart</on_reboot>
  49. <on_crash>restart</on_crash>
  50. <pm>
  51. <suspend-to-mem enabled='no'/>
  52. <suspend-to-disk enabled='no'/>
  53. </pm>
  54. <tools upgrade='auto'/>
  55. <devices>
  56. <emulator>/usr/bin/kvm</emulator>
  57. <disk type='file' device='disk'>
  58. <driver name='qemu' type='qcow2' cache='directsync' io='native'/>
  59. <source file='/dev/sdd'/>
  60. <target dev='vda' bus='virtio'/>
  61. <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
  62. </disk>
  63. <disk type='file' device='cdrom'>
  64. <driver name='qemu' type='raw' cache='none'/>
  65. <target dev='hdc' bus='ide'/>
  66. <readonly/>
  67. <address type='drive' controller='0' bus='1' target='0' unit='0'/>
  68. </disk>
  69. <controller type='usb' index='0'>
  70. <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
  71. </controller>
  72. <controller type='pci' index='0' model='pci-root'/>
  73. <controller type='ide' index='0'>
  74. <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
  75. </controller>
  76. <controller type='virtio-serial' index='0'>
  77. <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
  78. </controller>
  79. <serial type='pty'>
  80. <target port='0'/>
  81. </serial>
  82. <console type='pty'>
  83. <target type='serial' port='0'/>
  84. </console>
  85. <channel type='unix'>
  86. <source mode='bind' path='/var/lib/libvirt/qemu/centos7.agent'/>
  87. <target type='virtio' name='org.qemu.guest_agent.0'/>
  88. <address type='virtio-serial' controller='0' bus='0' port='1'/>
  89. </channel>
  90. <input type='tablet' bus='usb'/>
  91. <input type='mouse' bus='ps2'/>
  92. <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
  93. <listen type='address' address='0.0.0.0'/>
  94. </graphics>
  95. <video>
  96. <model type='cirrus' vram='9216' heads='1'/>
  97. <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
  98. </video>
  99. <memballoon model='virtio'>
  100. <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
  101. </memballoon>
  102. </devices>
  103. root@h3cas-e306:/etc/libvirt/qemu# virsh define centos7_q_0.xml
  104. Domain centos7_q_0 defined from centos7_q_0.xml
  105. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  106. Id Name State
  107. ----------------------------------------------------
  108. 33 centos7 running
  109. - centos7_q_0 shut off
  110. root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_q_0
  111. Domain centos7_q_0 started
  112. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  113. Id Name State
  114. ----------------------------------------------------
  115. 33 centos7 running
  116. 34 centos7_q_0 running
  • Step3:对 centos7_0 做快照得到增量快照数据 centos7_1(increment qcow2)
  1. root@h3cas-e306:/vms/images# virsh snapshot-create-as --domain centos7 snap01 snap01-desc --disk-only --diskspec vda,snapshot=external,file=/vms/images/centos7_1 --atomic
  2. Domain snapshot snap01 created
  3. root@h3cas-e306:/vms/images# l
  4. centos7_0 centos7_1
  5. root@h3cas-e306:/vms/images# qemu-img info centos7_1
  6. image: centos7_1
  7. file format: qcow2
  8. virtual size: 20G (21474836480 bytes)
  9. disk size: 772K
  10. cluster_size: 262144
  11. backing file: /vms/images/centos7_0
  12. backing file format: qcow2
  13. Format specific information:
  14. compat: 1.1
  15. lazy refcounts: false
  16. root@h3cas-e306:/vms/images# virsh domblklist centos7
  17. Target Source
  18. ------------------------------------------------
  19. vda /vms/images/centos7_1
  20. hda /vms/isos/CentOS-7-x86_64-Minimal-1511.iso

NOTE: 现在虚拟机的数据会写入到 centos7_1 中, centos7_0 理论上应该是只读的.

  • Step4:Copy centos7_1 的副本到备份目录下
  1. root@h3cas-e306:/vms/images# cp centos7_1 /kvm_backup/
  2. root@h3cas-e306:/vms/images# ll /kvm_backup/
  3. total 2572
  4. drwxr-xr-x 2 root root 4096 Apr 18 23:39 ./
  5. drwxr-xr-x 33 root root 4096 Apr 18 23:22 ../
  6. -rw------- 1 root root 2883584 Apr 18 23:39 centos7_1
  • Step5:rebase 并 commit centos7_1 到 iSCSI 设备中
  1. root@h3cas-e306:/etc/libvirt/qemu# virsh destroy 34
  2. Domain 34 destroyed
  3. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  4. Id Name State
  5. ----------------------------------------------------
  6. 33 centos7 running
  7. - centos7_q_0 shut off
  8. root@h3cas-e306:/vms/images# cd /kvm_backup/
  9. root@h3cas-e306:/kvm_backup# ls
  10. centos7_1
  11. root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
  12. image: centos7_1
  13. file format: qcow2
  14. virtual size: 20G (21474836480 bytes)
  15. disk size: 2.5M
  16. cluster_size: 262144
  17. backing file: /vms/images/centos7_0
  18. backing file format: qcow2
  19. Format specific information:
  20. compat: 1.1
  21. lazy refcounts: false
  22. root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
  23. image: /dev/sdd
  24. file format: qcow2
  25. virtual size: 20G (21474836480 bytes)
  26. disk size: 0
  27. cluster_size: 262144
  28. Format specific information:
  29. compat: 1.1
  30. lazy refcounts: false
  31. root@h3cas-e306:/kvm_backup# qemu-img rebase -b /dev/sdd -F qcow2 centos7_1
  32. root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
  33. image: centos7_1
  34. file format: qcow2
  35. virtual size: 20G (21474836480 bytes)
  36. disk size: 15M
  37. cluster_size: 262144
  38. backing file: /dev/sdd
  39. backing file format: qcow2
  40. Format specific information:
  41. compat: 1.1
  42. lazy refcounts: false
  43. root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
  44. image: /dev/sdd
  45. file format: qcow2
  46. virtual size: 20G (21474836480 bytes)
  47. disk size: 0
  48. cluster_size: 262144
  49. Format specific information:
  50. compat: 1.1
  51. lazy refcounts: false
  52. root@h3cas-e306:/kvm_backup# qemu-img commit -f qcow2 centos7_1
  53. Image committed.
  54. root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
  55. image: centos7_1
  56. file format: qcow2
  57. virtual size: 20G (21474836480 bytes)
  58. disk size: 15M
  59. cluster_size: 262144
  60. backing file: /dev/sdd
  61. backing file format: qcow2
  62. Format specific information:
  63. compat: 1.1
  64. lazy refcounts: false
  65. root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
  66. image: /dev/sdd
  67. file format: qcow2
  68. virtual size: 20G (21474836480 bytes)
  69. disk size: 0
  70. cluster_size: 262144
  71. Format specific information:
  72. compat: 1.1
  73. lazy refcounts: false
  • Step6:使用 commit 后的 iSCSI 设备启动虚拟机
  1. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  2. Id Name State
  3. ----------------------------------------------------
  4. 33 centos7 running
  5. - centos7_q_0 shut off
  6. root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_q_0
  7. Domain centos7_q_0 started
  8. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  9. Id Name State
  10. ----------------------------------------------------
  11. 33 centos7 running
  12. 35 centos7_q_0 running

NOTE: 虚拟机启动成功, 证明 QCOW2 格式的虚拟机增量快照文件是能够合并到虚拟机 Base 数据文件中的。

方式二

思路:以 RAW 格式来备份和恢复被保护的 KVM 虚拟机

  • Step1:centos7(base qcow2) 以 raw 格式写入到 iSCSI 设备
  1. root@h3cas-e306:/vms/images# qemu-img info centos7
  2. image: centos7
  3. file format: qcow2
  4. virtual size: 20G (21474836480 bytes)
  5. disk size: 1.0G
  6. cluster_size: 262144
  7. Format specific information:
  8. compat: 1.1
  9. lazy refcounts: false
  10. root@h3cas-e306:/vms/images# qemu-img convert -f qcow2 /vms/images/centos7 -O raw /dev/sdd
  11. root@h3cas-e306:/vms/images# qemu-img info /dev/sdd
  12. image: /dev/sdd
  13. file format: raw
  14. virtual size: 23G (24696061952 bytes)
  15. disk size: 0
  • Step2:使用 iSCSI 设备手动启动 KVM 虚拟机
  1. root@h3cas-e306:/etc/libvirt/qemu# virsh define centos7_r_0.xml
  2. Domain centos7_r_0 defined from centos7_r_0.xml
  3. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  4. Id Name State
  5. ----------------------------------------------------
  6. 36 centos7 running
  7. - centos7_q_0 shut off
  8. - centos7_r_0 shut off
  9. root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_r_0
  10. Domain centos7_r_0 started
  11. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  12. Id Name State
  13. ----------------------------------------------------
  14. 36 centos7 running
  15. 37 centos7_r_0 running
  16. - centos7_q_0 shut off
  • Step3:对 centos7 做快照得到增量快照数据 centos7_1(increment qcow2)
  1. root@h3cas-e306:/vms/images# virsh snapshot-create-as --domain centos7 snap01 snap01-desc --disk-only --diskspec vda,snapshot=external,file=/vms/images/centos7_1 --atomic
  2. Domain snapshot snap01 created
  3. root@h3cas-e306:/vms/images# ls
  4. centos7 centos7_1
  5. root@h3cas-e306:/vms/images# qemu-img info centos7_1
  6. image: centos7_1
  7. file format: qcow2
  8. virtual size: 20G (21474836480 bytes)
  9. disk size: 2.0M
  10. cluster_size: 262144
  11. backing file: /vms/images/centos7
  12. backing file format: qcow2
  13. Format specific information:
  14. compat: 1.1
  15. lazy refcounts: false
  • Step4: Copy centos7_1 的副本到备份目录下
  1. root@h3cas-e306:/vms/images# cp centos7_1 /kvm_backup/
  2. root@h3cas-e306:/vms/images# cd /kvm_backup/
  3. root@h3cas-e306:/kvm_backup# ls
  4. centos7_1
  5. root@h3cas-e306:/kvm_backup# qemu-img info /kvm_backup/centos7_1
  6. image: /kvm_backup/centos7_1
  7. file format: qcow2
  8. virtual size: 20G (21474836480 bytes)
  9. disk size: 2.5M
  10. cluster_size: 262144
  11. backing file: /vms/images/centos7
  12. backing file format: qcow2
  13. Format specific information:
  14. compat: 1.1
  15. lazy refcounts: false
  16. root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
  17. image: /dev/sdd
  18. file format: raw
  19. virtual size: 23G (24696061952 bytes)
  20. disk size: 0
  • Step5:以 raw 的格式 rebase 并 commit centos7_1 到 iSCSI 设备中
  1. root@h3cas-e306:/kvm_backup# qemu-img rebase -b /dev/sdd -F raw centos7_1
  2. root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
  3. image: centos7_1
  4. file format: qcow2
  5. virtual size: 20G (21474836480 bytes)
  6. disk size: 25M
  7. cluster_size: 262144
  8. backing file: /dev/sdd
  9. backing file format: raw
  10. Format specific information:
  11. compat: 1.1
  12. lazy refcounts: false
  13. root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
  14. image: /dev/sdd
  15. file format: raw
  16. virtual size: 23G (24696061952 bytes)
  17. disk size: 0
  18. root@h3cas-e306:/kvm_backup# qemu-img commit -f qcow2 centos7_1
  19. Image committed.
  20. root@h3cas-e306:~# qemu-img info /dev/sdd
  21. image: /dev/sdd
  22. file format: raw
  23. virtual size: 23G (24696061952 bytes)
  24. disk size: 0
  • Step6: 使用 commit 后的 iSCSI 设备再次启动虚拟机
  1. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  2. Id Name State
  3. ----------------------------------------------------
  4. 38 centos7 running
  5. - centos7_q_0 shut off
  6. - centos7_r_0 shut off
  7. root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_r_0
  8. Domain centos7_r_0 started
  9. root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
  10. Id Name State
  11. ----------------------------------------------------
  12. 38 centos7 running
  13. 39 centos7_r_0 running
  14. - centos7_q_0 shut off

NOTE:尚未测试虚拟机在备份和恢复的过程中虚拟机的应用业务是否被中断。

CAS KVM 虚拟机的保护与恢复的更多相关文章

  1. centos7命令行模式安装&&配置_br0+kvm+虚拟机+添加硬盘+快照及恢复

    KVM创建虚拟机步骤 Submitted by zhaoley on October 18, 2016 - 10:43am 测试环境: 1: 43.243.130.89, CentOS Linux r ...

  2. 烂泥:KVM快照的创建与恢复

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 因为要做有关KVM虚拟机的实验,所以需要虚拟机生成快照.查询相关资料,说KVM可以使用两种方法生成虚拟机的快照. 方法一.使用qemu-img snap ...

  3. (转)CentOS7安装KVM虚拟机详解

    原文:https://github.com/jaywcjlove/handbook/blob/master/CentOS/CentOS7%E5%AE%89%E8%A3%85KVM%E8%99%9A%E ...

  4. 6、安装kvm虚拟机

    6.1.虚拟机开启虚拟化: 6.2.检查linux虚拟机cpu是否开启了虚拟化: egrep -o 'vmx|svm' /proc/cpuinfo vmx 6.3.安装kvm管理和安装kvm虚拟机的软 ...

  5. Oracl Linux KVM虚拟机备份

    Oracle Linux  KVM 作为Oracle Linux的一部分,基于KVM的Oracle Linux 服务器虚拟化解决方案在功能上得到了增强.用户可以利用Oracle Linux旧版本,将操 ...

  6. 烂泥:KVM虚拟机克隆

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 上一篇文章介绍了有关KVM虚拟机快照的创建与恢复,这篇文章我们来介绍有关KVM虚拟机克隆. KVM虚拟机的克隆,我们可以分以下几步: 1. 使用virt ...

  7. kvm虚拟机日常管理和配置操作命令梳理

    KVM虚拟机的管理主要是通过virsh命令对虚拟机进行管理.1)查看KVM虚拟机配置文件及运行状态KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/autostart目录是配置kvm ...

  8. 【转】libvirt kvm 虚拟机上网 – Bridge桥接

    libvirt kvm 虚拟机上网 – Bridge桥接 2013 年 7 月 3 日 / 东东东 / 暂无评论 目录 [hide] 1 Bridge桥接原理 2 在host机器配置桥接网络 2.1  ...

  9. 实现将VirtualBox 虚拟机转换为KVM虚拟机的步骤

    原来在桌面上一直使用virtualbox虚拟机管理程序(VMM)构建虚拟机安装不同的操作系统,现在 研究linux下的KVM,能否将已经建立的virtualBox虚拟客户机(guest)转换为KVM虚 ...

随机推荐

  1. P3158 [CQOI2011]放棋子(dp+组合数)

    P3158 [CQOI2011]放棋子 放棋子的顺序和方案数无关,所以可以从按颜色递推 设$f[u][p][k]$为放到第$u$种颜色,所剩空间$p*k$的方案数 $g[u][i][j]$表示第$u$ ...

  2. Android 点击跳转到蓝牙设置界面

    不再重写一遍了,看csdn: https://blog.csdn.net/qq_42866164/article/details/101353709

  3. Linux之目录配置

    Linux目录配置标准:FHS 主要目的,希望让用户可以了解到已安装软件通常放置于哪个目录下. FHS定义了三层主目录:/./usr./var 1. /(root,根目录) (1)根目录与开机.还原. ...

  4. 北京师范大学第十五届ACM决赛-重现赛 B Borrow Classroom (树 ——LCA )

    链接:https://ac.nowcoder.com/acm/contest/3/B 来源:牛客网 Borrow Classroom 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 2 ...

  5. string遍历

    #include <iostream>#include <string> using namespace std;int main(int argc, const char * ...

  6. element-ui 表格标题换行

     render-header: 列标题 Label 区域渲染使用的 Function <template> <el-table :data="dataList"& ...

  7. pip install mysql_python报错解决办法

    首先请注意,mysql_python只支持Python2,所以假如你是python3,就直接用python-connector去吧.下面这一条命令就可以了 pip install mysql-conn ...

  8. Spring Boot 整合Spring Data JPA

    Spring Boot整合Spring Data JPA 1)加入依赖 <dependency> <groupId>org.springframework.boot</g ...

  9. shimo

    shimo破解需要同意安装允许各个端安装

  10. 内联元素的盒子模型与文档流定位padding属性

            内联元素的盒子模型 1.内联元素不能设置width宽度和高度height span{width:200px ; height:200px}   与     span{width:100 ...