Skip to content

Commit 13cf617

Browse files
authored
Merge pull request #3047 from dalehhirt/dalehirt-MoveFiles
feat: Enable configuration item to allow data/log files to be moved …
2 parents 6bef93d + e365481 commit 13cf617

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

sp_AllNightLog.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ DECLARE @servercertificate NVARCHAR(MAX); --Config table: server certificate tha
124124
DECLARE @restore_path_base NVARCHAR(MAX); --Used to hold the base backup path in our configuration table
125125
DECLARE @restore_path_full NVARCHAR(MAX); --Used to hold the full backup path in our configuration table
126126
DECLARE @restore_path_log NVARCHAR(MAX); --Used to hold the log backup path in our configuration table
127+
DECLARE @restore_move_files INT; -- used to hold the move files bit in our configuration table
127128
DECLARE @db_sql NVARCHAR(MAX) = N''; --Used to hold the dynamic SQL to create msdbCentral
128129
DECLARE @tbl_sql NVARCHAR(MAX) = N''; --Used to hold the dynamic SQL that creates tables in msdbCentral
129130
DECLARE @database_name NVARCHAR(256) = N'msdbCentral'; --Used to hold the name of the database we create to centralize data
@@ -243,7 +244,17 @@ IF (@PollDiskForNewDatabases = 1 OR @Restore = 1) AND OBJECT_ID('msdb.dbo.restor
243244
END;
244245
245246
END /* IF CHARINDEX('**', @restore_path_base) <> 0 */
246-
247+
248+
SELECT @restore_move_files = CONVERT(BIT, configuration_setting)
249+
FROM msdb.dbo.restore_configuration c
250+
WHERE configuration_name = N'move files';
251+
252+
IF @restore_move_files is NULL
253+
BEGIN
254+
-- Set to default value of 1
255+
SET @restore_move_files = 1
256+
END
257+
247258
END /* IF @PollDiskForNewDatabases = 1 OR @Restore = 1 */
248259
249260
@@ -1324,6 +1335,7 @@ IF @Restore = 1
13241335
@ContinueLogs = 1,
13251336
@RunRecovery = 0,
13261337
@OnlyLogsAfter = @only_logs_after,
1338+
@MoveFiles = @restore_move_files,
13271339
@Debug = @Debug
13281340
13291341
END
@@ -1340,6 +1352,7 @@ IF @Restore = 1
13401352
@BackupPathLog = @restore_path_log,
13411353
@ContinueLogs = 0,
13421354
@RunRecovery = 0,
1355+
@MoveFiles = @restore_move_files,
13431356
@Debug = @Debug
13441357
13451358
END

sp_AllNightLog_Setup.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ALTER PROCEDURE dbo.sp_AllNightLog_Setup
2626
@Debug BIT = 0,
2727
@FirstFullBackup BIT = 0,
2828
@FirstDiffBackup BIT = 0,
29+
@MoveFiles BIT = 1,
2930
@Help BIT = 0,
3031
@Version VARCHAR(30) = NULL OUTPUT,
3132
@VersionDate DATETIME = NULL OUTPUT,
@@ -72,6 +73,7 @@ BEGIN
7273
* Holds variables used by stored proc to make runtime decisions
7374
* RTO: Seconds, how often to look for log backups to restore
7475
* Restore Path: The path we feed to sp_DatabaseRestore
76+
* Move Files: Whether to move files to default data/log directories.
7577
* dbo.restore_worker
7678
* Holds list of databases and some information that helps our Agent jobs figure out if they need to look for files to restore
7779
@@ -102,6 +104,7 @@ BEGIN
102104
@UpdateSetup BIT, defaults to 0. When set to 1, will update existing configs for RPO/RTO and database backup/restore paths.
103105
@RPOSeconds BIGINT, defaults to 30. Value in seconds you want to use to determine if a new log backup needs to be taken.
104106
@BackupPath NVARCHAR(MAX), This is REQUIRED if @Runsetup=1. This tells Ola''s job where to put backups.
107+
@MoveFiles BIT, defaults to 1. When this is set to 1, it will move files to default data/log directories
105108
@Debug BIT, defaults to 0. Whent this is set to 1, it prints out dynamic SQL commands
106109
107110
Sample call:
@@ -626,6 +629,8 @@ BEGIN
626629
INSERT msdb.dbo.restore_configuration (database_name, configuration_name, configuration_description, configuration_setting)
627630
VALUES ('all', 'log restore path', 'The path to which Log Restores come from.', @RestorePath);
628631

632+
INSERT msdb.dbo.restore_configuration (database_name, configuration_name, configuration_description, configuration_setting)
633+
VALUES ('all', 'move files', 'Determines if we move database files to default data/log directories.', @MoveFiles);
629634

630635
IF OBJECT_ID('msdb.dbo.restore_worker') IS NULL
631636

0 commit comments

Comments
 (0)