Azure中用于多服务器管理SQL代理作业的替代方法?

问题描述 投票:1回答:1

目前在我的组织中有15个QA和5个UAT SQL环境。截至目前,我们正在目标服务器之一中使用SQL Server的多服务器管理功能管理所有SQL代理作业。现在我们计划在Azure上迁移这些所有SQL环境数据库。在azure中,我们使用SQL数据库服务而不是任何VM盒。那么,是否有任何功能或替代解决方案来管理所有环境中的所有工作在azure的中心位置。所有SQL作业都只是T-SQL的类型。

azure-devops azure-sql-database azure-storage
1个回答
1
投票

您可以使用Azure Automation将所有Azure SQL数据库作业集中在一个位置。

您可以在Azure自动化上使用以下PowerShell Workflow来安排在任何Azure SQL数据库上执行任何存储过程,无论它们驻留在哪个Azure SQL逻辑服务器上。

workflow SQL_Agent_SprocJob
{
[cmdletbinding()]
param
(
# Fully-qualified name of the Azure DB server
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $SqlServerName,
# Name of database to connect and execute against
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $DBName,
# Name of stored procedure to be executed
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string] $StoredProcName,
# Credentials for $SqlServerName stored as an Azure Automation credential asset
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[PSCredential] $Credential
)
inlinescript
{
Write-Output “JOB STARTING”
# Setup variables
$ServerName = $Using:SqlServerName
$UserId = $Using:Credential.UserName
$Password = ($Using:Credential).GetNetworkCredential().Password
$DB = $Using:DBName
$SP = $Using:StoredProcName
# Create & Open connection to Database
$DatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
$DatabaseConnection.ConnectionString = “Data Source = $ServerName; Initial Catalog = $DB; User ID = $UserId; Password = $Password;”
$DatabaseConnection.Open();
Write-Output “CONNECTION OPENED”
# Create & Define command and query text
$DatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
$DatabaseCommand.CommandType = [System.Data.CommandType]::StoredProcedure
$DatabaseCommand.Connection = $DatabaseConnection
$DatabaseCommand.CommandText = $SP
Write-Output “EXECUTING QUERY”
# Execute the query
$DatabaseCommand.ExecuteNonQuery()
# Close connection to DB
$DatabaseConnection.Close()
Write-Output “CONNECTION CLOSED”
Write-Output “JOB COMPLETED”
}
}

使用this分步教程开始。

© www.soinside.com 2019 - 2024. All rights reserved.