0

I am trying to use sp_DatabaseRestore from the SQL Server First Responder Kit to restore some databases. It works fine if I first restore the database in a normal way using SSMS, but if the database does not previously exist, it says that it could not find the file specified (for both data an log-files).

It also ends with the following message:

The database "DatabaseName" does not exist. RESTORE can only create a database when restoring either a full backup or a file backup of the primary file.

But the first path is for the full backup, so I am not sure what this means.

Is there some particular use of the parameters that would help me use this even when the database does not exist, or am I forced to create them first?

Any suggestions appreciated.

Edit: Code that is used (paths and names have been changed). The code fails if the database does not exist. If I create the database, then it works:

DECLARE @VersionDate datetime;
EXEC dbo.sp_DatabaseRestore @Database = N'DatabaseName',                                
                            @BackupPathFull = N'\\SERVERNAME\Backup\servername-wfcs$ServerNameAG01\DatabaseName\FULL\',            
                            @BackupPathLog = N'\\SERVERNAME\Backup\servername-wfcs$ServerNameAG01\DatabaseName\LOG\',             
                            @MoveFiles = 0,                
                            @ContinueLogs = 0,             
                            @RunRecovery = 1,              
                            @ForceSimpleRecovery = 0,
                            @Debug = 0,
                            @VersionDate = @VersionDate OUTPUT

Edit 2: Turns out there was a difference in the data-file folder names between the old and the new server. The old server had a version-number lower than the actual version of the SQL Server, probably due to an earlier in place upgrade. When trying to restore from a backup with correct data folder, there is no problem.

  • The first googled link has an answer: brentozar.com/archive/2017/03/… – Denis Rubashkin Nov 6 '18 at 12:58
  • @DenisRubashkin Thanks for your comment. However I have read that documentation already (and once again now), and I can't really find anything there that answers my question. If you found the answer in there, I would appreciate it if you could narrow it down for me where to look in that link. – GHauan Nov 6 '18 at 13:16
  • Can you post the command you're using now that isn't working? – Erik Darling Nov 6 '18 at 13:18
  • 2
    Specify variables MoveFiles = 1, MoveDataDrive = YourDataLocation and MoveLogDrive = YourLogLocation" - I believe it should help – Denis Rubashkin Nov 6 '18 at 13:24
  • @sp_BlitzErik Hi Erik, I edited my post and added the code. – GHauan Nov 6 '18 at 13:27
0

Turns out there was a difference in the data-file folder names between the old and the new server. The old server had a version-number lower than the actual version of the SQL Server, probably due to an earlier in place upgrade. When trying to restore from a backup with correct data folder, there is no problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.