kvm snapshot backup and recovery

View disk formats:

[root@ehs-as-04 ehs-rac-01]# cd /var/lib/libvirt/images/
[root@ehs-as-04 images]# qemu-img info ehs-rac-01.qcow2
image: ehs-rac-01.qcow2
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 34G
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 ehs-rac-01-bak 1.6G 2019-09-09 16:00:13 00:16:16.672
2 ehs-rac-01-bak02 1.9G 2019-09-09 16:04:40 00:20:27.294
Format specific information:
    compat: 1.1
    lazy refcounts: true
Because kvm virtual machines using the default raw format image format, the performance of the best, fastest, its drawback is that does not support some new features, such as support for mirroring, zlib disk compression, AES encryption. To use mirroring, disk format must be qcow2. If the format is raw, you need to convert. We can see a mirror image of the grid is qcow2, so no need to change the image format.
 
Disk format conversion
[EHS-AS- the root @ 04 Images] -f # QEMU Convert RAW -O-IMG qcow2 of rac- EHS- 01 .img of rac- EHS- 01 .qcow2
 - Format of the mirror f   
 -O target image format
Virtual machine snapshot management
 
Create a snapshot
[root @ EHS-AS- 04 ImagesRF Royalty Free] # virsh the Create Snapshot-EHS-rac-Ethyl 01 
## can also give a snapshot from the alias 
[root @ EHS -as- 04 ImagesRF Royalty Free] # virsh the Create Snapshot-AS-EHS-rac-Ethyl 01 EHS-rac-Ethyl 01 -bak

View snapshot version

[EHS-AS- the root @ 04 Images] # virsh Snapshot-List of rac- EHS- 01 
 Name Generation Time Status
 -------------------------- ---------------------------------- 
 EHS -rac- 01 -bak 2019 - 09 - 09  16 : 00 : 13 is + 0800 running 
 EHS -rac- 01 -bak02 2019 - 09 - 09  16 : 04 : 39 + 0800 running

View the current version of the virtual machine snapshot

[root@ehs-as-04 images]# virsh snapshot-current ehs-rac-01
<domainsnapshot>
  <name>ehs-rac-01-bak02</name>
  <state>running</state>
  <parent>
    <name>ehs-rac-01-bak</name>
  </parent>
  <creationTime>1568016279</creationTime>
  <memory snapshot='internal'/>
  <disks>
    <disk name='hda' snapshot='internal'/>
    <disk name='hdb' snapshot='no'/>
  </disks>
  ...

View the current image file:

[root@ehs-as-04 images]# qemu-img info ehs-rac-01.qcow2
image: ehs-rac-01.qcow2
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 34G
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 ehs-rac-01-bak 1.6G 2019-09-09 16:00:13 00:16:16.672
2 ehs-rac-01-bak02 1.9G 2019-09-09 16:04:40 00:20:27.294
Format specific information:
    compat: 1.1
    lazy refcounts: true

Snapshot configuration file in the / var / lib / libvirt / qemu / snapshot / virtual machine name

[EHS-AS- the root @ 04 Images] # LL / var / lib / the libvirt / QEMU / Snapshot / EHS of rac-- 01 / 
Total amount 16 
-rw ------- . 1 the root the root 5250 . 9 dated . 9  16 : 04 EHS-rac-Ethyl 01 - bak02.xml
 -rw ------- 1 root root 5193 9 Yue 9  16 : 04 EHS-rac-Ethyl 01 -bak.xml
Restore virtual machine snapshots
Note: Recovery Snapshot, must be shut down, make sure the virtual machine is turned off.
[root@ehs-as-04 images]# virsh destroy ehs-rac-01
域 ehs-rac-01 被删除
[root@ehs-as-04 images]# virsh list --all
 Id 名称 状态
----------------------------------------------------
 10 ehs-jboss-02 running
 14 ehs-mq-02 running
 15 ehs-jboss-01 running
 17 ehs-mq-01 running
 23 ehs-rac-02 running
 - ehs-oracle-01 关闭
 - ehs-oracle-02Close
  - EHS rac-Ethyl- 01 closed

Snapshot version or time recognized the need to restore, where to restore ehs-rac-01-bak02

[EHS-AS- the root @ 04 Images] # virsh Snapshot-List of rac- EHS- 01 
 Name Generation Time Status
 -------------------------- ---------------------------------- 
 EHS -rac- 01 -bak 2019 - 09 - 09  16 : 00 : 13 is + 0800 running 
 EHS -rac- 01 -bak02 2019 - 09 - 09  16 : 04 : 39 + 0800 running

Performing a recovery

[root@ehs-as-04 images]# virsh snapshot-revert ehs-rac-01 ehs-rac-01-bak02

If the recovery time needed to ehs-rac-01-bak02 ​​modification timestamp

[root@ehs-as-04 images]# virsh snapshot-revert ehs-rac-01 1500373324
To delete a virtual machine snapshot
First ehs-rac-01 image corresponding to a snapshot of what
[root@ehs-as-04 images]# qemu-img info ehs-rac-01.qcow2 
image: ehs-rac-01.qcow2
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 34G
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 ehs-rac-01-bak 1.6G 2019-09-09 16:00:13 00:16:16.672
2 ehs-rac-01-bak02 1.9G 2019-09-09 16:04:40 00:20:27.294
Format specific information:
    compat: 1.1
    lazy refcounts: true

Remove the first snapshot

[root @ EHS-AS- 04 ImagesRF Royalty Free] # virsh the Delete Snapshot EHS-rac-Ethyl- 01 EHS-rac-Ethyl 01 - BAK 
deleted domain snapshots EHS -rac- 01 -bak

Look for confirmation

[EHS-AS- the root @ 04 Images] # virsh Snapshot-List of rac- EHS- 01 
 Name Generation Time Status
 -------------------------- ---------------------------------- 
 EHS -rac- 01 -bak02 2019 - 09 - 09  16 : 04 : 39 + 0800 running

It has been deleted.

 

Guess you like

Origin www.cnblogs.com/opma/p/11606951.html