Skip to content

Commit 2a710e6

Browse files
authored
Merge pull request #3431 from LukaszBiegus/dev
Add FileNamePrefix parameter to sp_DatabaseRestore
2 parents 02556f9 + 7d3add4 commit 2a710e6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ Parameters include:
513513
* @BackupPathFull - typically a UNC path like '\\\\FILESERVER\BACKUPS\SQL2016PROD1A\LogShipMe\FULL\' that points to where the full backups are stored. Note that if the path doesn't exist, we don't create it, and the query might take 30+ seconds if you specify an invalid server name.
514514
* @BackupPathDiff, @BackupPathLog - as with the Full, this should be set to the exact path where the differentials and logs are stored. We don't append anything to these parameters.
515515
* @MoveFiles, @MoveDataDrive, @MoveLogDrive - if you want to restore to somewhere other than your default database locations.
516+
* @FileNamePrefix - Prefix to add to the names of all restored files. Useful when you need to restore different backups of the same database into the same directory.
516517
* @RunCheckDB - default 0. When set to 1, we run Ola Hallengren's DatabaseIntegrityCheck stored procedure on this database, and log the results to table. We use that stored proc's default parameters, nothing fancy.
517518
* @TestRestore - default 0. When set to 1, we delete the database after the restore completes. Used for just testing your restores. Especially useful in combination with @RunCheckDB = 1 because we'll delete the database after running checkdb, but know that we delete the database even if it fails checkdb tests.
518519
* @RestoreDiff - default 0. When set to 1, we restore the ncessary full, differential, and log backups (instead of just full and log) to get to the most recent point in time.

sp_DatabaseRestore.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ ALTER PROCEDURE [dbo].[sp_DatabaseRestore]
3838
@Help BIT = 0,
3939
@Version VARCHAR(30) = NULL OUTPUT,
4040
@VersionDate DATETIME = NULL OUTPUT,
41-
@VersionCheckMode BIT = 0
41+
@VersionCheckMode BIT = 0,
42+
@FileNamePrefix NVARCHAR(260) = NULL
4243
AS
4344
SET NOCOUNT ON;
4445
SET STATISTICS XML OFF;
@@ -791,7 +792,7 @@ BEGIN
791792
WHEN Type = 'L' THEN @MoveLogDrive
792793
WHEN Type = 'S' THEN @MoveFilestreamDrive
793794
WHEN Type = 'F' THEN @MoveFullTextCatalogDrive
794-
END + CASE
795+
END + COALESCE(@FileNamePrefix, '') + CASE
795796
WHEN @Database = @RestoreDatabaseName THEN REVERSE(LEFT(REVERSE(PhysicalName), CHARINDEX('\', REVERSE(PhysicalName), 1) -1))
796797
ELSE REPLACE(REVERSE(LEFT(REVERSE(PhysicalName), CHARINDEX('\', REVERSE(PhysicalName), 1) -1)), @Database, SUBSTRING(@RestoreDatabaseName, 2, LEN(@RestoreDatabaseName) -2))
797798
END AS TargetPhysicalName,

0 commit comments

Comments
 (0)