How to recover accidentally deleted VM data from xenserver

Source: Internet
Author: User

Some users often ask how to recover a virtual machine accidentally deleted by the customer from the perspective of xenserver. Citrix technical support does not provide this data recovery service, but it is not unrecoverable and the process is complicated, here I will explain how to restore the accidentally deleted VM data.

Here I create a test storage and test Vm

650) This. width = 650; "Title =" QQ image 20140727192038 "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" QQ pictures 20140727192038 "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460290fAXg.jpg "width =" 519 "Height =" 195 "/>
The UUID corresponding to the SR is 4ec639db-6c87-b775-73d1-b54e21b3a31a.
Open the xenserver command line and enter pvsan to find the VG and PV information for the storage.

650) This. width = 650; "Title =" qq20140727192141 "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" qq20140727192141 "src =" http://img1.51cto.com/attachment/201407/27/152152_14064602990gLV.png "width =" 527 "Height =" 130 "/>
The default VG information is stored in/etc/LVM/backup.
# Dir

650) This. width = 650; "Title =" image "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460301IlFz.png "width =" 535 "Height =" 73 "/>
For test purposes, I will back up the original VG information first, and back up it to the/root directory.
# Cp VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a/root
In this case, we try to delete the virtual machine and the disk files.
After deletion, we can see that there is no corresponding data in the storage, because we have backed up VG before, so we can directly restore the VG information through the command.
# Vgcfgrestore VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a-F/root/VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a
After the restoration is complete, we use lvscan to check whether the restoration is successful.
# Lvscan | grep 4ec6

650) This. width = 650; "Title =" image "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460304gNnn.png "width =" 553 "Height =" 41 "/>
We see that the VHD-306128a9-7138-4611-a2c6-b79823e1e58b here has been restored, but here we see that the logical volume is inactive and we need to activate it first
# Lvchange-ay/dev/VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a/VHD-306128a9-7138-4611-a2c6-b79823e1e58b
After activation, note that the vhd attribute is hidden. If you execute Sr-scan at this time, you will find that the logical volume is missing again, for more information about vhd attributes, run the following command:
# Vhd-util read-N/dev/VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a/VHD-306128a9-7138-4611-a2c6-b79823e1e58b-P

650) This. width = 650; "Title =" image "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460310JTfq.png "width =" 502 "Height =" 479 "/>
In this case, we must change this attribute to non-hidden by default. Use the following command to complete
# Vhd-util set-N/dev/VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a/VHD-306128a9-7138-4611-a2c6-b79823e1e58b-F hidden-V 0
Create a VM and mount the corresponding disk to restore the VM.
However, the problem focuses on this, because it is impossible for the customer to manually back up the VG information, when deleting the VM, the VG information under the/etc/LVM/backup directory on the xenserver is also updated. Therefore, it is difficult to restore the file in this case, but there is no way to restore the file.
First, find the PV information of the VG.
# Pvscan

650) This. width = 650; "Title =" image "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460313Twuz.png "width =" 544 "Height =" 108 "/>
The PV corresponding to this VG is/dev/SDJ.
# Dd If =/dev/sdj count = 100 | strings

650) This. width = 650; "Title =" image "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460316CZ2F.png "width =" 557 "Height =" 165 "/>
In the above output, we can see the deleted vhd information (please note that if you store a lot of vhd information here, it must be correct one by one, I have very few vhd above, so it is easy to find), record the above information
Open the corresponding VG backup information under the/etc/LVM/Backup Directory
# Cat VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a | more
We can see that the normal vhd information is in the following format in the VG backup information:

650) This. width = 650; "Title =" image "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460319Wh7H.png "width =" 528 "Height =" 273 "/>
Based on the vhd information we found in PV, insert the information to the corresponding VG information in the above format and save and exit.
# Vi VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a
Insert the following content:

650) This. width = 650; "Title =" image "style =" border-right-width: 0px; border-bottom-width: 0px; border-top-width: 0px; "Border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201407/27/152152_1406460321nSVV.png "width =" 546 "Height =" 282 "/>
Continue to run vgcfgrestore
# Vgcfgrestore VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a-F VG_XenStorage-4ec639db-6c87-b775-73d1-b54e21b3a31a
At this time, the logical volume can be restored. The remaining logical volume will be activated. Change the vhd attribute hidden to 0, create a VM, and mount the disk to complete the final data recovery!

This article from the "virtual life" blog, please be sure to keep this source http://virtuallife.blog.51cto.com/152152/1530965

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.