Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement KVM virtual machine snapshot

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to achieve a snapshot of the KVM virtual machine. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The default file format for KVM is raw, which uses files to simulate the actual hard disk (of course, you can also use a real hard disk or a partition), but the raw format only supports memory snapshots (that is, adding-snapshot at startup, and all changes are written to memory), which will be gone after reboot. The raw format does not support disk snapshots, so use the qcow or qcow2 file format.

1. To create a virtual machine image file in qcow2 format

[root@target kvm_node] # qemu-img create-f qcow2 / virhost/kvm_node/node4.img 20G

The parameter-f specifies the format, if not, the default is raw.

[root@target kvm_node] # qemu-img info node4.img # View the image file format

Image: node4.img

File format: qcow2

Virtual size: 20g (21495808000 bytes)

Disk size: 6.3G

Cluster_size: 65536

2. Convert raw format to qcow2 format:

[root@target kvm_node] # qemu-img convert-f raw-O qcow2 / virhost/kvm_node/node5.img / virhost/kvm_node/node5_qcow2.img

3. Create a snapshot for virtual machine node4

No file under [root@node4 ~] # ls / root/ # / root/

[root@target kvm_node] # virsh snapshot-create-as node4 node4.snap1

[root@target kvm_node] # qemu-img info node4.img

Image: node4.img

File format: qcow2

Virtual size: 20g (21495808000 bytes)

Disk size: 6.3G

Cluster_size: 65536

Snapshot list:

ID TAG VM SIZE DATE VM CLOCK

1 node4.snap1 401m 2012-04-10 12:04:42 22 purl 02purl 04.672

4. Modify node4 system files and restore them through snapshot files.

[root@node4] # scp node5:/root/*. # copy files from node5

Root@node5's password:

Anaconda-ks.cfg 100% 1224 1.2KB/s 00:00

Scp: / root/Desktop: not a regular file

Install.log 100% 34KB 33.7KB/s 00:00

Install.log.syslog 100% 4232 4.1KB/s 00:00

Nginx-0.7.65.tar.gz 100% 590KB 590.3KB/s 00:00

Pcre-8.02.tar.gz 100% 1218KB 1.2MB/s 00:00

Php-5.2.13-fpm-0.5.13.diff.gz 100% 197KB 196.6KB/s 00:00

Php-5.2.13.tar.gz 0 0 0.0KB/s-ETAlphp-5.2.13.tar.gz 100% 11MB 11.2MB/s 00:01

Scp: / root/webbench-1.5: not a regular file

Webbench-1.5.tar.gz 100% 7675 7.5KB/s 00:00

[root@node4 ~] # ls

Anaconda-ks.cfg install.log.syslog pcre-8.02.tar.gz php-5.2.13.tar.gz

Install.log nginx-0.7.65.tar.gz php-5.2.13-fpm-0.5.13.diff.gz webbench-1.5.tar.gz

[root@target kvm_node] # virsh snapshot-create-as node4 node4.snap2 # create a snapshot of the current state of the virtual machine node4

[root@target kvm_node] # virsh snapshot-list node4 # View a snapshot of node4

Name Creation Time statu

Node4.snap1 2012-04-11 00:47:06 + 0800 paused

Node4.snap2 2012-04-11 01:19:06 + 0800 running

[root@target kvm_node] # virsh snapshot-revert node4 node4.snap1 # restore node4 from snapshot file node4.snap1

There are no files under [root@node4 ~] # ls / root/ # / root/. The recovery is successful.

[root@target kvm_node] # virsh snapshot-revert node4 node4.snap2 # restore node4 from snapshot file node4.snap2

[root@node4 ~] # ls # recovered successfully

Anaconda-ks.cfg install.log.syslog pcre-8.02.tar.gz php-5.2.13.tar.gz

Install.log nginx-0.7.65.tar.gz php-5.2.13-fpm-0.5.13.diff.gz webbench-1.5.tar.gz

5. Delete a snapshot

[root@target kvm_node] # virsh snapshot-delete node4 node4.snap1

6. Create the snapshot of the image file by using qemu-img

Create a snapshot

Qemu-img snapshot-c node4.snap1 / virhost/kvm_node/node4.img

# Test the command to create a snapshot whose size is always 0. I don't know which god can solve it.

View Snapshot

Qemu-img snapshot-l / virhost/kvm_node/node4.img

Restore the virtual machine to the state of a snapshot:

Qemu-img snapshot- a snapshot-name / path/to/os.img

Delete a snapshot:

Qemu-img snapshot- d snapshot-name / path/to/os.img

This is the end of the article on "how to realize the snapshot of KVM virtual machine". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report