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?
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.
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
Related
Is it possible to rollback only with MDF and LDF files but without backup file?
I worked days but suddenly it's gone. It's important to me.
Yes, it is possible, but only if:
Your database is in full or bulk-logged recovery mode, and
You had taken at least one full backup prior to the point of failure, and
There is a complete chain of transaction log backups since the last full backup, or
There were no transaction log backups since then.
What you need to do is:
Take transaction log backup of your database;
Restore your last full backup as a new database with NO_RECOVERY option;
Restore all necessary transaction log backups, if any, again with NO_RECOVERY;
Restore the most recent transaction log backup you just made in #1 with RECOVERY and STOPAT options. In the latter, you can specify the exact time on which you want your database to be restored.
For full syntax, see RESTORE.
I have implemented Ola Hallengren's maintenance solution and transaction log backup is running every hour. I was going to perform restore test for one particular database today and noticed that although the database is in Full Recovery Mode there have been no transaction log backup taken. There were about 100 other databases running on this particular instance and about 95 of them had transaction log backups successfully taken.
I have just recently taken over this environment so I have no history as to how things have been set up or how these databases have been created.
When comparing the settings I against a database which was getting transaction log backup taken I see that the "Log Reuse Wait Description" is set to DATABASE_SNAPSHOT_CREATION for the database that does not have transaction log backup but LOG_BACKUP or NOTHING for those having successful transaction log backups taken.
I checked backup history and those that had transaction log backup today had history of successful backup last months but there was no history of any transaction log backup being taking for the databases that I am not seeing transaction log backup. I also checked and there are no long running transactions going on.
What should I check and how should I fix it so that the log backups start to generate for all the user databases?
And is there something I can do to prevent this from happening in future?
Thanks in advance!
When you restored the last full backup, the database was in simple recovery mode. Databases in simple recovery mode do not use transaction log backups. In order to do transaction log backups you need:
Database in Full Recovery mode.
At least one full backup after switching to Full Recovery mode.
Suppose I want to restore a database in such circumstances: from one side there is no backup,
from the other side - all the changes are stored in the log file.
Can I restore the database from the log file to a specific date & time?
You are talking about point in time recovery
for that you first need a full backup at least then if you take t-log backup you can restore. without full backup nothing possible
I have full weekly backups, daily differential backups and hourly transaction log backups.
To restore the database, I restore the full backup, then the last dif backup then all the transaction log backups specifying NORECOVERY on all the restores except the last one.
My question is. If I accidently restore my last transaction log with the NORECOVERY flag set, is there a command I can run to "RECOVER" the database at this point?
I'm using SQL Server 2005.
Ok, so the answer is fairly simple. You can simply run the command.
RESTORE DATABASE [MyDatabase] WITH RECOVERY
It didn't even occur to me that you can run the RESTORE DATABASE command without specifying a backup to restore from.
Try this (from SQL2000 help):
RESTORE DATABASE dbname WITH RECOVERY
I'm planning to set up log shipping to a remote site for disaster recovery but I still want to take a nightly full backup so I can copy it to our backup tape and also use it to restore onto our reporting server. Can I do that without breaking the cycle of log backups?
Yes you can. You start the log shipping process from a restore of a full backup, and from then on you only need to restore transaction log backups. You can take as many diffs or full backups as you like and it doesn't affect the LSN and therefore does not interfere with the log shipping process as long as the logs are restored in order.
Here's the SQL Backup overview
http://msdn.microsoft.com/en-us/library/ms175477(SQL.90).aspx
FULL, and DIFFERENTIAL backups do not break the LSN log chain, so you are safe to take these backup anytime without affecting the log shipping