Skip to content

Commit

Permalink
adding sqlTimeout par to Restore-BcDatabaseFromArtifacts (#3239)
Browse files Browse the repository at this point in the history
This parameter is useful to restore large databases to external SQL
without it the command will just timeout.

I don't know if the default value makes sense here I just copied it
over. In my case I just want to max it out.

---------

Co-authored-by: Freddy Kristiansen <[email protected]>
  • Loading branch information
lktraser and freddydk authored Nov 29, 2023
1 parent c031b09 commit 9cf2f23
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Bacpac/Restore-BcDatabaseFromArtifacts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Include this switch if you want to split the database .bak file into an application database and a tenant template
.Parameter async
Include this parameter if you want to restore the database asynchronous. A file called <databasePrefix>databasescreated.txt will be created in the containerhelper folder when done
.Parameter sqlTimeout
SQL Timeout for database restore operations
#>
function Restore-BcDatabaseFromArtifacts {
Param(
Expand All @@ -36,7 +38,8 @@ function Restore-BcDatabaseFromArtifacts {
[Parameter(Mandatory=$false)]
[string] $bakFile,
[switch] $multitenant,
[switch] $async
[switch] $async,
[int] $sqlTimeout = -1
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
Expand All @@ -54,7 +57,7 @@ try {
$containerHelperPath = (Get-Item (Join-Path $PSScriptRoot "..\Import-BcContainerHelper.ps1")).FullName
Write-Host $containerHelperPath

$job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile )
$job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout )
$ErrorActionPreference = "Stop"
try {
. "$containerHelperPath"
Expand Down Expand Up @@ -139,8 +142,19 @@ try {
}
}

$newNavDBparams = @{
"DatabaseInstance" = $databaseInstance
"DatabaseServer" = $databaseServer
"DatabaseName" = $dbName
"FilePath" = $bakFile
"DestinationPath" = $destinationPath
}
if ($sqlTimeout -ge 0) {
$newNavDBparams += @{ "timeout" = $sqlTimeout }
}

Write-Host "Restoring database $dbName into $destinationPath"
New-NAVDatabase -DatabaseServer $databaseServer -DatabaseInstance $databaseInstance -DatabaseName $dbName -FilePath $bakFile -DestinationPath $destinationPath | Out-Null
New-NAVDatabase @newNavDBparams | Out-Null

if ($multitenant) {
if ($sqlpsModule) {
Expand Down Expand Up @@ -200,7 +214,7 @@ try {
throw
}

} -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile
} -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout

if (!$async) {
While ($job.State -eq "Running") {
Expand Down

0 comments on commit 9cf2f23

Please sign in to comment.