SQL Server 2005 Perform "RECOVERY" on database restored with "NORECOVERY" - sql-server

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

Related

Restoring Daily Differential Backup - No Files Are Ready To Rollforward Issue

I use SQL Server. There is a problem with my differential backups. I take full backup of my database at the end of the week and beside, i also take differential backup of the database daily. I have created a job which makes these backing up tasks automatically. After taking those full and diff bakcups, i restore them with a job schudelar every day & week. My full restore job task works successfully every week but when my other task,which is restoring daily differential backup, try to work, it fails with " The log or differential backup cannot be restored because no files are ready to rollforward. " error message.
I have two database servers. One of them is production server and the other one is reporting server. Reporting server contains the same database in the production db server. At the end of every week, I take full back up of the db in prodcution db server for reporting server. In the same way, every midnight, i also take differential back up of the db in prodcution server for reporting server. Next day,I restore the last diff back up to the db in the reporting server. I use visual cron tool for the process but it has failed with that error. I tried to restore manual but got same error message.
Here is my restoring commands.
EXEC [dbo].[DatabaseRestoreMany]
#Databases = 'DB_2004',
#BackupRoot = '\\BCKPSRVR\BKUP\',
#BackupTypes = 'DIFF',
#DataFileDirectory = 'D:\DBFILES\DB_2004\',
#LogFileDirectory = 'D:\DBFILES\DB_2004\',
#DirectoryPerDatabase = 'Y',
#RecoveryState = 'STANDBY',
#ReturnBackupList = 'N',
#ReturnTaskList = 'N',
#Execute = 'Y'
How can i solve this issue? Can you help me?
Thank you in advance.
You've got this error because no full backup was restored prior to your restore from differential backup.
Today is wednesday. I had restored the full back up of the db on
sunday.
You restored your full backup with recovery. Your database became operational, it's online, and no more log or differential backup can be restored now.
In order to restore your differential backup you should first restore your full backup with norecovery, and only then you can restore your differential backup.
Please refer this BOL article to understand how differential backup can be restored: Restore a Differential Database Backup (SQL Server)
To restore a differential database backup
Execute the RESTORE DATABASE
statement, specifying the NORECOVERY clause, to restore the full
database backup that comes before the differential database backup.
For more information, see How to: Restore a Full Backup.
Execute the RESTORE DATABASE statement to restore the differential
database backup, specifying:
The name of the database to which the differential database backup is
applied.
The backup device where the differential database backup is restored
from.
The NORECOVERY clause if you have transaction log backups to apply
after the differential database backup is restored. Otherwise, specify
the RECOVERY clause.

How to rollback database only with MDF and LDF files but without backup file?

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.

Difficulty restoring a differential backup in SQL Server, 2 media families are expected or no files are ready for rollforward

I have sql backups copied from server A to server B on a nightly basis.
We want to move the sql server from server A to server B without much downtime, but the files are very large.
I assumed that performing a differential backup and restore would solve the problem with the databases.
Copy full backup from server A to copy to server B (10+gb)
Open SQL Server Managment Studio on server B
Right mouse on databases
Restore Database
Type in the new DB-name
Choose "From Device" and browse to the backup file
Click Okay. This is now resorting the original "full" backup.
Test new db with dev application - everything works :)
On original database rightmouse on DB > Tasks > Backup...
Backup Type = Differential, Backup to disk, add a new file, and remove the old one (it needs to be a small file to transfer for the smallest amount of outage)
Copy the diff backup onto the new db
Right mouse on DB > Tasks > Restore > Database
This is where I get stuck. If I add both the new differential file, and the original backup to the restore process I get an error
The media loaded on "M:\path\to\backup\full.bak" is formatted to support 1 media families, but 2 media families are expected according to the backup device specification.
RESTORE HEADERONLY is terminating abnormally.
But if I try to restore using just the differential file I get
System.Data.SqlClient.SqlError: The log or differential backup cannot be restored because no files are ready to rollforward. (Microsoft.SqlServer.Smo)
Any idea how to do it? Is there a better way of restoring backups with limited downtime?
See 2008 Books Online Performing a Complete Database Restore for details and code.
Perhaps the error is caused by both full and differential backups trying to be restored at once by the backup device specification (may need to be changed).
Do them one at a time (basic idea):
Create tail_log backup.
Restore full first, with NORECOVERY.
Restore differential, with NORECOVERY.
Restore log, with NORECOVERY.
Restore tail_log, with NORECOVERY.
Then, when all done, Restore with RECOVERY.

SQL Server LOG Data recovery

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

Restore to a point in time

I copied over the mdf and ldf for a database (Sql 2005 Express) to my machine and in my Sql 2005 (Developer Edition) attached them. I had set the logging in the source machine to full since I need to research an issue.
Now, in my SQL Server I have 2 database, DAProd that I just attached and DARestore that I just created. I want to restore DARestore with a point in time version of DAProd. When I bring up the Restore dialog, it does not show DAProd in the source dropdown. Any pointers will be appreciated.
Thanks.
I assume you have the backup of DAProd (both full and log). You don't need to attach a copy of DAProd, the backup process can create the 'copy' database for you. But is OK if you did attach it, won't matter.
First you run a restore of your most recent full backup of DAProd that is older than the moment in time you want to stop the recovery:
RESTORE DATABASE [DAProd] FROM DISK = '<yourfullbackup>' WITH NORECOVERY;
Next you start to recover the LOG backup that occurred after the full backup but are still prior to the moment in time, one by one:
RESTORE LOG [DAprod] FROM DISK = 'yournextlog' WITH NORECOVERY;
Now you restore the log that contains the moment in time you want to stop:
RESTORE LOG [DAProd] FROM DISK = 'yournextlog' WITH STOPAT = '<timetostop';
The final step is to take the DAProd database online. BTW this will rollback any uncommitted transaction 'in flight' at your moment in time:
ALTER DATABASE [DAProd] SET ONLINE;
You can now look at the database as it was in the moment in time you wish, as if it would roll back any pending transaction at that moment.
In order to perform a point in time restore, you need the various point in time backups of DAProd, not a current copy of DB reattached.
Please See How to: Restore to a Point in Time (SQL Server Management Studio)
Also: Point in Time Recovery
How to: Restore a Database Backup (SQL Server Management Studio)

Resources