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)
Related
Is it possible to restore a SQL Server .bak file to any time earlier than the time of last backup taken?
I can successfully restore a .bak file to the last backup taken. That looks like this. The backup set automatically appears.
However, I want to restore to a point in time before the latest available (to a time before an accidental deletion of some item in that database). So I select Timeline and set as follows. The inverted triangle is the only one in the entire timeline.
But then, I can't restore, I get an error
No backupset selected to be restored
I'm running SSMS as Administrator, using SQL Server 2017 Developer edition here. The original database was on SQL Server 2012.
Below the response from documentation:
A specified time is always restored from a log backup. In every
RESTORE LOG statement of the restore sequence, you must specify your
target time or transaction in an identical STOPAT clause. As a
prerequisite to a point-in-time restore, you must first restore a full
database backup whose end point is earlier than your target restore
time. That full database backup can be older than the most recent full
database backup as long as you then restore every subsequent log
backup, up to and including the log backup that contains your target
point in time.
For more details look here
So i have read Microsoft etc and am struggling to understand the difference in Point in time recovery and complete recovery (i.e. seems to do the same thing, slightly differently).
I.e. when should i use one as opposed to the other, from what i can see i should always use point in time if i have a full backup model?.
Point in time recovery is where you wanted to restore database to specific time of the date, for example some records accidentally deleted at 3:45PM from database and log backup runs every 30 minutes, this is where you can restore database to 3:45PM using Log backups and STOPAT.
RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK'
WITH NORECOVERY
GO
RESTORE LOG AdventureWorks FROM DISK = 'C:\AdventureWorks.TRN'
WITH RECOVERY,
STOPAT = 'Mar 01, 2017 03:45:00 PM'
GO
Whereby complete recovery is something you can recover database from backups (full/differential) to the last or specific date/time log backup.
I have a SQL Server 2005 .BAK file (created with a maintenance plan) that I am trying to restore into a different instance of SQL Server 2005.
Regardless of whether I use the UI or RESTORE DATABASE, the restore process seems to halt at 99%. If I use RESTORE VERIFYONLY FROM DISK='mybackup.bak' it reports that my backup is valid.
Interestingly, immediately after I start the restore process, a 43 GB transaction log file appears in my MSSQL\DATA directory. The .BAK file is 60 MB. The system has more than enough free space for this recovery.
Any suggestions on other restore strategies I should try? I'm going to let the restore run overnight and see what happens.
Thanks
If you have a 43Gb transaction log, depending on the speed of your disks, the restore will take a while. What that means is that when you backed up your db, it had a 43Gb log file and it was empty. So when you restore, the SQL Server has to go and allocate 43Gb for the log file, and it has to physically go and zero out 43Gb, and this takes a while.
What I suggest is to wait a while for restore to complete, couple hours maybe, or do a transaction log backup on production, then shrink the trans log file to say 100Mb and then do a backup, and restore from that.
IT is very important to understand recovery models, and backup models used. Dont just slap a db on production and let it run, if you dont manage it, you will end up with big problems.
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.
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