Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Back SQL Agent Jobs Expand / Collapse
Author
Message
Posted Wednesday, January 16, 2008 6:08 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
Hi All
I need to back up all the Agent Jobs i have on my servers, is there some ways to automate this process, rather than go into the Enterprise manager, script the job and then save it

Please post your suggestions :)
Post #443559
Posted Wednesday, January 16, 2008 9:08 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 9:23 AM
Points: 649, Visits: 206
A long time ago--ok, file timestamp says 5 months, but I don't remember doing any of it--I created a simple VB script utility to script out all the jobs from a given SQL instance. (This was for 2005; I had tried something similar for 2000 years ago, but various features I came across meant it didn't work too well.) This was a manual process, as you can see from the use of MsgBox.

This uses SQLDMO, which I'm 99% certain is what SSMS uses to generate scripts. It's all documented in BOL and online, and at this time I couldn't tell you what it all means. Start with this, do some research on what it all means and how it might be adapted to your system, and (I'm hoping) you should be able to work it all out.

Good luck!

Philip


' This will generate build scripts for all SQL Agent jobs on the target server (xxx)
' and save them to file "AllJobs.sql".
'
' First # parameter:
' 4 - Create the object
' 64 - Output to file (only)
' 4096 - Create only if it doesn't exist
' 131072 - Include header and descriptive info
'
' Second # parameter:
' 2048 - SQL Agent [as opposed to something else]
'


'Set the server to work over
targetServer = "xxx"


'Let them know it started and where it's pointing; user selects Ok (1) or Cancel (2)
If MsgBox("Work over jobs on " & targetServer & "?", 257, "Jobs Processing") = 2 Then
'Exit the script
Wscript.echo "Cancelled"
Wscript.quit
End If


' Configure object
DIM loDMO, loSQLInstance, loJobs
SET loDMO = CreateObject("SQLDMO.SQLServer2")


' Login to server with NT authentication
loDMO.LoginSecure = TRUE
loDMO.Connect(targetServer)


' Generate the scripts
lsScripts = loDMO.JobServer.Jobs.Script(135236, "JobsFrom_" & targetServer & "__All.sql", 2048)


Wscript.echo "Completed"



Post #443750
Posted Wednesday, January 16, 2008 10:38 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Thursday, July 24, 2014 4:49 PM
Points: 4,065, Visits: 5,277
Suji,

Since you mention Enterprise Manager, I assume you're talking SQL 2000. You know you can script all the jobs in an instance in Enterprise Manager by right_clicking on 'Jobs' under 'Management'. You don't have to script each one individually.

Greg


Greg
Post #443850
Posted Saturday, January 19, 2008 10:58 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
Thanks Philip, yes i am a bit late to join the community,i will try it on monday, will be here more often


Cheers

Post #445234
Posted Thursday, January 24, 2008 3:09 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Saturday, August 25, 2012 9:48 PM
Points: 777, Visits: 134
hi Greg Charles ,
thx for ur information. it helps me too.

thx
sreejith
MCAD
Post #447219
Posted Friday, January 25, 2008 2:52 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:35 AM
Points: 2,859, Visits: 3,186
All your jobs are stored in msdb, so a backup of msdb will contain all your jobs.

As other people have said, it is a good idea to also have scripts for all your jobs. This means they can be re-created if you need to build a new server, or for any other reason.


Original author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2014, 2012, 2008 R2, 2008 and 2005. 28 July 2014: now over 30,000 downloads.
Disclaimer: All information provided is a personal opinion that may not match reality.
Concept: "Pizza Apartheid" - the discrimination that separates those who earn enough in one day to buy a pizza if they want one, from those who can not.
Post #447360
Posted Friday, January 25, 2008 4:24 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 2:53 AM
Points: 1,030, Visits: 2,794
backing up msdb database will backup your agent jobs, its also a good idea to script them out.

Gethyn Ellis

gethynellis.com
Post #447871
Posted Tuesday, February 5, 2008 12:25 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
Hi Philip
Thanks a lot mate, it worked for me,


Cheers
Post #451835
Posted Wednesday, February 6, 2008 6:54 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, July 3, 2014 10:20 AM
Points: 770, Visits: 1,596
Hi All
I have also found a way of scripting using SQL DMO , i have used this code on SQL 2005 and its working, you have to enable OLE-Automation before you run the code below


--sp_OA params
DECLARE @cmd varchar(255) -- Command to run
DECLARE @oSQLServer int -- OA return object
DECLARE @hr int -- Return code

--User params
DECLARE @FileName varchar(200) -- File name to script jobs out
DECLARE @Server varchar(30) -- Server name to run script on. By default, local server.

--SQL DMO Constants
DECLARE @ScriptType varchar(50)
DECLARE @Script2Type varchar(50)
SET @ScriptType = '327' -- Send output to file, Transact-SQL, script permissions, test for existence, used quoted characters.
SET @Script2Type = '3074' -- Script Jobs, Alerts, and use CodePage 1252.

--Set the following properties for your server
SET @FileName = 'c:\sqlJobs.sql'
SET @Server = @@SERVERNAME

--CREATE The SQLDMO Object
EXEC @hr = sp_OACreate 'SQLDMO.SQLServer', @oSQLServer OUT

--Set Windows Authentication
EXEC @hr = sp_OASetProperty @oSQLServer, 'LoginSecure', TRUE

--Connect to the Server
EXEC @hr = sp_OAMethod @oSQLServer,'Connect',NULL,@server

--Script the job out to a text file
SET @cmd = 'Jobserver.Jobs.Script(' + @ScriptType + ',"' + @FileName +'",' + @Script2Type + ')'
EXEC @hr = sp_OAMethod @oSQLServer, @cmd

--Close the connection to SQL Server
--If object is not disconnected, the processes will be orphaned.
EXEC @hr = sp_OAMethod @oSQLServer, 'Disconnect'

--Destroy object created.
exec sp_OADestroy @oSQLServer




Post #452172
Posted Wednesday, February 6, 2008 7:32 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:35 AM
Points: 2,859, Visits: 3,186
You may find www.codeplex.com/SQLServerFineBuild helpful. FineBuild is something I published that helps you get a 1-click install and configuration of SQL Server 2005. It includes scripts that help in upgrading from SQL 2000, including scripting out jobs, accounts, etc, etc.

Original author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2014, 2012, 2008 R2, 2008 and 2005. 28 July 2014: now over 30,000 downloads.
Disclaimer: All information provided is a personal opinion that may not match reality.
Concept: "Pizza Apartheid" - the discrimination that separates those who earn enough in one day to buy a pizza if they want one, from those who can not.
Post #452199
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse