Based loosely on Example E in the documentation, open a new query window and run:
RESTORE DATABASE MyDB_Copy FROM DISK = 'C:\blahblah\MyDB.bak'
WITH REPLACE, RECOVERY,
MOVE 'MyDB' TO 'C:\blahblah\Data\MyDB_Copy.mdf',
---------------------------------------^^^^^
MOVE 'MyDB_log' TO 'C:\blahblah\Data\MyDB_Copy.ldf';
-------------------------------------------^^^^^
The logical names are not important; the physical file names are. This makes assumptions about your logical file names and that there are only two; run EXEC MyDB..sp_helpfile;
to be sure.
If you need to restore logs, then change RECOVERY
to NORECOVERY
:
WITH REPLACE, NORECOVERY,
----------------^^
Then you can issue a series of:
RESTORE LOG MyDB_Copy FROM DISK = 'C:\blahblah\file1.trn' WITH NORECOVERY;
And on the very last one:
RESTORE LOG MyDB_Copy FROM DISK = 'C:\blahblah\fileN.trn' WITH RECOVERY;
Or if you only need part of a log up until a point in time (I assume you've checked where the LSNs and times are so you know exactly which files you need):
RESTORE LOG MyDB_Copy FROM DISK = 'C:\blahblah\fileN.trn' WITH
STOPAT = '<some point in time Friday>', RECOVERY;
The way you said worked in previous versions would never have worked, unless the backup came from a different server. By default it will try to put the new mdf and ldf files in the exact same place, and this isn't possible.
That won't work. As soon as you recover the database after restore, that begins a new timeline for the database.
If this is an on-going process, one possible solution is to get the team generating the backups to take a differential every day which will have fairly low impact on effort and system load. This is in addition to what they currently have. However, it will require some careful management of the files to ensure you have the right sequence of full backup, differential and tlogs. The benefit is, you will not have more than the 20 tlog files to apply if you ever need to restore the database to the latest version. You also don't lose existing PITR based on the 15-20 tlog backups taken daily (I'm assuming there is some PITR requirement given the number of log backups).
If you want to further reduce the number of log files to apply, you can increase the number of differential backups per day but I'd wager the added complexity in managing the files far outweighs the benefits. If you script all your tasks (sounds like you are), execution and scrutinizing for issues is fairly easy to do. If you're using the SSMS GUI, well, you really shouldn't.
** To make it clear, this assumes you already reset the backup chain with a full database backup at some interval. Having just a single full DB backup and only taking differentials and tlog backups from there on is not a viable solution. In most situations, the differential will eventually grow to a large size, possibly bigger than the base (full DB) backup if you have lots of write activities. An example of a basic backup cycle might look like:
- Full DB backup - every Sunday 2am
- Differential DB backup - every day
- 8pm Transaction log backup - every 15minutes
This cycle has potential data loss of up to 15 minutes if there are no other protections (e.g. AlwaysOn) in place.
If this is just a 1-time thing, i.e. you won't get any more tlog backups then you could reduce your recovery time when the goal is to get to the latest point-in-time available. Just restore the DB, differential and apply all the logs. Once done, take a backup of that and keep it along with all the other backup files you have. This buys you rapid recovery when you need to get to the latest version available since you only need to do a single DB restore. However, don't delete all the other backup files in case you need to restore to a specific point-in-time other than the most recent.
Best Answer
No, you need to have taken transaction logs that cover the time frame you want to use with
STOPAT
. You can't do this from a full database backup only - that is just a one-time copy, and that is why we have different types of backups (full, log, diff).If you have taken transaction log backups in between your full backups, please update the question with that information, and we can show you steps for restoring to a point in time. But those tutorials are easy to find, so I suspect you're asking here because you haven't taken log backups. If that is the case, you're kind of stuck - you may be able to use some kind of log reading utility to get at that information from the current transaction log, but I wouldn't be confident about success there - and it doesn't seem like that product, at least, has a feature called "restore to point in time" - it allows you to recover specific pieces of information, like restoring a table or undoing a truncate. So I think that would be quite a manual "undo transaction A, undo transaction B, undo transaction C, etc etc" to get at your eventual result. Probably still less work than trying to do that yourself from
fn_dblog
output.This post is rather timely:
And these may be useful too:
To demonstrate that you can't now take a log backup and try to restore to some point in time prior to the last full backup. First, run this script:
The above simulates what you have: a full backup, taken after the time you want to restore to, and that's it.
Now, take a tail-log backup:
Now, let's start the recovery process. First, restore the full backup with norecovery:
Now, attempt to restore the tail-log backup with the
STOPAT
parameter set to whatever was output above forGETDATE()
:I get the following error messages:
In order to restore to a point in time, you need to have taken at least one transaction log backup after a full backup (not necessarily after the last full backup, but after one that is valid and can be restored), and after the point in time you want to restore to (but before the next full database backup).
This is why we typically take full backups nightly or weekly, and transaction log backups every 15 minutes or every hour (and sometimes diff/filegroup backups in there too, depending on business needs, RTO/RPO, etc). In full recovery model there is certainly no use case where you'd want to take a full backup once a week, and nothing in between. This can be a very expensive lesson to learn the hard way, but I bet it doesn't happen to you twice.
This post probably has a lot of useful points about backups, why we take them, the usefulness of log backups, etc. - I highly recommend bookmarking it and giving it a thorough read once you solve your current problem.