How to Create a snapshot using Linux commands?

Source: Internet
Author: User

During our study of Linux, we often encounter problems that cannot be solved. This article explains how to create snapshots using Linux commands. A vm snapshot is a good function that can save the status of the current VM. Unfortunately, open-source Xen does not support snapshots, but Linux does. Because open-source Xen usually uses Linux as its privileged domain, you can use Linux commands to create snapshots.

One byte Snapshot

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

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

2. Now, dd is used to convert the current status of the disk image file to a backup file. The following example shows the logical volume of LVM:

 
 
  1. dd if=/dev/xenvols/linux01_root of=/data/xen_linux01_root.img 

3. Run the xm restore command to restart the VM.

The main disadvantage of this solution is time consumption. The dd command replicates Virtual Machine disk files one byte at a time, so it takes a lot of time. Therefore, this solution 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 method means that your VM uses the LVM logical volume as the storage backend and compares it with the Virtual Disk File. Because of this logical volume, you need to create a snapshot next. This snapshot is a type of backup that only contains the metadata and block changed during the snapshot. When you use the metadata to create a snapshot Copy Using dd, you usually create a snapshot of the original block on the original volume and do not need to reactivate the original volume. In this way, the snapshot creation time can be greatly reduced. The procedure is as follows:

1. Run the xm save command to save the current status of the VM and write it to the disk file:

 
 
  1. xm save linux01 linux01.sav 

2. If you already have an LVM logical volume used as the storage backend of your Vm, use the following command to Snapshot the volume. The best practice is to use 10% of the disk space allocated in the original logical volume as the snapshot volume size:

 
 
  1. lvcreate -s -L 1G -n linux01-snap /dev/xenvols/linux01 

3. Because you have saved the status of the VM in the LVM snapshot, You can restart the VM to significantly reduce the downtime of the VM:

 
 
  1. xm restore linux01-sav 

4. Use dd to create a VM snapshot and write an image file. Because snapshot is used to copy the disk blocks allocated by all virtual machines, this takes a long time:

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

5. Do not forget to remove the snapshot in the last step. This is very important because the snapshot will eventually be completely overwritten and the snapshot will not be available. This problem will prevent you from restarting the original volume, so do not forget this last step:

 
 
  1. lvremove /dev/xenvols/linux01-snap 

Currently, no Linux version provides a way to create virtual machine snapshots in the open-source Xen stack. In this article, we have learned how to use standard Linux tools, such as LVM and dd commands to create snapshots.

In this way, you will learn how to use Linux commands to create snapshots.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.