英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论