当DB大小太大时,Powershell importBacpac到Azure会失败吗?

时间:2013-10-01 10:55:35

标签: powershell azure azure-sql-database

我使用powershell从bacpac文件创建SQL Azure数据库。但是,当数据库大小超出默认的最大大小时,有时会遇到麻烦。

根据文档,应该可以将数据库大小添加到ImportBacpac方法,但我不确定如何在powershell中使用它。

是否正在使用更改的数据库最大大小恢复数据库?

文档:http://technet.microsoft.com/en-us/library/jj870786.aspx

当前代码

function restore-SQLBackup
([string]$ConnectionString = $(throw "The ConnectionString parameter is required."), 
[string]$DatabaseName = $(throw "The databaseName parameter is required."),
[string]$fileName = $(throw "The fileName parameter is required."), 
[string]$microsoftSqlServerDacPath = "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.SqlServer.Dac.dll") {

Add-Type -Path $microsoftSqlServerDacPath

$Services = new-object Microsoft.SqlServer.Dac.DacServices $ConnectionString

if ($Services -eq $null)
{
    exit
}

$timeStamp = (Get-Date).ToString("yyyy-MM-dd_HH-mm-ss")

$bacpac = [Microsoft.SqlServer.Dac.BacPackage]::Load($fileName)
Write-Host "Starting restoring $DatabaseName at $timeStamp"
$Watch = New-Object System.Diagnostics.StopWatch
$Watch.Start()
$Services.ImportBacpac($bacpac, $DatabaseName)
$Watch.Stop()
Write-Host "Restore completed in" $Watch.Elapsed.ToString()
}

1 个答案:

答案 0 :(得分:1)

尝试更改为:

$Watch.Start() 
$DatabaseSpecifications = New-Object Microsoft.SqlServer.Dac.DacAzureDatabaseSpecification
$DatabaseSpecifications.MaximumSize = 5 #5GB, based on your need
$Services.ImportBacpac($bacpac, $DatabaseName,$DatabaseSpecifications)
$Watch.Stop()

以下是我使用的文档:http://technet.microsoft.com/en-us/library/microsoft.sqlserver.dac.dacazuredatabasespecification.maximumsize.aspx

以下是一般数据库大小调整的cmdlet: http://msdn.microsoft.com/en-us/library/windowsazure/jj983732.aspx