Using T-SQL or Powershell, how can I create a stored procedure that performs the following:
- Copy a SQL Server Agent Job to another backup Job on the same server (with a new name)
-
Disable the backup job so that it is not scheduled.
USE msdb; IF object_id('[backupSQLServerJob]') IS NULL EXEC ('create procedure [backupSQLServerJob] as select 1') GO ALTER PROCEDURE backupSQLServerJob @JobName varchar(50) AS BEGIN DECLARE @BackupName VARCHAR(100) = CONCAT(@JobName, '_bak_', CONVERT(VARCHAR(10), GETDATE(), 112)); IF EXISTS (SELECT * FROM dbo.sysjobs WHERE name = @JobName) BEGIN -- What goes here? END END
The solution needs to work on SQL Server 2008 – 2014
Best Answer