0

I want to restore a database to 12/29/2016. I want to restore to another name so I do not lose the state of the original database. The name of my database is APDatabase.

How do I modify the SQL below to restore to a database called TempAPDatabase? I also want to be careful not to lose any of the backup information which is stored on the disk as 87A991B1-9305-45C1-A461-9B1A3174A707.

USE [master]

BACKUP LOG [APDatabase] 
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MYSQLSERVER\MSSQL\Backup\APDatabase_LogBackup_2017-03-13_10-52-54.bak' 
WITH NOFORMAT, NOINIT,  
     NAME = N'APDatabase_LogBackup_2017-03-13_10-52-54', 
     NOSKIP, NOREWIND, NOUNLOAD,  NORECOVERY, STATS = 5

RESTORE DATABASE [APDatabase] 
FROM DISK = N'{87A991B1-9305-45C1-A461-9B1A3174A707}10' 
WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5

RESTORE LOG [APDatabase] 
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MYSQLSERVER\MSSQL\Backup\APDatabase_LogBackup_2017-03-10_06-47-10.bak' 
WITH FILE = 1, NOUNLOAD, STATS = 5, STOPAT = N'2016-12-29T00:00:00'
GO
2

1 Answer 1

1

Assuming the rest of your command is correct, you just need to state the new name as the database you're restoring.

RESTORE DATABASE [TempAPDatabase] 
FROM DISK = N'{87A991B1-9305-45C1-A461-9B1A3174A707}10' 
WITH FILE = 1, NORECOVERY, NOUNLOAD, STATS = 5

RESTORE LOG [TempAPDatabase] 
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MYSQLSERVER\MSSQL\Backup\APDatabase_LogBackup_2017-03-10_06-47-10.bak' 
WITH FILE = 1, NOUNLOAD, STATS = 5, STOPAT = N'2016-12-29T00:00:00'
GO
Sign up to request clarification or add additional context in comments.

5 Comments

Is the BACKUP LOG (the first 5 lines) part of my SQL necessary?
Simple question, long winded answer. At somepoint in the past you'll need to run the Backup command, but the BACKUP LOG portion is not actually required to run restore. As long as you already have the BACKUPs created, you can restore them. However, it is a good idea to backup the Log just before the restore so you get the most update to date data in your restore.
Okay. Thank you for your help. One last thing. What's up with the GUID instead of an actual file name?
Don't know, I just copied your statement. I haven't used a GUID in a Restore command previously.
If you are copying the database to another location, make sure you verify the options. A backup for a copy should be treated differently than a backup for recovery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.