Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally add Job prefix to created jobs #620

Open
JungleGeorge opened this issue Feb 11, 2022 · 1 comment
Open

Optionally add Job prefix to created jobs #620

JungleGeorge opened this issue Feb 11, 2022 · 1 comment

Comments

@JungleGeorge
Copy link

In the Maintenance Solution add a variable used to create all jobs with a common prefix. I provided some sample code I used. The new lines are in BOLD. I did not add all of the jobs in the sample and the AWS portion is just a best guess.

DECLARE @JobPrefix nvarchar(max) = 'DBA--' -- Specify Job Prefix. Default is ''.

INSERT INTO #Config ([Name], [Value]) VALUES('CreateJobs', @CreateJobs)
INSERT INTO #Config ([Name], [Value]) VALUES('JobPrefix', @JobPrefix)

IF (SELECT [Value] FROM #Config WHERE Name = 'CreateJobs') = 'Y' AND SERVERPROPERTY('EngineEdition') NOT IN(4, 5) AND (IS_SRVROLEMEMBER('sysadmin') = 1 OR (DB_ID('rdsadmin') IS NOT NULL AND SUSER_SNAME(0x01) = 'rdsa')) AND (SELECT [compatibility_level] FROM sys.databases WHERE database_id = DB_ID()) >= 90
BEGIN

DECLARE @JobPrefix nvarchar(100)
SELECT @JobPrefix = [Value] FROM #Config WHERE Name = 'JobPrefix'

INSERT INTO @Jobs ([Name], CommandTSQL, DatabaseName, OutputFileNamePart01, OutputFileNamePart02)
SELECT @JobPrefix + 'DatabaseBackup - SYSTEM_DATABASES - FULL',

IF @AmazonRDS = 1
BEGIN
UPDATE @Jobs
SET Selected = 1
WHERE [Name] IN(@JobPrefix + 'DatabaseIntegrityCheck - USER_DATABASES',@JobPrefix + 'IndexOptimize - USER_DATABASES',@JobPrefix + 'CommandLog Cleanup')

@bwiggins10
Copy link

Why not just script out renaming the job and have it run after you deploy the OLA Jobs? Something like:
USE [msdb] GO EXEC msdb.dbo.sp_update_job @job_name=N'CommandLog Cleanup', @new_name=N'_MAINT_CommandLog Cleanup',@enabled=1 GO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants