Skip to content

Commit 3f030b3

Browse files
authored
Merge pull request #1190 from ShawnCrocker/issue_1180
sp_DatabaseRestore - Add option to force simple recovery model #1180
2 parents 5986d74 + 13a26a0 commit 3f030b3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

sp_DatabaseRestore.sql

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ALTER PROCEDURE [dbo].[sp_DatabaseRestore]
1616
@RestoreDiff BIT = 0,
1717
@ContinueLogs BIT = 0,
1818
@RunRecovery BIT = 0,
19+
@ForceSimpleRecovery BIT = 0,
1920
@StopAt NVARCHAR(14) = NULL,
2021
@OnlyLogsAfter NVARCHAR(14) = NULL,
2122
@Debug INT = 0,
@@ -901,7 +902,21 @@ IF @RunRecovery = 1
901902
IF @Debug IN (0, 1)
902903
EXECUTE sp_executesql @sql;
903904
END;
904-
905+
906+
-- ensure simple recovery model
907+
IF @ForceSimpleRecovery = 1
908+
BEGIN
909+
SET @sql = N'ALTER DATABASE ' + @RestoreDatabaseName + N' SET RECOVERY SIMPLE' + NCHAR(13);
910+
911+
IF @Debug = 1
912+
BEGIN
913+
IF @sql IS NULL PRINT '@sql is NULL for SET RECOVERY SIMPLE: @RestoreDatabaseName';
914+
PRINT @sql;
915+
END;
916+
917+
IF @Debug IN (0, 1)
918+
EXECUTE sp_executesql @sql;
919+
END;
905920

906921
--Run checkdb against this database
907922
IF @RunCheckDB = 1

0 commit comments

Comments
 (0)