是否有自动终止Azure SQL DW的选项

时间:2017-12-14 11:21:00

标签: azure terminate azure-sqldw

我使用的是Azure SQL DW,每小时花费更多。所以我想知道是否有一个小时后自动终止SQL DW的选项?

3 个答案:

答案 0 :(得分:3)

您可以暂停Azure数据仓库,然后只需支付使用的存储空间。 您可以使用Azure自动化帐户和Runbook自动暂停DWH。 这篇博客解释了这个过程: https://blogs.msdn.microsoft.com/allanmiller/2017/09/20/pausing-azure-sql-data-warehouse-using-an-automation-runbook/

马库斯

答案 1 :(得分:2)

是的,这是可能的。

为了节省成本,您可以按需暂停和恢复计算资源。例如,如果您在晚上和周末不能使用数据库,则可以在这些时间暂停,并在白天恢复。在数据库暂停时,您不会为DWU付费。

暂停数据库时:

计算和内存资源将返回到数据中心的可用资源池

  • 暂停期间DWU成本为零。

  • 数据存储不受影响,您的数据保持不变。

  • SQL数据仓库取消所有正在运行或排队的操作。

要暂停数据库,请使用Suspend-AzureRmSqlDatabase cmdlet

Suspend-AzureRmSqlDatabase –ResourceGroupName "ResourceGroup1" `
–ServerName "Server01" –DatabaseName "Database02"

要启动数据库,请使用Resume-AzureRmSqlDatabase cmdlet。

Resume-AzureRmSqlDatabase –ResourceGroupName "ResourceGroup1" `
–ServerName "Server01" -DatabaseName "Database02"

更多信息请参阅此official document

正如Markus Bohse所说,你也可以使用自动化来做到这一点。

enter image description here

注意:您也可以编写Runbook来启动数据库。

更新:如果您想使用java来执行此操作,请参阅此API document

public void pauseDataWarehouse()

更新

您还可以使用Rest API执行此操作。见link

POST https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Sql/servers/{server-name}/databases/{database-name}/pause?api-version=2014-04-01-preview HTTP/1.1

答案 2 :(得分:0)

您可以使用Runbook或Powershell脚本来暂停dn恢复SQL DWH。

Powershell脚本如下。如果您想使用“ Runbook”,请告诉我


[CmdletBinding(DefaultParametersetName='None')]
Param 
(    
    [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] 
    [String] 
    $AzureSubscriptionId, 
    [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] 
    [String] 
    $AzureDataWareHouseList="All", 
    [Parameter(Mandatory=$true)][ValidateSet("Suspend","Resume")] 
    [String] 
    $Action 
)

function PauseAzureDWH
{
    Param
    (
    [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] 
    [String] 
    $AzureSubscriptionId, 
    [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] 
    [String] 
    $AzureDataWareHouseList="All", 
    [Parameter(Mandatory=$true)][ValidateSet("Suspend","Resume")] 
    [String] 
    $Action
    )
    try     
    {

    Login-AzureRmAccount
    Select-AzureRmSubscription -SubscriptionId $AzureSubscriptionId 

    if($AzureDataWareHouseList -ne "All") 
    {
        $AzureDWHList = @()
        $AzureDWHTotalList = $AzureDataWareHouseList.Split(",") 
        foreach($DWHitem in $AzureDWHTotalList)
        {
            $DWH = "*$DWHitem*"
            $DWH = Get-AzureRmResource | Where-Object ResourceName -like $DWH
            if($DWH -ne $Null)
            {
                $dwc = $DWH.ResourceName.split("/")
                # splat reused parameter lists
                $ThisDW = @{
                'ResourceGroupName' = $DWH.ResourceGroupName
                'ServerName' = $dwc[0]
                'DatabaseName' = $dwc[1]
                }
                $AzureDWHList += $ThisDW
            }
            else
            {
                Write-Warning "Given DataWarehouse '$DWHitem' is not found in given subscription"
            }
        }
    }
    else 
    {
        [array]$TotalDataWareHouseList = Get-AzureRmResource | Where-Object ResourceType -EQ "Microsoft.Sql/servers/databases" | Where-Object Kind -Like "*datawarehouse*"
        $AzureDWHList = @()
        foreach($DWH in $TotalDataWareHouseList)
        {
            $dwc = $DWH.ResourceName.split("/")
            $ThisDW = @{
            'ResourceGroupName' = $DWH.ResourceGroupName
            'ServerName' = $dwc[0]
            'DatabaseName' = $dwc[1]
            }
            $AzureDWHList += $ThisDW
        }
    }

    <# foreach($AzureDWHItem in $AzureDWHList) 
    {
        if(!(Get-AzureRmResource | ? {$_.Name -eq $AzureDWHItem.ServerName}) ) 
        {
            throw " AzureDWH : [$AzureDWHItem] - Does not exist! - please Check your inputs " 
        }
    } #>

    if($Action -eq "Suspend") 
    {
        Write-Output "Suspending Azure DataWareHouses"; 
        foreach ($AzureDWH in $AzureDWHList) 
        { 
            $status = Get-AzureRmSqlDatabase @AzureDWH | Select Status
            if($status.Status -eq "Online")
            {
                Suspend-AzureRmSqlDatabase @AzureDWH
            }
        }
    }
    else 
    { 
        Write-Output "Resuming Azure DataWareHouses"; 
        foreach ($AzureDWH in $AzureDWHList) 
        {
            $status = Get-AzureRmSqlDatabase @AzureDWH | Select Status
            if($status.Status -eq "Paused")
            {
                Resume-AzureRmSqlDatabase @AzureDWH
            }
        }
    }
}

catch
{
    Write-Error " Exception while getting resource details and writing back to CSV"
    Write-Error $_.Exception.message
    Write-Error " ErrorStack: $Error[0] "
    exit 1

}
}

PauseAzureDWH -AzureSubscriptionId $AzureSubscriptionId -AzureDataWareHouseList $AzureDataWareHouseList -Action $Action