Elenakretova23

SQL Server on Linux: Running jobs with SQL Server Agent

Discussion created by Elenakretova23 on Nov 29, 2017

In line with our purpose to allow square Server functions across all platforms supported via square Server, Microsoft is happy to announce the preview of sq. Server Agent on Linux in square Server vNext network technology Preview (CTP) 

Sql Server Agent is a part that executes scheduled administrative responsibilities, referred to as “jobs.” Jobs include one or extra task steps. each step carries its own assignment which includes backing up a database. square Server Agent can run a activity on a schedule, in reaction to a selected event, or on demand. as an example, if you want to again up all of the employer databases each weekday after hours, you can automate doing so by using scheduling an Agent task to run a backup at 22:00 Monday thru Friday.

we've got launched sql Server Agent programs for Ubuntu, RedHat agency Linux, and SUSE Linux employer Server that you could install through apt-get, yum, and zypper. when you deploy these packages, you may create T-sq. Jobs the usage of SSMS, sqlcmd, and different GUI and command line gear.

  • Create a job

CREATE DATABASE SampleDB ;

USE msdb ;

GO

EXEC dbo.sp_add_job

@job_name = N’Daily SampleDB Backup’ ;

GO

  • Add one or more job steps

EXEC sp_add_jobstep

@job_name = N’Daily SampleDB Backup’,

@step_name = N’Backup database’,

@subsystem = N’TSQL’,

@command = N’BACKUP DATABASE SampleDB TO DISK = \

N”/var/opt/mssql/data/SampleDB.bak” WITH NOFORMAT, NOINIT, \

NAME = ”SampleDB-full”, SKIP, NOREWIND, NOUNLOAD, STATS = 10′,

@retry_attempts = 5,

@retry_interval = 5 ;

GO

  • Create a job schedule

EXEC dbo.sp_add_schedule

@schedule_name = N’Daily SampleDB’,

@freq_type = 4,

@freq_interval = 1,

@active_start_time = 233000 ;

USE msdb ;

GO

  • Attach the schedule and add the job server

EXEC sp_attach_schedule

@job_name = N’Daily SampleDB Backup’,

@schedule_name = N’Daily SampleDB’;

GO

EXEC dbo.sp_add_jobserver

@job_name = N’Daily SampleDB Backup’,

@server_name = N'(LOCAL)’;

GO

  • Start job

EXEC dbo.sp_start_job N’ Daily SampleDB Backup’ ;

GO

Outcomes