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 use the Linux command to create a snapshot

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

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the Linux command to create a snapshot. 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.

Virtual machine snapshot is a very good feature, it can save the state of the current virtual machine. Unfortunately, open source Xen does not provide support for snapshots, but Linux does. Because open source Xen usually uses Linux as its privileged domain, you can use the Linux command to create snapshots.

Take a snapshot byte by byte

One way to create a snapshot in Xen is to use Linux dd after saving the current state of the virtual machine. This includes the following steps:

1. Use the xm save command to disable the current virtual machine state and write it to a disk file. This only writes the machine state to a file, not for the current state of the Xen disk file or partition. Do this with the name linux01 and xm save linux01 linux01.sav. Note that this command will stop the virtual machine.

two。 Now use dd to transfer the current state of the disk image file to a backup file. The following example will be a LVM logical volume:

Dd if=/dev/xenvols/linux01_root of=/data/xen_linux01_root.img

3. Restart the virtual machine using the xm restore command.

The main drawback of this solution is that it takes time. The dd command copies virtual machine disk files byte by byte, so it takes a lot of time. So this scheme is not very practical.

LVM method

In Linux, Logical Volume Manager (LVM) can also be used to create snapshots, which saves a lot of time than the previous disk file method. This approach means that your virtual machine uses LVM logical volumes as the storage back end, in contrast to using virtual disk files. Because of this logical volume, you next need to create a snapshot. This snapshot is a backup that contains only the metadata and blocks that were changed when the snapshot was taken. When you make a snapshot copy using dd with metadata, you usually take a snapshot of the original block on the original volume without reactivating the original volume. In this way, the time it takes to create a snapshot can be greatly reduced. The steps are as follows:

1. Use the xm save command to save the current state of the virtual machine and write to the disk file:

Xm save linux01 linux01.sav

two。 Assuming you already have a LVM logical volume to use as the storage back end for your virtual machine, use the following command to take a snapshot of the volume. A better guideline is to use 10% of the disk space allocated in the original logical volume as the size of the snapshot volume:

Lvcreate-s-L 1G-n linux01-snap / dev/xenvols/linux01

3. Now that you have saved the state of the virtual machine in the LVM snapshot, you can restart the virtual machine and significantly reduce the downtime of the virtual machine:

Xm restore linux01-sav

4. Use dd to create a virtual machine snapshot and write to an image file. This will take a long time because you want to use snapshots to replicate disk blocks assigned by all virtual machines:

Dd if=/dev/xenvols/linux01-snap of=/data/xen01.img

5. Don't forget to remove the snapshot in one step. This is important because the snapshot will eventually be completely overwritten, making the snapshot unusable. Such a problem will prevent you from rebooting from the original volume, so don't forget this step:

Lvremove / dev/xenvols/linux01-snap on "how to use the Linux command to create a snapshot" this article is shared here, 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 out 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: 246

*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