Skip to content

Commit 7ec0f53

Browse files
authored
Merge pull request #3240 from spurdata/issue_3234---sp_DatabaseRestore---support-@FileExtensionDiff
Added @FileExtensionDiff param. Fixes #3234.
2 parents 7b17027 + 04c9e6f commit 7ec0f53

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

sp_DatabaseRestore.sql

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ALTER PROCEDURE [dbo].[sp_DatabaseRestore]
3131
@DatabaseOwner sysname = NULL,
3232
@SetTrustworthyON BIT = 0,
3333
@Execute CHAR(1) = Y,
34+
@FileExtensionDiff NVARCHAR(128) = NULL,
3435
@Debug INT = 0,
3536
@Help BIT = 0,
3637
@Version VARCHAR(30) = NULL OUTPUT,
@@ -158,6 +159,16 @@ BEGIN
158159
@RunRecovery = 0,
159160
@Debug = 0;
160161
162+
--Restore just through the latest DIFF, ignoring logs, and using a custom ".dif" file extension
163+
EXEC dbo.sp_DatabaseRestore
164+
@Database = ''LogShipMe'',
165+
@BackupPathFull = ''D:\Backup\SQL2016PROD1A\LogShipMe\FULL\'',
166+
@BackupPathDiff = ''D:\Backup\SQL2016PROD1A\LogShipMe\DIFF\'',
167+
@RestoreDiff = 1,
168+
@FileExtensionDiff = ''dif'',
169+
@ContinueLogs = 0,
170+
@RunRecovery = 1;
171+
161172
-- Restore from stripped backup set when multiple paths are used. This example will restore stripped full backup set along with stripped transactional logs set from multiple backup paths
162173
EXEC dbo.sp_DatabaseRestore
163174
@Database = ''DBA'',
@@ -500,6 +511,13 @@ BEGIN
500511
END
501512
END
502513

514+
--File Extension cleanup
515+
IF @FileExtensionDiff LIKE '%.%'
516+
BEGIN
517+
IF @Execute = 'Y' OR @Debug = 1 RAISERROR('Removing "." from @FileExtensionDiff', 0, 1) WITH NOWAIT;
518+
SET @FileExtensionDiff = REPLACE(@FileExtensionDiff,'.','');
519+
END
520+
503521
SET @RestoreDatabaseID = DB_ID(@RestoreDatabaseName);
504522
SET @RestoreDatabaseName = QUOTENAME(@RestoreDatabaseName);
505523
SET @UnquotedRestoreDatabaseName = PARSENAME(@RestoreDatabaseName,1);
@@ -1044,9 +1062,15 @@ BEGIN
10441062
END
10451063
/*End folder sanity check*/
10461064
-- Find latest diff backup
1065+
IF @FileExtensionDiff IS NULL
1066+
BEGIN
1067+
IF @Execute = 'Y' OR @Debug = 1 RAISERROR('No @FileExtensionDiff given, assuming "bak".', 0, 1) WITH NOWAIT;
1068+
SET @FileExtensionDiff = 'bak';
1069+
END
1070+
10471071
SELECT TOP 1 @LastDiffBackup = BackupFile, @CurrentBackupPathDiff = BackupPath
10481072
FROM @FileList
1049-
WHERE BackupFile LIKE N'%.bak'
1073+
WHERE BackupFile LIKE N'%.' + @FileExtensionDiff
10501074
AND
10511075
BackupFile LIKE N'%' + @Database + '%'
10521076
AND

0 commit comments

Comments
 (0)