Restore accidentally deleted data using SQL Server logs

Source: Internet
Author: User
If you are anxious to see this article, please change your posture, take a few deep breaths, and calm down to read this article. Maybe your problem can be solved. The problem I encountered was that the website was implanted with a Trojan and my web. config file was stolen. The database connection strings in the web. config file were not encrypted, while my database

If you are anxious to see this article, please change your posture, take a few deep breaths, and calm down to read this article. Maybe your problem can be solved. The problem I encountered was that the website was implanted with a Trojan and my web. config file was stolen. The database connection strings in the web. config file were not encrypted, while my database

If you are anxious to see this article, please change your posture, take a few deep breaths, and calm down to read this article. Maybe your problem can be solved.

This is the case where my website was implanted with Trojans and my web was stolen. config File, web. the database connection string in the config file is not encrypted, and the remote connection to my database is not subject to IP address restrictions. After a hacker connects to my database through the database client, delete all tables, so you must have a good habit.Encrypt the database connection stringOrRestrict the IP address used to remotely access the database.

I don't know the specific time when the hacker deleted all the data, so I used a tool.Log ExplorerTo view and analyze the database logs, and to see when the logs are deleted (if you already know the time point you want to restore, you do not need to use this tool). AsLog ExplorerI will not go into details about how to install and use the database here. I will go to Baidu to search for a large number of items, select both the Client and Server during installation, and then enter the user name and password of the database in the installation process, if you don't understand anything else, go crazy next.

Through the Log Explorer tool, I can see that the deleted time point is: 07-10 09:46:29. 880. Then I will restore the data to 07-10 09:46:29. 879.

Now, let's get started with the Restoration Operation.

1. Back up the database logs and use the T-SQL statement.

?

1

BACKUP LOG shua TO DISK='c:\shua_log.bak' WITH FORMAT

2. Because my database has an automatic and complete backup every day, find a complete backup from the latest time to restore it. Here I will not overwrite the old database, directly restored to a new database shua2

Use the SQL Server Management Studio tool to perform interface operations. It is too complicated to write SQL statements.

Right-click the database and choose Restore database. The information is displayed on the [Restore database] page and on the [general] tab.

Click the options tab,Note that this step is very important.

Click [do not perform any operations on the database, do not roll back to commit transactions], and then confirm. If the database is large, it will take a long time to restore the database. Just take a few mouthfuls of fresh air and you will be done.

3. It is in this status after the database is restored successfully.

Display (restoring...), right-click the database shua2, choose task> restore transaction log.

As filled in, first fill in the log c: \ shua_log.bak, and then select [restore]. The most important thing is to select a time point. Unfortunately, this time point cannot be set to milliseconds, so I chose 29 seconds. At this time, the data from the past 29.0 seconds will be restored, and my data will be deleted from 29.880 seconds. Therefore, I chose 29 seconds; why didn't I select 28 seconds? Because my database changes a lot every second, I try to narrow down this time range as much as possible.

After filling out the information, click OK. Now the database has been restored to the status at 09:46:29. 0 on February 10,. Naturally, all my table data is back.

Ps:

1. If your database has never been fully backed up, you cannot use this method to recover it;

2. During the [full backup-> now] period, you have compressed the database logs to a large extent, which may be difficult to restore.

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.