Question

I was wondering how you can recover data from your logfile. I'm using sql 2005 (full backup).

The problem is that a service cleared my data last night (which it shouldn't have). and now I want to recover those rows that were deleted before.

can anyone tell me how I can do this?

Was it helpful?

Solution

As long as you have a backup of your database from before the delete and then all transaction log backups that have been made since the last database backup then you will be able to restore to a point in time.

The first thing to do is take a backup of the transaction log.

Then you restore your last database backup and all transaction log backups since then up to the point in time just before the delete.

See this MSDN Article on how to do it.

I would suggest that you leave your existing database in place as it is and restore the backups to a new database. Then you can write some scripts to transfer the required data back into your live database.

OTHER TIPS

First of all, your database must be in the full recovery model and you must have a full chain of transaction log backups - a series of log records having an unbroken sequence of log sequence numbers (LSNs)

The log backup chain is started when a full database backup is made or the recovery model is switched from SIMPLE to FULL and a full backup is made. After that, transaction log backups are created on regular basis. The log backup chain can be broken only in two ways:

  • Overwriting the backup set
  • Switching from FULL to SIMPLE or BULK LOGGED recovery models

Breaking the log backup chain can lead to missing transaction information

You can restore to a point in time using:

  • SQL Server Management Studio, as shown in the link Robin provided
  • Using T-SQL and the STOPAT option

Syntax

RESTORE LOG database_name 
FROM <backup_device> 
WITH STOPAT = time, RECOVERY… 
  • Use a third party tool, such as ApexSQL Log which can not only restore to a specific point in time, but selectively roll back only the transdactions you selected

You can find the steps for all listed options here: Restore a database to a point in time

Disclaimer: I work for ApexSQL as a Support engineer

Your data can be recovered only in case: 1) database uses full recovery model; 2) you have full backup that you make before accidental deleting; 3) you have have NOT recover or backup again this database yet.

If this is correct, you should: 1) make transaction log backup; 2) restore database from full backup WITH NORECOVERY option; 3) restore transaction log using STOPAT option.

To restore transaction log files to a point-in-time your database must run under full recovery model. So firstly you have to restore the latest full database backup:

RESTORE DATABASE *database* FROM DISK = 'D:/Full.bak' WITH NORECOVERY, REPLACE

The next step is to restore the last differential database backup:

RESTORE DATABASE *database* FROM DISK = 'D:/Diff.bak' WITH NORECOVERY

And then restore all transaction log backups that have made since last differential backup in correct sequence

RESTORE LOG *database* FROM DISK = 'D:/log1.bak' WITH NORECOVERY
RESTORE LOG *database* FROM DISK = 'D:/log2.bak' WITH NORECOVERY
RESTORE LOG *database* FROM DISK = 'D:/log3.bak' WITH NORECOVER

The last one transaction log backup that must be restored is the transaction log backup that have been made after the failure occurred with stopat option. After stopat option, you should set up the time to which you want to restore your database.

RESTORE LOG *database* FROM DISK = 'D:/log4.bak' WITH STOPAT = '2015-11-26 16:22:40.000', RECOVERY
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top