patternsqlMinor
Moving SQL Server Agent Job Categories and Schedules
Viewed 0 times
sqlagentandschedulesmovingcategoriesserverjob
Problem
I want to copy a set of Job Categories and Schedules between MS SQL Servers (2012/2014).
Returns all schedules.
Returns all my job categories.
To add them i could use the stored procedures:
I can get it done with this information, but it would almost be as tedious as re-doing them manually.
How can i do this in a more effective way?
select * FROM msdb.dbo.sysschedulesReturns all schedules.
select * FROM msdb.dbo.syscategories
WHERE category_id IN (SELECT DISTINCT category_id FROM msdb.dbo.sysjobs)Returns all my job categories.
To add them i could use the stored procedures:
sp_add_category
sp_add_jobscheduleI can get it done with this information, but it would almost be as tedious as re-doing them manually.
How can i do this in a more effective way?
Solution
Another cool powershell utility that I use everyday for server migrations is Start-SqlServerMigration.ps1 written by Chrissy LeMaire
It is very adaptive with different options.
Eg. In your scenario for migrating jobs with schedule, you can use
.PARAMETER MigrateJobServer
Migrates all job server objects, including proxy accounts, job schedules, shared schedules, alert system, job categories, operator categories, alert categories, alerts, target server groups, target servers, operators, and jobs. Existing objects will not be deleted, and no -force option is available.
e.g. The PS below code will move all the databases (overwrite if the same name databases exists since it uses
It is very adaptive with different options.
Eg. In your scenario for migrating jobs with schedule, you can use
.PARAMETER MigrateJobServer
Migrates all job server objects, including proxy accounts, job schedules, shared schedules, alert system, job categories, operator categories, alert categories, alerts, target server groups, target servers, operators, and jobs. Existing objects will not be deleted, and no -force option is available.
e.g. The PS below code will move all the databases (overwrite if the same name databases exists since it uses
force parameter) from Source sqlserver\instance to Destination sqlcluster. It will exclude Northwind, pubs databases. It will migrate all the logins except nwuser, pubsuser, "corp\domain admins", will migrate all the sql agent jobs, will export the sp_configure options from source to destination server..\Start-SqlServerMigration.ps1 -Source sqlserver\instance -Destination sqlcluster -AllUserDBs -ExcludeDBs Northwind, pubs -IncludeSupportDBs -force -AllLogins -ExcludeLogins nwuser, pubsuser, "corp\domain admins" -MigrateJobServer -ExportSPconfigure -UseSqlLoginSource -UseSqlLoginDestinationCode Snippets
.\Start-SqlServerMigration.ps1 -Source sqlserver\instance -Destination sqlcluster -AllUserDBs -ExcludeDBs Northwind, pubs -IncludeSupportDBs -force -AllLogins -ExcludeLogins nwuser, pubsuser, "corp\domain admins" -MigrateJobServer -ExportSPconfigure -UseSqlLoginSource -UseSqlLoginDestinationContext
StackExchange Database Administrators Q#125867, answer score: 4
Revisions (0)
No revisions yet.