SQL Server Agent jobs in a migration: what moves, what breaks and what replaces them

A backup of a SQL Server database contains its tables, code and users, but not the jobs that run against it every night. Those jobs belong to SQL Server Agent and are stored in msdb. This guide explains what the Agent does, why jobs are often only missed after the switch-over, what each target platform offers instead, and how to make an inventory before you migrate.

What SQL Server Agent is

SQL Server Agent is a separate service that runs next to the database engine. It is the built-in scheduler of SQL Server: it starts work at set times or in response to events, keeps a history of every run and can notify someone when something fails. Express Edition does not include it. Its building blocks:

  • Jobs: a named unit of work with an owner, a category and one or more steps.
  • Steps: each step has a type, the command to run, the database it runs in, and what happens on success or failure: go to the next step, stop, or retry.
  • Schedules: once, daily, weekly, monthly, when the Agent starts or when the CPU is idle. One schedule can be shared by several jobs. Times are in the local time of the server.
  • Alerts: react to an error number, a severity or a performance condition, and can notify an operator or start a job.
  • Operators: people or mailboxes to notify, usually by e-mail through Database Mail.
  • Proxies and credentials: let a step that is not T-SQL run under another Windows account than the Agent service account.

The usual step types are Transact-SQL, Operating system (CmdExec), PowerShell and SQL Server Integration Services package. There are also step types for the replication agents (snapshot, log reader, distribution, merge, queue reader) and for Analysis Services commands and queries.

Jobs, steps, schedules, alerts, operators and proxies are all stored in the msdb system database, not in the user database the jobs work on. That one fact explains most of the problems in this guide.

What jobs do in a typical system

In most systems the Agent does more than anyone remembers. Typical jobs:

  • Index and statistics maintenance, often with Ola Hallengren's scripts or a maintenance plan
  • Backups and DBCC CHECKDB integrity checks
  • Nightly imports and exports: files from a network share, BULK INSERT, bcp or an SSIS package
  • Stored procedures on a schedule: invoicing runs, recalculations, aggregations for reports
  • Cleanup: deleting old log rows, archiving, emptying staging tables, removing old files
  • Mail with sp_send_dbmail: reports, reminders and warnings to the business
  • Operating system commands and scripts: copying files, starting an executable, a PowerShell script that talks to another system

Many of these jobs were set up years ago, often by someone who has since left. They are not part of the application code, so nobody thinks of them until a report or an import is missing after the switch-over.

Why jobs do not move with the database

Every common migration method moves the user database only: backup and restore, a .bacpac export, Azure Database Migration Service, AWS DMS, log shipping, an availability group, detach and attach. None of them copies msdb, and on a managed service you cannot restore your old msdb. The jobs stay behind on the old server, where they keep running against a database that is no longer in use, or start failing once it is gone.

Even on a target with an Agent, a scripted job does not always run unchanged. Typical causes:

  • No Agent at all: Azure SQL Database, including Hyperscale and elastic pools, has no SQL Server Agent. Babelfish for Aurora PostgreSQL, PostgreSQL, MySQL, MariaDB and Oracle have none either.
  • Step types that are not allowed: managed services block or restrict CmdExec and PowerShell steps, and with them everything that starts an executable or a script.
  • No local disk or network share: steps that read files from a network share or write to a local folder have nothing to point at. On Azure SQL Managed Instance, files come from Azure Blob Storage instead.
  • Owners and proxies: a job owned by a login that was not migrated, or by a Windows login on a service without Windows authentication, does not run. Proxies are not available on every service.
  • Database Mail: profiles and accounts are stored in msdb, outgoing SMTP may be blocked, and some services require a fixed profile name or do not offer Database Mail at all.
  • Server names: steps that contain the old server name, a linked server, or a connection string in an SSIS package or script still point at the old environment.
  • Time zone: Agent schedules use the local time of the server. Managed services use UTC by default, and on several of them the time zone can only be chosen when the instance is created, so a job planned for 02:00 can run at another hour.
  • Maintenance plans: they are SSIS packages stored in msdb. Cloud SQL for SQL Server lists them as unavailable and Azure SQL Database has no Agent to run them; on other services, check before you count on them.
  • Backups: on a managed service the service makes the backups. On Amazon RDS, backups through the Agent are not supported; on Azure SQL Managed Instance only COPY_ONLY backups to a URL are possible.

SQL Server Agent per target platform

The table summarises what each target offers. Limits change with new releases: check the documentation of the service for the version you deploy.

PlatformSQL Server AgentJob step types / limitsReplacement or scheduler
SQL Server on a VM or own serverYes, complete (not in Express Edition)All step types, proxies, alerts and operators, as on the old serverScript the jobs and recreate them; correct server names, paths and owners
Azure SQL Database (incl. Hyperscale)NoNo Agent jobs at allElastic jobs (T-SQL), Azure Automation, Logic Apps, Azure Functions with a timer trigger, Azure Data Factory
Azure SQL Managed InstanceYes, always running; Agent settings are read onlyT-SQL, SSIS (through an Azure-SSIS integration runtime) and transactional replication steps; PowerShell without scripts on disk or external modules; no command shell, merge replication, queue reader or Analysis Services steps; no proxies and no alerts; e-mail only through the profile AzureManagedInstance_dbmail_profile; job history fixed at 1,000 rowsThe Agent for T-SQL work; Azure Automation, Logic Apps or Azure Functions for work outside the instance
Amazon RDS for SQL ServerYes (Web, Standard and Enterprise Edition); you cannot start or stop itT-SQL; SSIS with an SSIS proxy when the SSIS option is enabled; no CmdExec, PowerShell, ActiveX or replication jobs; no alerts, operators or Agent e-mail notifications; no backups through the Agent; no Agent tokens; up to 10,000 jobs on Multi-AZThe Agent for T-SQL work; Amazon EventBridge Scheduler with AWS Lambda or AWS Step Functions for the rest
Babelfish for Aurora PostgreSQLNoNo SQL Server Agent and no xp_cmdshellpg_cron on the Aurora PostgreSQL cluster (check it for your Babelfish version), or EventBridge Scheduler with Lambda
Google Cloud SQL for SQL ServerYesDatabase Mail and maintenance plans are listed as unavailable; SSIS packages cannot run on Cloud SQL itself; no sysadmin role; check which step types are allowedThe Agent for T-SQL work; Cloud Scheduler with Cloud Run, or SSIS on a separate host
PostgreSQL, MySQL or OracleNoEach engine has its own scheduler and syntax; T-SQL steps must be rewrittenpg_cron or pg_timetable (PostgreSQL), Event Scheduler (MySQL, MariaDB), DBMS_SCHEDULER (Oracle), or an external scheduler

Two details for high availability: in an Azure SQL Managed Instance failover group the system databases are not replicated, so jobs must also be created on the secondary instance. On Amazon RDS Multi-AZ, Agent jobs are only copied to the secondary once job replication is turned on with msdb.dbo.rds_set_system_database_sync_objects, and only jobs with T-SQL steps are replicated.

Making an inventory before you migrate

Start on the old server, before anything is switched off. For each job you want to know: is it enabled and does it still run, who owns it, which step types it uses, which database each step runs in, when it runs, who is notified, and which external resources it touches: file shares, other servers, linked servers, mail, executables.

The two queries below only read from msdb and change nothing. The first lists every step with its type, target database and proxy; the second every schedule with the next and last run.

Jobs and steps
-- SQL Server Agent: jobs and steps (read-only, reads msdb only)
SELECT
    j.name                    AS job_name,
    j.enabled                 AS job_enabled,
    SUSER_SNAME(j.owner_sid)  AS job_owner,      -- NULL: no login found for this SID
    c.name                    AS category,
    st.step_id,
    st.step_name,
    st.subsystem,                                -- TSQL, CmdExec, PowerShell, SSIS, ...
    st.database_name,                            -- database the step runs in
    p.name                    AS proxy_name,
    o.name                    AS email_operator,
    LEFT(st.command, 400)     AS command_start
FROM msdb.dbo.sysjobs AS j
JOIN msdb.dbo.syscategories AS c ON c.category_id = j.category_id
LEFT JOIN msdb.dbo.sysjobsteps AS st ON st.job_id = j.job_id
LEFT JOIN msdb.dbo.sysproxies AS p ON p.proxy_id = st.proxy_id
LEFT JOIN msdb.dbo.sysoperators AS o ON o.id = j.notify_email_operator_id
ORDER BY j.name, st.step_id;
Schedules and last run
-- SQL Server Agent: schedules and last run (read-only, reads msdb only)
SELECT
    j.name                    AS job_name,
    s.name                    AS schedule_name,
    s.enabled                 AS schedule_enabled,
    CASE s.freq_type
        WHEN 1   THEN 'once'
        WHEN 4   THEN 'daily'
        WHEN 8   THEN 'weekly'
        WHEN 16  THEN 'monthly'
        WHEN 32  THEN 'monthly, relative'
        WHEN 64  THEN 'when the Agent starts'
        WHEN 128 THEN 'when the CPU is idle'
    END                       AS frequency,
    s.freq_interval,
    s.freq_subday_type,
    s.freq_subday_interval,
    STUFF(STUFF(RIGHT('000000' + CAST(s.active_start_time AS varchar(6)), 6), 5, 0, ':'), 3, 0, ':')
                              AS start_time_server_local,
    js.next_run_date,
    jsv.last_run_date,
    jsv.last_run_outcome                         -- 0 failed, 1 succeeded, 3 canceled, 5 unknown
FROM msdb.dbo.sysjobs AS j
LEFT JOIN msdb.dbo.sysjobschedules AS js ON js.job_id = j.job_id
LEFT JOIN msdb.dbo.sysschedules AS s ON s.schedule_id = js.schedule_id
LEFT JOIN msdb.dbo.sysjobservers AS jsv ON jsv.job_id = j.job_id
ORDER BY j.name, s.name;

A step that runs in master or another database can still work on your database through three-part names such as Sales.dbo.Orders. Also search the step commands for the database name, for example with WHERE st.command LIKE '%Sales%'.

To script the jobs, right-click a job in SQL Server Management Studio and choose Script Job as, CREATE To, or select several jobs in Object Explorer Details and script them together. With the PowerShell module dbatools, Get-DbaAgentJob piped to Export-DbaScript writes the scripts to files, and Copy-DbaAgentJob copies jobs directly to another instance that has an Agent.

Then put every job in one of three groups:

  • No longer needed because the service does it: backups on every managed service, and integrity checks where the service runs them. Be careful: index and statistics maintenance remains your job on most services.
  • Moves as it is: T-SQL jobs that only call procedures or run statements in the same database, to a target with an Agent. Script them, correct owner and database names, and keep them disabled until the switch-over so they do not run twice.
  • Must be rebuilt elsewhere: CmdExec and PowerShell steps, file imports, SSIS packages, mail, and every job on a target without an Agent.

What replaces the Agent on each platform

Decide per job, not per server: a T-SQL job that calls one procedure needs a different replacement than an SSIS import from a file share.

  • SQL Server on a virtual machine or your own server: everything works as before. Script the jobs, create them on the new server, then correct owners, server names, file paths, proxies and the Database Mail profile.
  • Azure SQL Database: elastic jobs run T-SQL on a schedule against one or many databases. They need an elastic job agent with its own job database. Work outside the database moves to Azure Automation runbooks, Logic Apps (mail, files, other systems), Azure Functions with a timer trigger, or Azure Data Factory pipelines for imports and exports.
  • Azure SQL Managed Instance: most T-SQL jobs can be created as they are. Rebuild command shell steps, move file imports to Azure Blob Storage (BULK INSERT with a data source), run SSIS packages through an Azure-SSIS integration runtime, and create the mail profile AzureManagedInstance_dbmail_profile for notifications.
  • Amazon RDS for SQL Server: T-SQL jobs work. Anything that needs the operating system moves outside the instance, typically to Amazon EventBridge Scheduler calling an AWS Lambda function or an AWS Step Functions workflow. Backups are made by RDS; native backups to Amazon S3 go through the procedure msdb.dbo.rds_backup_database.
  • Google Cloud SQL for SQL Server: the Agent is enabled, so T-SQL jobs can stay in the Agent. Mail, files and SSIS move to Cloud Scheduler with Cloud Run, or to an SSIS server on a separate host.
  • PostgreSQL, including Babelfish: pg_cron runs SQL on a cron schedule inside the database. It is available on Amazon RDS and Aurora PostgreSQL (through shared_preload_libraries in the parameter group), Azure Database for PostgreSQL flexible server, Cloud SQL for PostgreSQL (flag cloudsql.enable_pg_cron) and AlloyDB (flag alloydb.enable_pg_cron). pg_cron schedules run in GMT unless the time zone is configured. pg_timetable is an external scheduler that can also chain shell commands. Procedures must be rewritten in PL/pgSQL.
  • MySQL and MariaDB: the Event Scheduler runs events created with CREATE EVENT. It only runs when event_scheduler is ON; on Amazon RDS and Aurora you set it in the parameter group. Events can only run SQL; everything else needs an external scheduler.
  • Oracle: DBMS_SCHEDULER covers jobs, programs, schedules and chains, and on your own server also external jobs on the operating system. On a managed Oracle service, check whether external jobs are allowed.

Other server objects that stay behind

Jobs are not the only thing outside the database. Go through this list as well:

  • Logins: database users are linked to logins by SID. After a restore on a new server without the same logins, the users are orphaned. Create SQL logins with the original SID (CREATE LOGIN ... WITH SID, or Copy-DbaLogin in dbatools), and replace Windows logins with Microsoft Entra ID or SQL logins where Windows authentication is not available.
  • Linked servers: not available in Azure SQL Database; on Azure SQL Managed Instance limited to SQL Server and Azure SQL targets; in Babelfish, four-part names only work for reading.
  • Database Mail: profiles, accounts and SMTP passwords are stored in msdb and must be recreated. Check outgoing SMTP ports and what the service supports.
  • Operators and alerts: recreate them where alerts are supported; otherwise use the monitoring of the platform, such as Azure Monitor, Amazon CloudWatch or Cloud Monitoring.
  • Credentials and proxies: the secret of a credential cannot be read back, so you need the original password or a new account.
  • Server configuration: sp_configure settings, trace flags, server-level triggers, server roles and permissions, and SSIS packages stored in SSISDB or msdb.

How the free scan helps

The read-only script of the MigrateMyDatabase scan counts the SQL Server Agent jobs with at least one step that runs in the scanned database. The result shows “SQL Agent jobs use this database” with the number of jobs, or reports that the jobs could not be read when the account has no access to msdb. The script does not read job names or step commands, and jobs that reach your database from another database through three-part names are not counted: use the queries above for the complete list.

Questions

Does a backup of my database include the SQL Server Agent jobs?

No. Jobs are stored in the msdb system database, not in the user database. A backup, a .bacpac or a migration service only moves the user database. Script the jobs separately, or copy them with dbatools to a target that has an Agent.

Is there a SQL Server Agent in Azure SQL Database?

No, also not in Hyperscale or elastic pools. T-SQL jobs move to elastic jobs; work outside the database moves to Azure Automation, Logic Apps, Azure Functions or Azure Data Factory.

Can I move my jobs to Azure SQL Managed Instance unchanged?

Most T-SQL jobs, yes. Command shell steps, proxies, alerts, files on network shares and Analysis Services steps do not work, and e-mail notifications need the profile AzureManagedInstance_dbmail_profile.

Does Amazon RDS for SQL Server support SQL Server Agent?

Yes, on Web, Standard and Enterprise Edition. T-SQL steps work, and SSIS steps with an SSIS proxy when the SSIS option is enabled. CmdExec, PowerShell and replication jobs, alerts, operators, Agent e-mail notifications and backups through the Agent are not supported.

What replaces SQL Server Agent on PostgreSQL?

Usually pg_cron, which runs SQL on a cron schedule inside the database and is available on the large managed PostgreSQL services. For chains of tasks or shell commands, pg_timetable or an external scheduler such as a cloud scheduler service is a better fit.

Do I still need maintenance jobs on a managed service?

Backup jobs, no: the service makes the backups. Index and statistics maintenance usually remains your responsibility, and so do jobs with business logic such as imports, cleanup and reports.

Why does my job run at the wrong hour after the migration?

Agent schedules use the local time of the server, and managed services use UTC by default. On Azure SQL Managed Instance and Amazon RDS the time zone is chosen when the instance is created. Check the time zone and adjust the schedules.

Read next

See how many SQL Server Agent jobs depend on your database before you migrate: run the read-only script and paste the result. Free, and nothing leaves your browser.

Start the free scan