目录

方式一

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

  • Step1:centos7_0(base qcow2) 以 qcow2 格式写入到 iSCSI 设备
root@h3cas-e306:/vms/images# virsh list --all
Id Name State
----------------------------------------------------
33 centos7 running
root@h3cas-e306:/vms/images# virsh domblklist centos7
Target Source
------------------------------------------------
vda /vms/images/centos7_0
hda /vms/isos/CentOS-7-x86_64-Minimal-1511.iso
root@h3cas-e306:/vms/images# qemu-img convert -f qcow2 /vms/images/centos7_0 -O qcow2 /dev/sdd
root@h3cas-e306:/vms/images# qemu-img info /dev/sdd
image: /dev/sdd
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 0
cluster_size: 262144
Format specific information:
compat: 1.1
lazy refcounts: false
  • Step2:尝试使用 iSCSI 设备手动启动 KVM 虚拟机
# 创建 XML 文件
root@h3cas-e306:/etc/libvirt/qemu# vim centos7_q_0.xml <domain type='kvm'>
<name>centos7_q_0</name>
<uuid>d668e699-22a4-464b-99c4-1ffdcd6ad4e1</uuid>
<osha>0</osha>
<timesync>0</timesync>
<automem>0</automem>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<memorySlots>10</memorySlots>
<maxMemory unit='KiB'>34359738368</maxMemory>
<blkiotune>
<weight>300</weight>
</blkiotune>
<memtune>
<priority>1</priority>
</memtune>
<memoryBacking>
<locked>0</locked>
</memoryBacking>
<vcpu placement='static' current='2'>24</vcpu>
<cputune>
<shares>512</shares>
<period>1000000</period>
<quota>-1</quota>
</cputune>
<os>
<type arch='x86_64' machine='pc-i440fx-2.1'>hvm</type>
<system>linux</system>
<boot dev='hd'/>
<boot dev='cdrom'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<cpu>
<topology sockets='24' cores='1' threads='1'/>
<numa>
<cell cpus='0-1' memory='4194304'/>
</numa>
<gurantee unit='MHz'>0</gurantee>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<tools upgrade='auto'/>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='directsync' io='native'/>
<source file='/dev/sdd'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' cache='none'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</controller>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/centos7.agent'/>
<target type='virtio' name='org.qemu.guest_agent.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' 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='0x09' function='0x0'/>
</memballoon>
</devices> root@h3cas-e306:/etc/libvirt/qemu# virsh define centos7_q_0.xml
Domain centos7_q_0 defined from centos7_q_0.xml root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
33 centos7 running
- centos7_q_0 shut off root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_q_0
Domain centos7_q_0 started root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
33 centos7 running
34 centos7_q_0 running
  • Step3:对 centos7_0 做快照得到增量快照数据 centos7_1(increment qcow2)
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
Domain snapshot snap01 created
root@h3cas-e306:/vms/images# l
centos7_0 centos7_1
root@h3cas-e306:/vms/images# qemu-img info centos7_1
image: centos7_1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 772K
cluster_size: 262144
backing file: /vms/images/centos7_0
backing file format: qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/vms/images# virsh domblklist centos7
Target Source
------------------------------------------------
vda /vms/images/centos7_1
hda /vms/isos/CentOS-7-x86_64-Minimal-1511.iso

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

  • Step4:Copy centos7_1 的副本到备份目录下
root@h3cas-e306:/vms/images# cp centos7_1 /kvm_backup/
root@h3cas-e306:/vms/images# ll /kvm_backup/
total 2572
drwxr-xr-x 2 root root 4096 Apr 18 23:39 ./
drwxr-xr-x 33 root root 4096 Apr 18 23:22 ../
-rw------- 1 root root 2883584 Apr 18 23:39 centos7_1
  • Step5:rebase 并 commit centos7_1 到 iSCSI 设备中
root@h3cas-e306:/etc/libvirt/qemu# virsh destroy 34
Domain 34 destroyed
root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
33 centos7 running
- centos7_q_0 shut off
root@h3cas-e306:/vms/images# cd /kvm_backup/
root@h3cas-e306:/kvm_backup# ls
centos7_1
root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
image: centos7_1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 2.5M
cluster_size: 262144
backing file: /vms/images/centos7_0
backing file format: qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
image: /dev/sdd
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 0
cluster_size: 262144
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/kvm_backup# qemu-img rebase -b /dev/sdd -F qcow2 centos7_1
root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
image: centos7_1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 15M
cluster_size: 262144
backing file: /dev/sdd
backing file format: qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
image: /dev/sdd
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 0
cluster_size: 262144
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/kvm_backup# qemu-img commit -f qcow2 centos7_1
Image committed.
root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
image: centos7_1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 15M
cluster_size: 262144
backing file: /dev/sdd
backing file format: qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
image: /dev/sdd
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 0
cluster_size: 262144
Format specific information:
compat: 1.1
lazy refcounts: false
  • Step6:使用 commit 后的 iSCSI 设备启动虚拟机
root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
33 centos7 running
- centos7_q_0 shut off root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_q_0
Domain centos7_q_0 started root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
33 centos7 running
35 centos7_q_0 running

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

方式二

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

  • Step1:centos7(base qcow2) 以 raw 格式写入到 iSCSI 设备
root@h3cas-e306:/vms/images# qemu-img info centos7
image: centos7
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.0G
cluster_size: 262144
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/vms/images# qemu-img convert -f qcow2 /vms/images/centos7 -O raw /dev/sdd
root@h3cas-e306:/vms/images# qemu-img info /dev/sdd
image: /dev/sdd
file format: raw
virtual size: 23G (24696061952 bytes)
disk size: 0
  • Step2:使用 iSCSI 设备手动启动 KVM 虚拟机
root@h3cas-e306:/etc/libvirt/qemu# virsh define centos7_r_0.xml
Domain centos7_r_0 defined from centos7_r_0.xml
root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
36 centos7 running
- centos7_q_0 shut off
- centos7_r_0 shut off
root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_r_0
Domain centos7_r_0 started
root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
36 centos7 running
37 centos7_r_0 running
- centos7_q_0 shut off
  • Step3:对 centos7 做快照得到增量快照数据 centos7_1(increment qcow2)
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
Domain snapshot snap01 created
root@h3cas-e306:/vms/images# ls
centos7 centos7_1
root@h3cas-e306:/vms/images# qemu-img info centos7_1
image: centos7_1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 2.0M
cluster_size: 262144
backing file: /vms/images/centos7
backing file format: qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
  • Step4: Copy centos7_1 的副本到备份目录下
root@h3cas-e306:/vms/images# cp centos7_1 /kvm_backup/
root@h3cas-e306:/vms/images# cd /kvm_backup/
root@h3cas-e306:/kvm_backup# ls
centos7_1
root@h3cas-e306:/kvm_backup# qemu-img info /kvm_backup/centos7_1
image: /kvm_backup/centos7_1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 2.5M
cluster_size: 262144
backing file: /vms/images/centos7
backing file format: qcow2
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
image: /dev/sdd
file format: raw
virtual size: 23G (24696061952 bytes)
disk size: 0
  • Step5:以 raw 的格式 rebase 并 commit centos7_1 到 iSCSI 设备中
root@h3cas-e306:/kvm_backup# qemu-img rebase -b /dev/sdd -F raw centos7_1
root@h3cas-e306:/kvm_backup# qemu-img info centos7_1
image: centos7_1
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 25M
cluster_size: 262144
backing file: /dev/sdd
backing file format: raw
Format specific information:
compat: 1.1
lazy refcounts: false
root@h3cas-e306:/kvm_backup# qemu-img info /dev/sdd
image: /dev/sdd
file format: raw
virtual size: 23G (24696061952 bytes)
disk size: 0
root@h3cas-e306:/kvm_backup# qemu-img commit -f qcow2 centos7_1
Image committed.
root@h3cas-e306:~# qemu-img info /dev/sdd
image: /dev/sdd
file format: raw
virtual size: 23G (24696061952 bytes)
disk size: 0
  • Step6: 使用 commit 后的 iSCSI 设备再次启动虚拟机
root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
38 centos7 running
- centos7_q_0 shut off
- centos7_r_0 shut off root@h3cas-e306:/etc/libvirt/qemu# virsh start centos7_r_0
Domain centos7_r_0 started root@h3cas-e306:/etc/libvirt/qemu# virsh list --all
Id Name State
----------------------------------------------------
38 centos7 running
39 centos7_r_0 running
- 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. SCUT - 486 - 无向图上的点 - Dijkstra

    好像原题是这个?https://www.cnblogs.com/kanchuang/p/11120052.html 这个有解释:https://blog.csdn.net/wddwjlss/artic ...

  2. STL容器概述

    STL容器 1.容器概述 1.1.容器分类 1.1.1.顺序容器:提供对元素序列的访问,顺序容器为元素连续分配内存或将元素组织为链表,元素的类型是容器成员value_type. 顺序容器 说明 vec ...

  3. 自动化部署三剑客 gitlab + ansible + jenkins

    http://www.showerlee.com/archives/1880 https://edu.51cto.com/center/course/lesson/index?id=280700 Gi ...

  4. iOS之Run Loop详解

    转自标哥的技术博客(www.henishuo.com) 前言 做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一 ...

  5. mongo 数据库操作

    启动和关闭数据库 启动 # mongodb 默认使用执行 mongod 命令所处的盘的根目录下  /data/db 作为自己的数据存储目录 #   所以在第一次执行该命令之前先自己动手新建一个  /d ...

  6. 将数据转为tfrecord格式

    假设emo文件夹下,有1,2,3,4等文件夹,每个文件夹代表一个类别 import tensorflow as tf from PIL import Image from glob import gl ...

  7. 如何对GitHubPages上的静态资源进行CDN加速

    前记 从我开始学习前端我就一直在做着我的个人简历网站,使用GitHubpPages的预览功能进行预览,但是由于最近我的个人简历,不停的丰富,图片增多,而且将css和js文件用webpack打包后变成一 ...

  8. 滑块QAbstractSlider

    继承于 QWidget 抽象类-必须子类化 提供的范围内的整数值 QAbstractSlider import sys from PyQt5.QtWidgets import QApplication ...

  9. postman-参数化

    1.txt 1.如图第一行为变量名,下面行为对应的值 2.设置 Pre-request-Script 参数 data为文件名,username.password自定义参数名:在Tests最好加上断言 ...

  10. CF1244C

    题目描述 给出n,p,w,d,求(x,y,z)使得 xw+yd=p x+y+z=n 其中d<w<10^5^ 题解 显然扩欧啊( 来自天国的long long y如果大于等于w,则显然可以把 ...