kvm--虛擬機器快照備份

來源:互聯網
上載者:User

標籤:

 

 

kvm虛擬機器預設使用raw格式的鏡像格式,效能最好,速度最快,它的缺點就是不支援一些新的功能,如支援鏡像,zlib磁碟壓縮,AES加密等。   
要使用鏡像功能,磁碟格式必須為qcow2。下面開始kvm虛擬機器快照備份的過程。

本文出自:http://koumm.blog.51cto.com

進一步的學習參考:kvm+libvirt虛擬機器快照淺析 http://itxx.sinaapp.com/blog/content/130

1.  查看現有磁碟鏡像格式與轉換

(1) 查看磁碟格式

# qemu-img info test01.img

raw格式需要轉換成qcow2

(2) 關閉虛擬機器並轉換磁碟

# virsh shutdown oeltest01

 

(3) 轉換磁碟格式

# qemu-img convert -f raw -O qcow2 test01.img test01.qcow2 

-f  源鏡像的格式   
-O 目標鏡像的格式

查看轉換後的格式,已經轉換成了qcow2, 這裡是拷貝一份,並將格式轉成qcow2

# qemu-img info test01.qcow2

2. 修改虛擬機器組態檔

修改磁碟格式,與新qcow2格式的磁碟。

3. 對虛擬機器進行快照管理 

(1) 對oeltest01虛擬機器建立快照

也可以virsh snapshot-create as oeltest01 snap1 建立後個快照別名。

(2) 查看虛擬機器鏡像快照的版本

(3) 查看當前虛擬機器鏡像快照的版本

可以看到為當前最新的快照版本。

[[email protected] data]#    
[[email protected] data]# virsh snapshot-current oeltest01    
<domainsnapshot>    
  <name>1378579737</name>    
  <state>shutoff</state>    
  <creationTime>1378579737</creationTime>    
  <memory snapshot=‘no‘/>    
  <disks>    
    <disk name=‘hda‘ snapshot=‘internal‘/>    
    <disk name=‘hdc‘ snapshot=‘no‘/>    
  </disks>    
  <domain type=‘kvm‘>    
    <name>oeltest01</name>    
    <uuid>8f2bb4a7-c7ed-32aa-3676-9fb05923269d</uuid>    
    <memory unit=‘KiB‘>524288</memory>    
    <currentMemory unit=‘KiB‘>524288</currentMemory>    
    <vcpu placement=‘static‘>1</vcpu>    
    <os>    
      <type arch=‘x86_64‘ machine=‘rhel6.4.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/test01.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=‘ide‘ index=‘0‘>    
        <address type=‘pci‘ domain=‘0x0000‘ bus=‘0x00‘ slot=‘0x01‘ function=‘0x1‘/>    
      </controller>    
      <controller type=‘usb‘ index=‘0‘/>    
      <interface type=‘bridge‘>    
        <mac address=‘52:54:00:82:39:01‘/>    
        <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=‘tablet‘ bus=‘usb‘/>    
      <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=‘0x04‘ function=‘0x0‘/>    
      </memballoon>    
    </devices>    
  </domain>    
</domainsnapshot> 

[[email protected] data]# 

(4) 查看當前虛擬機器鏡像檔案

又建立了一個,快照的版本也記錄在鏡像檔案中了。

快照設定檔在/var/lib/libvirt/qemu/snapshot/虛擬機器名稱/下

4. 恢複虛擬機器快照

(1) 恢複虛擬機器快照必須關閉虛擬機器。

確認虛擬機器是關機狀態

(2) 確認需要恢複的快照時間,這裡恢複到1378579737

(3) 執行恢複,並確認恢複版本

# virsh snapshot-revert oeltest01 1378579737 

5. 刪除虛擬機器快照

(1) 查看虛擬機器快照

# qemu-img info test01.qcow2

這裡刪除第一個快照1378579737

(2) 刪除快照

到此kvm虛擬機器快照測試完畢。kvm虛擬化學習筆記進行到這裡了,感覺到kvm虛擬化的內容真的很多。水是越來越深了。

kvm--虛擬機器快照備份

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.