Skip to content

Commit

Permalink
Merge pull request #3443 from gdoddsy/issue_3429
Browse files Browse the repository at this point in the history
Update sp_DatabaseRestore.sql
  • Loading branch information
BrentOzar authored Feb 19, 2024
2 parents aa84eb9 + 9be50b1 commit 213f104
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions sp_DatabaseRestore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1635,32 +1635,31 @@ END;'
EXECUTE [dbo].[CommandExecute] @DatabaseContext = 'master', @Command = @sql, @CommandType = 'UPDATE', @Mode = 1, @DatabaseName = @UnquotedRestoreDatabaseName, @LogToTable = 'Y', @Execute = 'Y';
END;

-- If test restore then blow the database away (be careful)
IF @TestRestore = 1
BEGIN

IF @RunStoredProcAfterRestore IS NOT NULL AND LEN(LTRIM(@RunStoredProcAfterRestore)) > 0
BEGIN
PRINT 'Attempting to run ' + @RunStoredProcAfterRestore
SET @sql = N'EXEC ' + @RestoreDatabaseName + '.' + @RunStoredProcAfterRestore
IF @RunStoredProcAfterRestore IS NOT NULL AND LEN(LTRIM(@RunStoredProcAfterRestore)) > 0
BEGIN
PRINT 'Attempting to run ' + @RunStoredProcAfterRestore
SET @sql = N'EXEC ' + @RestoreDatabaseName + '.' + @RunStoredProcAfterRestore

IF @Debug = 1 OR @Execute = 'N'
BEGIN
IF @sql IS NULL PRINT '@sql is NULL when building for @RunStoredProcAfterRestore'
PRINT @sql
END
IF @Debug = 1 OR @Execute = 'N'
BEGIN
IF @sql IS NULL PRINT '@sql is NULL when building for @RunStoredProcAfterRestore'
PRINT @sql
END

IF @RunRecovery = 0
BEGIN
PRINT 'Unable to run Run Stored Procedure After Restore as database is not recovered. Run command again with @RunRecovery = 1'
END
ELSE
BEGIN
IF @Debug IN (0, 1) AND @Execute = 'Y'
EXEC sp_executesql @sql
END
END
IF @RunRecovery = 0
BEGIN
PRINT 'Unable to run Run Stored Procedure After Restore as database is not recovered. Run command again with @RunRecovery = 1'
END
ELSE
BEGIN
IF @Debug IN (0, 1) AND @Execute = 'Y'
EXEC sp_executesql @sql
END
END

-- If test restore then blow the database away (be careful)
IF @TestRestore = 1
BEGIN
SET @sql = N'DROP DATABASE ' + @RestoreDatabaseName + NCHAR(13);

IF @Debug = 1 OR @Execute = 'N'
Expand Down

0 comments on commit 213f104

Please sign in to comment.