Practical case-SQL Server database data cannot be read solution

Source: Internet
Author: User
Tags truncated

1. Overview of database Failures
The data for the SQL Server database cannot be read.

2. Fault Analysis

The SQL Server database file could not be read because the underlying file record was truncated to 0, unable to find the beginning of the document, and the data table structure was corrupted. The image file's front 80M space after the left, and the middle part is overwritten, causing the system table to be corrupted, so it cannot be read, consider the automatic backup file to extract the table structure.
Record of operation in log:

Because the system tables are damaged, the structure of a large number of data tables cannot be determined, but only by engineers recovering from experience.

3. Solutions

Back up the user data to the hard disk that lost the data. Do a full backup to ensure the security of your data.
Analyze the database of old data in the backup file.
Look for the structure of the data table from the old database.
Extracts the structure of a portion of the data table from the log.
Extract intact data from logs and residual data.
Restore the corresponding data based on the log and check that the data is correct.
Recover all data after checking the data without problems.

4. Data recovery implementation Process

4.1 Backing up user data
As the data are all placed in the customer's original disk, the hardware department first to detect whether there is physical failure. After detecting the problem, make a full image of each hard drive and use special tools to mirror all the sectors on the hard disk to a single backup drive.

4.2 Scanning image files
Open residual files with Winhex, carefully analyze the underlying data of the hard disk, and discover that there are many previous SQL Server logs and backup files in the bottom of the hard disk. After careful observation and analysis, found that there are many databases in the log, including INSERT statement operation Records, these records can be considered extracted. There are backup files, open backup files can be found in the table statements, and some old data.
However, because the entire hard disk is too large to manually search the SQL Server related Data section is very slow, so write a database to extract data related to a small program, the entire hard disk to all existing database residue scan, extract all the data.
4.3 Analyzing scanned data
Analysis of all the log files scanned, found that the log file is also divided into data pages, with a fixed beginning and end, where each piece of data in a fixed location has its own object ID number, in the next scan file, continue to search for the same object ID data records, found the same structure, Can be determined that this is intact data that can be extracted.
After analyzing the scanned backup files, we find that we can extract a lot of table statements and get some table structure. The remaining table structure, because the truncated 0 part is just in the system table, there is no way to extract the table structure, only the data extracted from the log to guess the table structure and data type.
4.4 Extracting data
According to the conclusion of the previous analysis, the program first extracts the table statement from the backup file, analyzes the table structure and various data types according to the table statement, and finds 22H, 07H and 05H tables in the remaining system tables, according to the corresponding relationship between these tables and object_id. Then write a new program to extract the records in the log (I was not able to parse the numeric type of bytecode into data at this point, so it stuck), corresponding to the data and table according to the object ID, and inserted into the new table.
4.5 Verifying all data
It is verified that the new table of data recovery is basically consistent with the data that is observed manually.
Data recovery was successful.

Practical case-SQL Server database data cannot be read solution

Related Article

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.