PowerShell 检查 Azure SQL 托管实例中的可用剩余空间

huangapple go评论59阅读模式
英文:

PowerShell to check available free space in Azure SQL Managed Instance

问题

我正在编写一个PowerShell脚本,用于从Azure存储帐户动态恢复数据库到托管实例。为了增加额外的功能,我正在寻找一个PowerShell模块,可以帮助我找到托管实例中的可用空间,以避免在最后一刻恢复失败。

有人可以帮忙吗?

英文:

I am working on a PowerShell script to restore databases dynamically from the Azure storage account to Managed instance. To add additional functionality I am looking for a PowerShell module that can help me to find free space from managed instances to avoid restoring failure at the last moment.

can anyone help me?

答案1

得分: 1

你可以使用PowerShell的Get-AzMetric来实现这个。在下面的脚本中查看$SpaceMetric。

$StorageAccounts = Get-AzResource -ResourceType Microsoft.Sql/managedInstances
FOREACH($StorageAccount in $StorageAccounts){
    $ResourceId = $StorageAccount.ResourceId
    $Start = (get-date).AddDays(-7)
    $End = get-date         
    $SpaceMetric = Get-AzMetric -ResourceId $ResourceId -MetricName "storage_space_used_mb" -WarningAction Ignore
    $IOMetric = Get-AzMetric -ResourceId $ResourceId -MetricName "io_requests" -StartTime $Start -EndTime $End -WarningAction Ignore
    $CoreMetric = Get-AzMetric -ResourceId $ResourceId -MetricName "virtual_core_count" -WarningAction Ignore

    #Load Variables for SQL Statement.
    $TeamGroupName = $SubscriptionID.TeamGroupsName
    $ServiceName = $SubscriptionID.ServiceName
    $SubscriptionName = $SubscriptionID.SubscriptionName
    $SubID = $SubscriptionID.SubscriptionID
    $StorageAccountName = $StorageAccount.Name
    $StorageType = 'SQL-MI'
    $SQLMISize = ($SpaceMetric.Data | Select-Object -First 1).Average/1024
    $TotalRequests = ($IOMetric.Data | Select-Object -First 1).Average
    $CoreCount = ($CoreMetric.Data | Select-Object -First 1).Average
    $Region = $StorageAccount.Location
    $RefreshedAt = Get-Date
}
英文:

You can use PowerShell Get-AzMetric for that. See $SpaceMetric on below script.

$StorageAccounts = Get-AzResource -ResourceType Microsoft.Sql/managedInstances
        FOREACH($StorageAccount in $StorageAccounts){
            $ResourceId = $StorageAccount.ResourceId
            $Start = (get-date).AddDays(-7)
            $End = get-date         
            $SpaceMetric = Get-AzMetric -ResourceId $ResourceId -MetricName "storage_space_used_mb" -WarningAction Ignore
            $IOMetric = Get-AzMetric -ResourceId $ResourceId -MetricName "io_requests" -StartTime $Start -EndTime $End -WarningAction Ignore
            $CoreMetric = Get-AzMetric -ResourceId $ResourceId -MetricName "virtual_core_count" -WarningAction Ignore

            #Load Variables for SQL Statement.
            $TeamGroupName = $SubscriptionID.TeamGroupsName
            $ServiceName = $SubscriptionID.ServiceName
            $SubscriptionName = $SubscriptionID.SubscriptionName
            $SubID = $SubscriptionID.SubscriptionID
            $StorageAccountName = $StorageAccount.Name
            $StorageType = 'SQL-MI'
            $SQLMISize = ($SpaceMetric.Data | Select-Object -First 1).Average/1024
            $TotalRequests = ($IOMetric.Data | Select-Object -First 1).Average
            $CoreCount = ($CoreMetric.Data | Select-Object -First 1).Average
            $Region = $StorageAccount.Location
            $RefreshedAt = Get-Date

huangapple
  • 本文由 发表于 2023年7月17日 23:57:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706226.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定