Skip to content

Commit e5a589e

Browse files
authored
Merge pull request BrentOzarULTD#3034 from nick-fotopoulos/ola-same-location
Ola Hallengren scripts must be installed in the same database as Firs…
2 parents b7c458f + 3d38c7c commit e5a589e

3 files changed

Lines changed: 31 additions & 17 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ For more information about how this works, see [sp_AllNightLog documentation.](h
494494
Known issues:
495495

496496
* The msdbCentral database name is hard-coded.
497-
* sp_AllNightLog depends on Ola Hallengren's DatabaseBackup, which must be installed separately. (We're not checking for it right now.)
497+
* sp_AllNightLog depends on Ola Hallengren's DatabaseBackup, which must be installed separately. (We expect it to be installed in the same database as the SQL Server First Responder Kit.)
498498

499499

500500
[*Back to top*](#header1)

‎sp_AllNightLog.sql‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,28 @@ IF NOT EXISTS (SELECT * FROM sys.configurations WHERE name = 'xp_cmdshell' AND v
165165
END
166166

167167
/*
168-
Make sure Ola Hallengren's scripts are installed in master
168+
Make sure Ola Hallengren's scripts are installed in same database
169169
*/
170-
IF 2 <> (SELECT COUNT(*) FROM master.sys.procedures WHERE name IN('CommandExecute', 'DatabaseBackup'))
170+
DECLARE @CurrentDatabaseContext nvarchar(128) = DB_NAME();
171+
IF NOT EXISTS (SELECT * FROM sys.procedures WHERE name = 'CommandExecute')
171172
BEGIN
172-
RAISERROR('Ola Hallengren''s CommandExecute and DatabaseBackup must be installed in the master database. More info: http://ola.hallengren.com', 0, 1) WITH NOWAIT
173+
RAISERROR('Ola Hallengren''s CommandExecute must be installed in the same database (%s) as SQL Server First Responder Kit. More info: http://ola.hallengren.com', 0, 1, @CurrentDatabaseContext) WITH NOWAIT;
174+
175+
RETURN;
176+
END
177+
IF NOT EXISTS (SELECT * FROM sys.procedures WHERE name = 'DatabaseBackup')
178+
BEGIN
179+
RAISERROR('Ola Hallengren''s DatabaseBackup must be installed in the same database (%s) as SQL Server First Responder Kit. More info: http://ola.hallengren.com', 0, 1, @CurrentDatabaseContext) WITH NOWAIT;
173180

174181
RETURN;
175182
END
176183

177184
/*
178-
Make sure sp_DatabaseRestore is installed in master
185+
Make sure sp_DatabaseRestore is installed in same database
179186
*/
180-
IF NOT EXISTS (SELECT * FROM master.sys.procedures WHERE name = 'sp_DatabaseRestore')
187+
IF NOT EXISTS (SELECT * FROM sys.procedures WHERE name = 'sp_DatabaseRestore')
181188
BEGIN
182-
RAISERROR('sp_DatabaseRestore must be installed in master. To get it: http://FirstResponderKit.org', 0, 1) WITH NOWAIT
189+
RAISERROR('sp_DatabaseRestore must be installed in the same database (%s) as SQL Server First Responder Kit. To get it: http://FirstResponderKit.org', 0, 1, @CurrentDatabaseContext) WITH NOWAIT;
183190

184191
RETURN;
185192
END
@@ -912,7 +919,7 @@ LogShamer:
912919
*/
913920

914921
IF @encrypt = 'Y'
915-
EXEC master.dbo.DatabaseBackup @Databases = @database, --Database we're working on
922+
EXEC dbo.DatabaseBackup @Databases = @database, --Database we're working on
916923
@BackupType = 'LOG', --Going for the LOGs
917924
@Directory = @backup_path, --The path we need to back up to
918925
@Verify = 'N', --We don't want to verify these, it eats into job time
@@ -925,7 +932,7 @@ LogShamer:
925932
@ServerCertificate = @servercertificate;
926933

927934
ELSE
928-
EXEC master.dbo.DatabaseBackup @Databases = @database, --Database we're working on
935+
EXEC dbo.DatabaseBackup @Databases = @database, --Database we're working on
929936
@BackupType = 'LOG', --Going for the LOGs
930937
@Directory = @backup_path, --The path we need to back up to
931938
@Verify = 'N', --We don't want to verify these, it eats into job time
@@ -1311,7 +1318,7 @@ IF @Restore = 1
13111318
13121319
IF @Debug = 1 RAISERROR('Starting Log only restores', 0, 1) WITH NOWAIT;
13131320
1314-
EXEC master.dbo.sp_DatabaseRestore @Database = @database,
1321+
EXEC dbo.sp_DatabaseRestore @Database = @database,
13151322
@BackupPathFull = @restore_path_full,
13161323
@BackupPathLog = @restore_path_log,
13171324
@ContinueLogs = 1,
@@ -1328,7 +1335,7 @@ IF @Restore = 1
13281335
IF @Debug = 1 RAISERROR('Starting first Full restore from: ', 0, 1) WITH NOWAIT;
13291336
IF @Debug = 1 RAISERROR(@restore_path_full, 0, 1) WITH NOWAIT;
13301337
1331-
EXEC master.dbo.sp_DatabaseRestore @Database = @database,
1338+
EXEC dbo.sp_DatabaseRestore @Database = @database,
13321339
@BackupPathFull = @restore_path_full,
13331340
@BackupPathLog = @restore_path_log,
13341341
@ContinueLogs = 0,

‎sp_AllNightLog_Setup.sql‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,21 +264,28 @@ IF NOT EXISTS (SELECT * FROM sys.configurations WHERE name = 'xp_cmdshell' AND v
264264
END
265265

266266
/*
267-
Make sure Ola Hallengren's scripts are installed in master
267+
Make sure Ola Hallengren's scripts are installed in same database
268268
*/
269-
IF 2 <> (SELECT COUNT(*) FROM master.sys.procedures WHERE name IN('CommandExecute', 'DatabaseBackup'))
269+
DECLARE @CurrentDatabaseContext nvarchar(128) = DB_NAME();
270+
IF NOT EXISTS (SELECT * FROM sys.procedures WHERE name = 'CommandExecute')
270271
BEGIN
271-
RAISERROR('Ola Hallengren''s CommandExecute and DatabaseBackup must be installed in the master database. More info: http://ola.hallengren.com', 0, 1) WITH NOWAIT
272+
RAISERROR('Ola Hallengren''s CommandExecute must be installed in the same database (%s) as SQL Server First Responder Kit. More info: http://ola.hallengren.com', 0, 1, @CurrentDatabaseContext) WITH NOWAIT;
273+
274+
RETURN;
275+
END
276+
IF NOT EXISTS (SELECT * FROM sys.procedures WHERE name = 'DatabaseBackup')
277+
BEGIN
278+
RAISERROR('Ola Hallengren''s DatabaseBackup must be installed in the same database (%s) as SQL Server First Responder Kit. More info: http://ola.hallengren.com', 0, 1, @CurrentDatabaseContext) WITH NOWAIT;
272279

273280
RETURN;
274281
END
275282

276283
/*
277-
Make sure sp_DatabaseRestore is installed in master
284+
Make sure sp_DatabaseRestore is installed in same database
278285
*/
279-
IF NOT EXISTS (SELECT * FROM master.sys.procedures WHERE name = 'sp_DatabaseRestore')
286+
IF NOT EXISTS (SELECT * FROM sys.procedures WHERE name = 'sp_DatabaseRestore')
280287
BEGIN
281-
RAISERROR('sp_DatabaseRestore must be installed in master. To get it: http://FirstResponderKit.org', 0, 1) WITH NOWAIT
288+
RAISERROR('sp_DatabaseRestore must be installed in the same database (%s) as SQL Server First Responder Kit. To get it: http://FirstResponderKit.org', 0, 1, @CurrentDatabaseContext) WITH NOWAIT;
282289

283290
RETURN;
284291
END

0 commit comments

Comments
 (0)