{"id":19165,"date":"2017-03-17T09:00:00","date_gmt":"2017-03-17T16:00:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/dataplatforminsider\/?p=19165"},"modified":"2024-01-22T22:50:45","modified_gmt":"2024-01-23T06:50:45","slug":"sql-server-on-linux-running-jobs-with-sql-server-agent","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/sql-server\/blog\/2017\/03\/17\/sql-server-on-linux-running-jobs-with-sql-server-agent\/","title":{"rendered":"SQL Server on Linux: Running jobs with SQL Server Agent"},"content":{"rendered":"
In keeping with our goal to enable SQL Server features across all platforms supported by SQL Server, Microsoft is excited to announce the preview of SQL Server Agent on Linux in SQL Server vNext Community Technology Preview (CTP) 1.4.<\/p>\n
SQL Server Agent is a component that executes scheduled administrative tasks, called \u201cjobs.\u201d Jobs contain one or more job steps. Each step contains its own task such as backing up a database. SQL Server Agent can run a job on a schedule, in response to a specific event, or on demand. For example, if you want to back up all the company databases every weekday after hours, you can automate doing so by scheduling an Agent job to run a backup at 22:00 Monday through Friday.<\/p>\n
We have released SQL Server Agent packages for Ubuntu, RedHat Enterprise Linux, and SUSE Linux Enterprise Server that you can install via apt-get, yum, and zypper<\/a>. Once you install these packages, you can create T-SQL Jobs using SSMS, sqlcmd, and other GUI and command line tools.<\/p>\n Here is a simple example:<\/p>\n CREATE DATABASE SampleDB ;<\/span><\/p>\n USE msdb ;<\/span><\/p>\n GO<\/span><\/p>\n EXEC dbo.sp_add_job<\/span><\/p>\n @job_name = N’Daily SampleDB Backup’ ;<\/span><\/p>\n GO<\/span><\/p>\n EXEC sp_add_jobstep<\/span><\/p>\n @job_name = N’Daily SampleDB Backup’,<\/span><\/p>\n @step_name = N’Backup database’,<\/span><\/p>\n @subsystem = N’TSQL’,<\/span><\/p>\n @command = N’BACKUP DATABASE SampleDB TO DISK = \\<\/span><\/p>\n N”\/var\/opt\/mssql\/data\/SampleDB.bak” WITH NOFORMAT, NOINIT, \\<\/span><\/p>\n NAME = ”SampleDB-full”, SKIP, NOREWIND, NOUNLOAD, STATS = 10′,<\/span><\/p>\n @retry_attempts = 5,<\/span><\/p>\n @retry_interval = 5 ;<\/span><\/p>\n GO<\/span><\/p>\n EXEC dbo.sp_add_schedule<\/span><\/p>\n @schedule_name = N’Daily SampleDB’,<\/span><\/p>\n @freq_type = 4,<\/span><\/p>\n @freq_interval = 1,<\/span><\/p>\n @active_start_time = 233000 ;<\/span><\/p>\n USE msdb ;<\/span><\/p>\n GO<\/span><\/p>\n EXEC sp_attach_schedule<\/span><\/p>\n @job_name = N’Daily SampleDB Backup’,<\/span><\/p>\n @schedule_name = N’Daily SampleDB’;<\/span><\/p>\n GO<\/span><\/p>\n EXEC dbo.sp_add_jobserver<\/span><\/p>\n @job_name = N’Daily SampleDB Backup’,<\/span><\/p>\n @server_name = N'(LOCAL)’;<\/span><\/p>\n GO<\/span><\/p>\n EXEC dbo.sp_start_job N’ Daily SampleDB Backup’ ;<\/span><\/p>\n GO<\/span><\/p>\n The following types of SQL Agent jobs are not currently supported on Linux:<\/p>\n If you\u2019re ready to get started with SQL Server on Linux, here\u2019s how to install the SQL Server Agent package via apt-get, yum, and zypper.<\/a> And here\u2019s how to create your first T-SQL job and show you to use SSMS with SQL Agent<\/a>.<\/p>\n In keeping with our goal to enable SQL Server features across all platforms supported by SQL Server, Microsoft is excited to announce the preview of SQL Server Agent on Linux in SQL Server vNext Community Technology Preview (CTP) 1.4. SQL Server Agent is a component that executes scheduled administrative tasks, called \u201cjobs.\u201d Jobs contain one<\/p>\n","protected":false},"author":1457,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"_classifai_error":"","_classifai_text_to_speech_error":"","footnotes":""},"post_tag":[],"product":[5227,2409],"content-type":[2424,2448],"topic":[2475],"coauthors":[2487],"class_list":["post-19165","post","type-post","status-publish","format-standard","hentry","product-sql","product-sql-server-2017-on-linux","content-type-best-practices","content-type-updates","topic-oltp-database-management","review-flag-1593580427-503","review-flag-1-1593580431-15","review-flag-4-1593580446-456","review-flag-5-1593580452-31"],"yoast_head":"\n\n
\n
\n
\n
\n
Limitations:<\/h2>\n
\n
Get started<\/h2>\n
Learn more<\/h2>\n
\n