Showing posts with label jobs. Show all posts
Showing posts with label jobs. Show all posts

Friday, March 23, 2012

Script to detect long running jobs

Is there a function/proc to help me detect jobs that are running long, say twice the normal run time?
I don't think so, but you could build a process that reviews the
sysjobhistory table and determine those jobs runs that contain durations
longer then the average. Review the format of the sysjobhistory table in
BOL.
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Ken Dutton" <fj60landcruiser@.yahoo.com> wrote in message
news:1FCC1245-DF44-4CA6-8856-4AEEC52206C8@.microsoft.com...
> Is there a function/proc to help me detect jobs that are running long, say
twice the normal run time?

Script to detect long running jobs

Is there a function/proc to help me detect jobs that are running long, say twice the normal run time?I don't think so, but you could build a process that reviews the
sysjobhistory table and determine those jobs runs that contain durations
longer then the average. Review the format of the sysjobhistory table in
BOL.
--
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Ken Dutton" <fj60landcruiser@.yahoo.com> wrote in message
news:1FCC1245-DF44-4CA6-8856-4AEEC52206C8@.microsoft.com...
> Is there a function/proc to help me detect jobs that are running long, say
twice the normal run time?

Script to detect long running jobs

Is there a function/proc to help me detect jobs that are running long, say t
wice the normal run time?I don't think so, but you could build a process that reviews the
sysjobhistory table and determine those jobs runs that contain durations
longer then the average. Review the format of the sysjobhistory table in
BOL.
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Ken Dutton" <fj60landcruiser@.yahoo.com> wrote in message
news:1FCC1245-DF44-4CA6-8856-4AEEC52206C8@.microsoft.com...
> Is there a function/proc to help me detect jobs that are running long, say
twice the normal run time?

Wednesday, March 21, 2012

Script Task Hang - Had to Re-Compile

Greetings,

This morning one of our jobs failed, so I eventually ran the SSIS package manually and found the flow "hanging" at a script task. The fix was to open the script in design mode and hit Save, which I believe compiles the code. Then the package ran as it has normally for several months.

There was a recent Windows update run on this server. I don't know what was updated, as it was the DBA that did that. It seems possible that a .NET framework update would cause this problem, does anyone have any thoughts on this or anything else causing this?

Given the extent of some SSIS environments, and ours is pretty extensive, this could be a real pain to go in and manually recompile each and every script task.

Thanks

Read the first post at the top of this forum.|||

Thanks Phil,

Just wanted to give some details about what I understand was our situation here.

We have had SQL Server 2005 SP2 for several months. This morning there was a big push which included Windows SP2, .NET 2.0, and .NET 3.0. So it doesn't surprise me that I'd have to recompile, but according to the article referenced at the top of this forum, it seems that SQL SP2 should have taken care of this. Possibly it was our unique sequence of updates here.

|||I'm surprised .Net 2.0 wasn't already installed. It should've been, I believe. You might have to reinstall SQL Server SP2 to reap its benefits.

I'm not entirely sure on the whole deal. That sounds like a pretty major update though.|||

Yes I was thinking the same thing, that the DBA must have been mistaken when he told me that. I thought .NET 2 was installed with SQL 2005, a prerequisite. Will probably just wait to see if it happens again, and if so then reinstall as you suggested.

Thanks for for your time on this

Monday, March 12, 2012

Script jobs for restore to another server

I want to restore all jobs from one server to another. I seem to remember that in SQL 2000 there was an option to script all jobs but it seems that in 2005 you have to script them 1 at a time. Is there a more efficient way than scripting each job and then executing each script individually?

Thanks,

-Dave

you still can. just open the 'summary' window and go to jobs. highlight all the jobs and generate the script.

Script Jobs

I need to move all my jobs on SQL 2000 and create them on SQL 2005, my
question what would the best and quickest way.?
and is there a way to script them all at once instead of one at the time.
Thanks
Hi
"msnews.microsoft.com" wrote:

> I need to move all my jobs on SQL 2000 and create them on SQL 2005, my
> question what would the best and quickest way.?
> and is there a way to script them all at once instead of one at the time.
> Thanks
>
See http://support.microsoft.com/kb/314546 on how to move jobs. Your job
scripts should be held in a Source Code management system along with all your
other DDL.
There are scripts to move logins and you will need to associate orphaned
users to logins.
Make sure you database are SQL 2005 compatible by using the Upgrade advisor
http://tinyurl.com/zt3a6 and change the compatibility mode of the
restored/reattached database to SQL 90. Other actions would include
rebuilding indexes, statistics and updating usage see
http://msdn2.microsoft.com/en-us/library/ms144267.aspx
John

Script Jobs

I need to move all my jobs on SQL 2000 and create them on SQL 2005, my
question what would the best and quickest way.?
and is there a way to script them all at once instead of one at the time.
ThanksHi
"msnews.microsoft.com" wrote:
> I need to move all my jobs on SQL 2000 and create them on SQL 2005, my
> question what would the best and quickest way.?
> and is there a way to script them all at once instead of one at the time.
> Thanks
>
See http://support.microsoft.com/kb/314546 on how to move jobs. Your job
scripts should be held in a Source Code management system along with all your
other DDL.
There are scripts to move logins and you will need to associate orphaned
users to logins.
Make sure you database are SQL 2005 compatible by using the Upgrade advisor
http://tinyurl.com/zt3a6 and change the compatibility mode of the
restored/reattached database to SQL 90. Other actions would include
rebuilding indexes, statistics and updating usage see
http://msdn2.microsoft.com/en-us/library/ms144267.aspx
John

Script Jobs

I need to move all my jobs on SQL 2000 and create them on SQL 2005, my
question what would the best and quickest way.?
and is there a way to script them all at once instead of one at the time.
ThanksHi
"msnews.microsoft.com" wrote:

> I need to move all my jobs on SQL 2000 and create them on SQL 2005, my
> question what would the best and quickest way.?
> and is there a way to script them all at once instead of one at the time.
> Thanks
>
See http://support.microsoft.com/kb/314546 on how to move jobs. Your job
scripts should be held in a Source Code management system along with all you
r
other DDL.
There are scripts to move logins and you will need to associate orphaned
users to logins.
Make sure you database are SQL 2005 compatible by using the Upgrade advisor
http://tinyurl.com/zt3a6 and change the compatibility mode of the
restored/reattached database to SQL 90. Other actions would include
rebuilding indexes, statistics and updating usage see
http://msdn2.microsoft.com/en-us/library/ms144267.aspx
John

Script for SQL Agent "Weighted Job Duration"

Hi,

Does anyone know of a script that will give "weighted job duration"?
I want to use it, to identify which jobs are hogging the CPU. That is
for a given server, list the sql agent jobs ordered by:

(avg job duration in minutes) times (avg num of times job runs in a
given day).On 20 Jul 2004 08:54:48 -0700, Louis wrote:

> Hi,
> Does anyone know of a script that will give "weighted job duration"?
> I want to use it, to identify which jobs are hogging the CPU. That is
> for a given server, list the sql agent jobs ordered by:
> (avg job duration in minutes) times (avg num of times job runs in a
> given day).

Assuming SQL Server 2000 or higher, I came up with this:

Select T3.name, avg(T3.Recurrences) 'AvgRecurrencesPerDay',
sum(T3.[TotalDailyDuration])/sum(T3.Recurrences) 'AvgDuration',
avg(T3.Recurrences) * sum(T3.TotalDailyDuration)/sum(T3.Recurrences)
'Weight'
from (
select T2.name, T1.run_date,
count(*) 'Recurrences',
sum(T1.run_duration) 'TotalDailyDuration'
from msdb.dbo.sysjobhistory T1
inner join msdbo.dbo.sysjobs T2 on T1.job_id = T2.job_id
group by T2.name, T1.run_date
) T3
group by T3.name
order by Weight desc, T3.Name asc|||Thanks Ross. I played with your script and altered it a bit. I decided
what I really want is avg minutes per day.
- Louis

SELECT name as Job,
str(occurrences/@.numDays,10,1) as RunsPerDay,
str(duration/occurrences,10,1) as MinsPerJob,
str(duration/@.numDays,10,1) as MinsPerDay
FROM (
SELECT T2.name,
cast(count(*) as dec) as occurrences,
cast(sum(
(run_duration / 100)/100*60 + (run_duration / 100)%100 --
run_duration is in hhmmss crazy format
) as dec) as duration
FROM msdb.dbo.sysjobhistory T1
INNER JOIN msdb.dbo.sysjobs T2
ON T1.job_id = T2.job_id and step_id=0
and cast(rtrim(T1.run_date) as datetime) between @.startdate and
@.enddate
GROUP BY T2.name
) T
ORDER BY MinsPerDay desc

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Wednesday, March 7, 2012

script all MSDB jobs in TSQL

I know of a way to script all SQL Agent jobs using EM. But i want to script
all my jobs on a daily basis and copy that script file to another server . I
know how i can do the daily part of it which would be scheduling it again
but whats the TSQL or command I need to run within the job step .. ThanksYou can use Distributed Management Objects (DMO), not T-SQL. Check the
article at
http://www.winnetmag.com/SQLServer/...790/38790.html.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uEV1iN8iEHA.3988@.tk2msftngp13.phx.gbl...
> I know of a way to script all SQL Agent jobs using EM. But i want to
script
> all my jobs on a daily basis and copy that script file to another server .
I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>|||You can set up a job that uses an ActiveX script type job step containing
the following
Set oSQL = CreateObject("SQLDMO.SQLServer")
oSQL.Name = "(local)"
oSQL.LoginSecure = True
oSQL.LoginTimeout = 10
oSQL.Connect
Set oJobs = oSQL.JobServer.Jobs
oJobs.Script 4,"c:\jobs.sql",2048
oSQL.DisConnect
Set oSQL = Nothing
This will script all your jobs to c:\jobs.sql. For a named instance, change
the oSQL.Name
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uEV1iN8iEHA.3988@.tk2msftngp13.phx.gbl...
>I know of a way to script all SQL Agent jobs using EM. But i want to script
> all my jobs on a daily basis and copy that script file to another server .
> I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>|||one thing to watch out for is that the job owner (@.owner_login_name) will be
scripted out too. If login doesn't exist or in a different domain / env this
may cause you problems.
Could parse the Scripted text (can use the Script object just to return text
as opposed to file) and do a replace operation on the @.owner_login_name =
'xx' and replace with @.owner_login_name = null, so that sp_add_job will
create the job with owner of the user executing the script.
Then write the corrected text to File.
cheers,
Andy
"Hassan" wrote:

> I know of a way to script all SQL Agent jobs using EM. But i want to scrip
t
> all my jobs on a daily basis and copy that script file to another server .
I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
>|||... or use the DTS Transfer Jobs task !
"Hassan" wrote:

> I know of a way to script all SQL Agent jobs using EM. But i want to scrip
t
> all my jobs on a daily basis and copy that script file to another server .
I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
>

script all MSDB jobs in TSQL

I know of a way to script all SQL Agent jobs using EM. But i want to script
all my jobs on a daily basis and copy that script file to another server . I
know how i can do the daily part of it which would be scheduling it again
but whats the TSQL or command I need to run within the job step .. ThanksYou can use Distributed Management Objects (DMO), not T-SQL. Check the
article at
http://www.winnetmag.com/SQLServer/Article/ArticleID/38790/38790.html.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uEV1iN8iEHA.3988@.tk2msftngp13.phx.gbl...
> I know of a way to script all SQL Agent jobs using EM. But i want to
script
> all my jobs on a daily basis and copy that script file to another server .
I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>|||You can set up a job that uses an ActiveX script type job step containing
the following
Set oSQL = CreateObject("SQLDMO.SQLServer")
oSQL.Name = "(local)"
oSQL.LoginSecure = True
oSQL.LoginTimeout = 10
oSQL.Connect
Set oJobs = oSQL.JobServer.Jobs
oJobs.Script 4,"c:\jobs.sql",2048
oSQL.DisConnect
Set oSQL = Nothing
This will script all your jobs to c:\jobs.sql. For a named instance, change
the oSQL.Name
--
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uEV1iN8iEHA.3988@.tk2msftngp13.phx.gbl...
>I know of a way to script all SQL Agent jobs using EM. But i want to script
> all my jobs on a daily basis and copy that script file to another server .
> I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>|||one thing to watch out for is that the job owner (@.owner_login_name) will be
scripted out too. If login doesn't exist or in a different domain / env this
may cause you problems.
Could parse the Scripted text (can use the Script object just to return text
as opposed to file) and do a replace operation on the @.owner_login_name ='xx' and replace with @.owner_login_name = null, so that sp_add_job will
create the job with owner of the user executing the script.
Then write the corrected text to File.
cheers,
Andy
"Hassan" wrote:
> I know of a way to script all SQL Agent jobs using EM. But i want to script
> all my jobs on a daily basis and copy that script file to another server . I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
>

script all MSDB jobs in TSQL

I know of a way to script all SQL Agent jobs using EM. But i want to script
all my jobs on a daily basis and copy that script file to another server . I
know how i can do the daily part of it which would be scheduling it again
but whats the TSQL or command I need to run within the job step .. Thanks
You can use Distributed Management Objects (DMO), not T-SQL. Check the
article at
http://www.winnetmag.com/SQLServer/A...90/38790.html.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uEV1iN8iEHA.3988@.tk2msftngp13.phx.gbl...
> I know of a way to script all SQL Agent jobs using EM. But i want to
script
> all my jobs on a daily basis and copy that script file to another server .
I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
|||You can set up a job that uses an ActiveX script type job step containing
the following
Set oSQL = CreateObject("SQLDMO.SQLServer")
oSQL.Name = "(local)"
oSQL.LoginSecure = True
oSQL.LoginTimeout = 10
oSQL.Connect
Set oJobs = oSQL.JobServer.Jobs
oJobs.Script 4,"c:\jobs.sql",2048
oSQL.DisConnect
Set oSQL = Nothing
This will script all your jobs to c:\jobs.sql. For a named instance, change
the oSQL.Name
HTH
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uEV1iN8iEHA.3988@.tk2msftngp13.phx.gbl...
>I know of a way to script all SQL Agent jobs using EM. But i want to script
> all my jobs on a daily basis and copy that script file to another server .
> I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
|||one thing to watch out for is that the job owner (@.owner_login_name) will be
scripted out too. If login doesn't exist or in a different domain / env this
may cause you problems.
Could parse the Scripted text (can use the Script object just to return text
as opposed to file) and do a replace operation on the @.owner_login_name =
'xx' and replace with @.owner_login_name = null, so that sp_add_job will
create the job with owner of the user executing the script.
Then write the corrected text to File.
cheers,
Andy
"Hassan" wrote:

> I know of a way to script all SQL Agent jobs using EM. But i want to script
> all my jobs on a daily basis and copy that script file to another server . I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
>
|||try attached
rename to .vbs
usage CSCRIPT ScriptAllJobs.vbs <Server> <FileName> <owner>
Server is Source Server where you want to script jobs from
FileName is output file for the script
owner is the new owner of the jobs. either do NULL (which will give make the
owner the user who runs the create script) or 'somelogin' ie the NT Login
that should be the owner ie 'Domainx\Jobowner' - with the quotes.
hope that makes sense
I had to do a bit of hacking cos a) the owner is hard coded and b) the
servername is hard coded (ie replace this with @.@.ServerName). Not too happy
about this, I think I might have missed a DMO Option somewhere
ai
Andy.
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uEV1iN8iEHA.3988@.tk2msftngp13.phx.gbl...
> I know of a way to script all SQL Agent jobs using EM. But i want to
script
> all my jobs on a daily basis and copy that script file to another server .
I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
begin 666 ScriptAllJobs.txt
M)R!38W)I<'1!;&Q*;V)S+G-Q;" -"B<@.4V-R:7!T<R!A;&P@.:F]B<R!O;B!A
M(&=I=F5N(%-13"!397)V97(@.86YD(')E<&QA8V5S('1H92!H87)D8V]D960@.
M<F5F97)E;F-E<R!T;R!A;&QO=R!T;R!B92 -"B<@.8V]P:65D('1O(&%N;W1H
M97(@.<V5R=F5R#0HG($%N9'D@.0F%L;" R-"\X+S(P,#0)=C$N, E"87-E(%9E
M<G-I;VX-"@.T*3W!T:6]N($5X<&QI8VET#0H)( T*)R!344PM1$U/(&-O;G-T
M86YT<PT*0V]N<W0@.4U%,1$U/4V-R:7!T7T1R;W!S(#T@.,0T*#0I#;VYS="!3
M44Q$34]38W)I<'1?4')I;6%R>4]B:F5C=" ](#0@.#0I#;VYS="!344Q$34]3
M8W)I<'1?5&]&:6QE3VYL>2 ](#8T#0I#;VYS="!344Q$34]38W)I<'1?07!P
M96YD=&]&:6QE(#T@.,C4V#0H-"D-O;G-T(%-13$1-3U-C<FE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E9F5R;F-E<RX@.#0I&=6YC=&EO;B!297!L86-E2&%R9$-O9&5D4F5F("A3
M44Q3=')I;F<L(%-E87)C:%-T<FEN9RP@.4F5P;&%C95-T<FEN9RD-"@.E$:6T@.
M3F5W4W1R:6YG#0H)1&EM(%-E87)C:%-T<FEN9U!O<PT*"41I;2!396-O;F11
M=6]T95!O<PT*#0H)1&EM($QO9VEN3F%M90T*"41I;2!344Q3=')I; F=,96X-
M"@.T*"5-13%-T<FEN9TQE;B ]($QE;BA344Q3=')I;F<I#0H-"@.DG(&=E="!T
M:&4@.;&]C871I;VX@.;V8@.=&AE(&]W;F5R7VQO9VEN7VYA;64@.8VAA<@.T*"5-E
M87)C:%-T<FEN9U!O<R ]($EN4W1R*#$L(%-13%-T<FEN9RP@.4V5A<F-H4W1R
M:6YG+" P*0T*#0H))R!G970@.82!3=')I;F<@.+"!S=&%R=&EN9R!W:71H( $XG
M;&]G:6X@.;F%M92<-"@.E,;V=I;DYA;64@./2!-:60H4U%,4W1R:6YG+"!396%R
M8VA3=')I;F=0;W,@.*R!,14XH4V5A<F-H4W1R:6YG*2 K(#,L(%-13%-T<FEN
M9TQE;B M(%-E87)C:%-T<FEN9U!O<RD-"@.D-"@.E396-O;F11=6]T95!O<R ]
M($EN4W1R*#,L($QO9VEN3F%M92P@.(B<B+" P*0D)#0H)3&]G:6Y.86UE(#T@.
M36ED*$QO9VEN3F%M92P@.,2P@.4V5C;VYD475O=&50;W,I#0H)# 0H))R!74V-R
M:7!T+D5C:&\@.3&]G:6Y.86UE#0H)4F5P;&%C94AA<F1#;V1E9%)E9B ](%)E
M<&QA8V4H4U%,4W1R:6YG+"!,;V=I;DYA;64L(%)E<&QA8V53= ')I;F<I#0I%
6;F0@.1G5N8W1I;VX@.#0H-"@.T*#0H-"@.``
`
end
|||... or use the DTS Transfer Jobs task !
"Hassan" wrote:

> I know of a way to script all SQL Agent jobs using EM. But i want to script
> all my jobs on a daily basis and copy that script file to another server . I
> know how i can do the daily part of it which would be scheduling it again
> but whats the TSQL or command I need to run within the job step .. Thanks
>
>

Script Alerts

I know that I can script all of the server alerts,
operators, and jobs using enterprise manager, however,
does anyone know how I can go about scripting out the
alerts, operators, and jobs not using enterprise
manager. What I want to do is make this part of my
disaster recovery process to have the SQLAgent run a job
every night to capture a script of the alerts, operators,
and jobs so that I can use these scripts to recovery said
objects in case of a disaster.Take a look at the Script method in the SQL-DMO
documenation in the SQL Server Books Online.
Linchi
>--Original Message--
>I know that I can script all of the server alerts,
>operators, and jobs using enterprise manager, however,
>does anyone know how I can go about scripting out the
>alerts, operators, and jobs not using enterprise
>manager. What I want to do is make this part of my
>disaster recovery process to have the SQLAgent run a job
>every night to capture a script of the alerts, operators,
>and jobs so that I can use these scripts to recovery said
>objects in case of a disaster.
>.
>|||In addition to Linchi's reply, if you are not comfortable with SQL-DMO, you
can contact me and I would develop a script for you if you were to
compensate me for my time. Pls remove NO_SPAM(s) from my email address if
you do.
--
Ata R
Parvan Consulting Inc
NO_SPAMar_alias001@.NO_SPAMparvan.net
"Z" <anonymous@.discussions.microsoft.com> wrote in message
news:027d01c3d49b$344851c0$a501280a@.phx.gbl...
> I know that I can script all of the server alerts,
> operators, and jobs using enterprise manager, however,
> does anyone know how I can go about scripting out the
> alerts, operators, and jobs not using enterprise
> manager. What I want to do is make this part of my
> disaster recovery process to have the SQLAgent run a job
> every night to capture a script of the alerts, operators,
> and jobs so that I can use these scripts to recovery said
> objects in case of a disaster.
>|||But the script is rather simple to write. Here's a Perl
script I just whipped up to script out Alerts, Jobs, and
Operators:
# Begin script
use strict;
use Win32::OLE 'in';
use Win32::OLE::Const 'Microsoft SQLDMO';
my $serverName = 'yourSQLServer';
my ($server, $obj);
my $script = shift; # get command line argument
$server = Win32::OLE->new('SQLDMO.SQLServer')
or die "Could not create SQLDMO object.";
$server->{LoginSecure} = 1;
$server->connect($serverName, '', '');
if (Win32::OLE->LastError()) {
die "***Err: Could not connect to $serverName.";
}
print "**** Scripting Alerts ... \n";
my $alerts = $server->JobServer->Alerts();
if (Win32::OLE->LastError()) {
die "**Err: Could not get the alerts collection in
$serverName.";
}
foreach $obj (in($alerts)) {
$obj->Script(SQLDMOScript_Default |
SQLDMOScript_AppendToFile |
SQLDMOScript_OwnerQualify |
SQLDMOScript_IncludeHeaders |
SQLDMOScript_Drops |
SQLDMOScript_ToFileOnly,
$script);
}
print "**** Scripting Jobs ... \n";
my $jobs = $server->JobServer->Jobs();
if (Win32::OLE->LastError()) {
die "**Err: Could not get the jobs collection in
$serverName.";
}
foreach $obj (in($jobs)) {
$obj->Script(SQLDMOScript_Default |
SQLDMOScript_AppendToFile |
SQLDMOScript_OwnerQualify |
SQLDMOScript_IncludeHeaders |
SQLDMOScript_Drops |
SQLDMOScript_ToFileOnly,
$script);
}
print "**** Scripting Operators ... \n";
my $operators = $server->JobServer->Operators();
if (Win32::OLE->LastError()) {
die "**Err: Could not get the operators collection in
$serverName.";
}
foreach $obj (in($operators)) {
$obj->Script(SQLDMOScript_Default |
SQLDMOScript_AppendToFile |
SQLDMOScript_OwnerQualify |
SQLDMOScript_IncludeHeaders |
SQLDMOScript_Drops |
SQLDMOScript_ToFileOnly,
$script);
}
$server->disconnect();
$server->DESTROY();
# End script
Linchi
>--Original Message--
>In addition to Linchi's reply, if you are not comfortable
with SQL-DMO, you
>can contact me and I would develop a script for you if
you were to
>compensate me for my time. Pls remove NO_SPAM(s) from my
email address if
>you do.
>--
>Ata R
>Parvan Consulting Inc
>NO_SPAMar_alias001@.NO_SPAMparvan.net
>
>"Z" <anonymous@.discussions.microsoft.com> wrote in message
>news:027d01c3d49b$344851c0$a501280a@.phx.gbl...
>> I know that I can script all of the server alerts,
>> operators, and jobs using enterprise manager, however,
>> does anyone know how I can go about scripting out the
>> alerts, operators, and jobs not using enterprise
>> manager. What I want to do is make this part of my
>> disaster recovery process to have the SQLAgent run a job
>> every night to capture a script of the alerts,
operators,
>> and jobs so that I can use these scripts to recovery
said
>> objects in case of a disaster.
>
>.
>|||AndI have a VB version of this that will script out the whole server for
you. As Linchi alludes to, SQL DMO is an untuitive object model and can
really help you out.
If you want the application then mail me
--
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Linchi Shea" <linchi_shea@.NOSPAMml.com> wrote in message
news:00c901c3d53f$db652240$a301280a@.phx.gbl...
> But the script is rather simple to write. Here's a Perl
> script I just whipped up to script out Alerts, Jobs, and
> Operators:
> # Begin script
> use strict;
> use Win32::OLE 'in';
> use Win32::OLE::Const 'Microsoft SQLDMO';
> my $serverName = 'yourSQLServer';
> my ($server, $obj);
> my $script = shift; # get command line argument
> $server = Win32::OLE->new('SQLDMO.SQLServer')
> or die "Could not create SQLDMO object.";
> $server->{LoginSecure} = 1;
> $server->connect($serverName, '', '');
> if (Win32::OLE->LastError()) {
> die "***Err: Could not connect to $serverName.";
> }
> print "**** Scripting Alerts ... \n";
> my $alerts = $server->JobServer->Alerts();
> if (Win32::OLE->LastError()) {
> die "**Err: Could not get the alerts collection in
> $serverName.";
> }
> foreach $obj (in($alerts)) {
> $obj->Script(SQLDMOScript_Default |
> SQLDMOScript_AppendToFile |
> SQLDMOScript_OwnerQualify |
> SQLDMOScript_IncludeHeaders |
> SQLDMOScript_Drops |
> SQLDMOScript_ToFileOnly,
> $script);
> }
> print "**** Scripting Jobs ... \n";
> my $jobs = $server->JobServer->Jobs();
> if (Win32::OLE->LastError()) {
> die "**Err: Could not get the jobs collection in
> $serverName.";
> }
> foreach $obj (in($jobs)) {
> $obj->Script(SQLDMOScript_Default |
> SQLDMOScript_AppendToFile |
> SQLDMOScript_OwnerQualify |
> SQLDMOScript_IncludeHeaders |
> SQLDMOScript_Drops |
> SQLDMOScript_ToFileOnly,
> $script);
> }
> print "**** Scripting Operators ... \n";
> my $operators = $server->JobServer->Operators();
> if (Win32::OLE->LastError()) {
> die "**Err: Could not get the operators collection in
> $serverName.";
> }
> foreach $obj (in($operators)) {
> $obj->Script(SQLDMOScript_Default |
> SQLDMOScript_AppendToFile |
> SQLDMOScript_OwnerQualify |
> SQLDMOScript_IncludeHeaders |
> SQLDMOScript_Drops |
> SQLDMOScript_ToFileOnly,
> $script);
> }
> $server->disconnect();
> $server->DESTROY();
> # End script
> Linchi
> >--Original Message--
> >In addition to Linchi's reply, if you are not comfortable
> with SQL-DMO, you
> >can contact me and I would develop a script for you if
> you were to
> >compensate me for my time. Pls remove NO_SPAM(s) from my
> email address if
> >you do.
> >
> >--
> >Ata R
> >Parvan Consulting Inc
> >NO_SPAMar_alias001@.NO_SPAMparvan.net
> >
> >
> >"Z" <anonymous@.discussions.microsoft.com> wrote in message
> >news:027d01c3d49b$344851c0$a501280a@.phx.gbl...
> >> I know that I can script all of the server alerts,
> >> operators, and jobs using enterprise manager, however,
> >> does anyone know how I can go about scripting out the
> >> alerts, operators, and jobs not using enterprise
> >> manager. What I want to do is make this part of my
> >> disaster recovery process to have the SQLAgent run a job
> >> every night to capture a script of the alerts,
> operators,
> >> and jobs so that I can use these scripts to recovery
> said
> >> objects in case of a disaster.
> >>
> >
> >
> >.
> >