You are on page 1of 31

Module 7:

Automating
Administrative Tasks
Overview

Automating Administrative Tasks in SQL Server 2005


Configuring SQL Server Agent
Creating Jobs and Operators
Creating Alerts
Managing Multiple Servers
Managing SQL Server Agent Security
Lesson 1: Automating Administrative Tasks in SQL
Server 2005

Benefits of Automation
What Is the Maintenance Plan Wizard?
What Is SQL Server Agent?
Practice: Using the Maintenance Plan Wizard
Benefits of Automation

Reduced administrative workload


Reduced risk of overlooking vital maintenance tasks
Reduced risk of human error
Proactive management
What Is the Maintenance Plan Wizard?

Helps database administrators schedule core tasks


Creates one or more SQL Server Agent jobs
Administrators can edit and create plans manually
What Is SQL Server Agent?

The component of SQL Server responsible


for automation
Runs as a Windows Service
Must be running to perform jobs, fire alerts, and
contact operators
Practice: Using the Maintenance Plan Wizard

In this practice, you will:


Create a maintenance plan by using the
Maintenance Plan Wizard
Verify that the maintenance plan executed
successfully
Lesson 2: Configuring SQL Server Agent

Considerations for SQL Server Agent Configuration


Options for SQL Server Agent Mail
Demonstration: Configuring Database Mail
Considerations for SQL Server Agent Configuration

SQL Server Agent service startup mode


 SQL Server Agent service is not configured to start
automatically by default
SQL Server Agent service account
 Requires log on as a service user right
SQL Server Agent service dependencies
 SQL Server service
 Messenger service for Net Send notifications
Options for SQL Server Agent Mail

Database Mail
 Uses SMTP
 Requires mail profile for the SQL Server Agent account
 SQL Server Agent account must be a member of the
DatabaseMailUserRole
 SQL Server Agent service must be restarted
SQL Mail
 MAPI-based
 Uses Microsoft Exchange Server
 Included for backward compatibility
Demonstration: Configuring Database Mail

In this demonstration, you will see how to:


Configure Database Mail
Configure SQL Server Agent to use Database
Mail
Test SQL Server Agent e-mail functionality
Lesson 3: Creating Jobs and Operators

What Is a Job?
What Are Operators?
How to Create Job Steps
What Is the Job Activity Monitor?
Practice: Implementing Operators and Jobs
What Is a Job?

Specified series of operations performed sequentially by


SQL Server Agent
Can include Transact-SQL, command-line application, and
ActiveX script steps
Can be scheduled to run once, run repeatedly, or be
started manually
What Are Operators?

People or groups that can receive notifications


 Notifications can be from a job, a job step, or an alert
Can be notified by using e-mail, pagers, or net
send messages
Fail-safe operator can be specified
How to Create Job Steps

Job step 1: Back up Database Yes


Fail?
(Transact-SQL)
Write to
No Application Log
Job step 2: Transfer Data Yes
Fail?
(CmdExec)

No
Notify operator
Job step 3: Custom Yes
Fail?
Application (ActiveX Script)

No

Notify operator
What Is the Job Activity Monitor?

SQL Server Management Studio tool


Allows you to:
 Start and stop jobs
 View job properties
 View the history for a specific job
 Refresh the information in the Agent Job Activity grid
(manual or automatic)
Practice: Implementing Operators and Jobs

In this practice, you will:


Create an operator based on the
Student user
Create a job to backup the
master database
Test the job and verify that the
operator is notified
Lesson 4: Creating Alerts

What Is an Alert?
How to Create an Alert
Practice: Implementing Alerts
What Is an Alert?

Predefined response to an event


Triggered by jobs, performance conditions, or application log
events
Can notify an operator or start a specified job
How to Create an Alert

Use SQL Server Management Studio or sp_add_alert


Specify:
 Alert name
 Event or condition that triggers the alert
 Response – notify an operator, start a job
Practice: Implementing Alerts

In this practice, you will create an alert that


informs an operator when a critical database
event occurs
Lesson 5: Managing Multiple Servers

What Are Master and Target Servers?


Considerations for Multi-Server Jobs
What Is Event Forwarding?
Demonstration: Implementing Event Forwarding
What Are Master and Target Servers?

Master server
 Holds central copy of job definitions
 Distributes jobs to enlisted target servers
 Receives messages from enlisted target servers
Target servers
 Are assigned to one master server
 Connect periodically to the master server to update their
schedule of jobs
 Download any new jobs
Considerations for Multi-Server Jobs

SQL Server Agent service and the SQL Server service must be running
as Windows domain accounts
First server enlisted becomes the master server; subsequent servers
enlisted become target servers
MSXOperator is created on master server to receive notifications
Create jobs on the master server and specify the required
target servers
What Is Event Forwarding?

Forward event messages to an instance of SQL Server


 All events
 Events above a specified severity level
Demonstration: Implementing Event Forwarding

In this demonstration, you will see how to:


Start a second instance of SQL Server to act
as a master server
Configure the SQL Server instance as an
events forwarding server
Lesson 6: Managing SQL Server Agent Security

What Are SQL Server Agent Roles?


What Are SQL Server Agent Proxies?
Practice: Implementing SQL Server Agent Proxies
What Are SQL Server Agent Roles?

Database roles in the msdb database with predefined SQL


Server Agent permissions
 SQLAgentUserRole
 SQLAgentReaderRole
 SQLAgentOperatorRole
What Are SQL Server Agent Proxies?

Define the security context for a job step


Provide granular control over access to subsystems
Are mapped to Windows users by using credentials
 The user specified in the credential must have the log on
as a batch job user right
Can only be used by principals with permission
 Logins
 Fixed server roles
 Database roles in the msdb database
Practice: Implementing SQL Server Agent Proxies

In this practice, you will:


Create a new credential for the SQL Server
Agent proxy
Create a SQL Server Agent proxy
Create a job that uses the SQL Server Agent
proxy
Test the job
Lab: Automating Administrative Tasks

Exercise 1: Configuring SQL


Server Agent
Exercise 2: Creating Operators and Jobs
Exercise 3: Creating Alerts

You might also like