Skip to content

Commit

Permalink
Merge pull request #3431 from LukaszBiegus/dev
Browse files Browse the repository at this point in the history
Add FileNamePrefix parameter to sp_DatabaseRestore
  • Loading branch information
BrentOzar authored Feb 16, 2024
2 parents 02556f9 + 7d3add4 commit 2a710e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ Parameters include:
* @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.
* @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.
* @MoveFiles, @MoveDataDrive, @MoveLogDrive - if you want to restore to somewhere other than your default database locations.
* @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.
* @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.
* @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.
* @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.
Expand Down
5 changes: 3 additions & 2 deletions sp_DatabaseRestore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ ALTER PROCEDURE [dbo].[sp_DatabaseRestore]
@Help BIT = 0,
@Version VARCHAR(30) = NULL OUTPUT,
@VersionDate DATETIME = NULL OUTPUT,
@VersionCheckMode BIT = 0
@VersionCheckMode BIT = 0,
@FileNamePrefix NVARCHAR(260) = NULL
AS
SET NOCOUNT ON;
SET STATISTICS XML OFF;
Expand Down Expand Up @@ -791,7 +792,7 @@ BEGIN
WHEN Type = 'L' THEN @MoveLogDrive
WHEN Type = 'S' THEN @MoveFilestreamDrive
WHEN Type = 'F' THEN @MoveFullTextCatalogDrive
END + CASE
END + COALESCE(@FileNamePrefix, '') + CASE
WHEN @Database = @RestoreDatabaseName THEN REVERSE(LEFT(REVERSE(PhysicalName), CHARINDEX('\', REVERSE(PhysicalName), 1) -1))
ELSE REPLACE(REVERSE(LEFT(REVERSE(PhysicalName), CHARINDEX('\', REVERSE(PhysicalName), 1) -1)), @Database, SUBSTRING(@RestoreDatabaseName, 2, LEN(@RestoreDatabaseName) -2))
END AS TargetPhysicalName,
Expand Down

0 comments on commit 2a710e6

Please sign in to comment.