Hello all. Is there a way I can backup my sql jobs because a machine we are currently running is starting to look bleak. I just need the SQL jobs on the machine backed up. Thanks all
Here is a "Job" you can create and run that will script all of your jobs at once. You will need to change the "MyDB" to reflect your server name. It creates a file called c:\JOBS.sql.
Enjoy!
====================================
BEGIN TRANSACTION
DECLARE @JobID BINARY(16)
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF (SELECT COUNT(*) FROM msdb.dbo.syscategories WHERE name = N'Personal Scripts') < 1
EXECUTE msdb.dbo.sp_add_category @name = N'Personal Scripts'
-- Delete the job with the same name (if it exists)
SELECT @JobID = job_id
FROM msdb.dbo.sysjobs
WHERE (name = N'Script All Jobs')
IF (@JobID IS NOT NULL)
BEGIN
-- Check if the job is a multi-server job
IF (EXISTS (SELECT *
FROM msdb.dbo.sysjobservers
WHERE (job_id = @JobID) AND (server_id <> 0)))
BEGIN
-- There is, so abort the script
RAISERROR (N'Unable to import job ''Script All Jobs'' since there is already a multi-server job with this name.', 16, 1)
GOTO QuitWithRollback
END
ELSE
-- Delete the [local] job
EXECUTE msdb.dbo.sp_delete_job @job_name = N'Script All Jobs'
SELECT @JobID = NULL
END
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.