microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
382 stars 243 forks source link

SQL Timeout restoring external database #3683

Open Ratmaniac82 opened 1 week ago

Ratmaniac82 commented 1 week ago

I've a timeout error when I try to restore an external database backup. Take care that DB to restore size is 50GB.

Scripts used to create container and cause the issue

$auth = "UserPassword"
$credential = New-Object PSCredential 'admin', (ConvertTo-SecureString -String 'admin' -AsPlainText -Force)
$containerName = "CUSTNAME"
$artifactUrl = Get-BCArtifactUrl -version 23.4 -country "it" -select Latest -type OnPrem
$additionalParameters = @("--storage-opt size=80GB")

$databaseParams = @{
    "databaseServer" = 'host.containerhelper.internal'
    "databaseInstance" = ''
    "databasePrefix" = "$containerName-"
    "databaseName" = 'CRONUS'
    "databaseCredential" = New-Object PSCredential 'admin', (ConvertTo-SecureString -String 'admin' -AsPlainText -Force)
    "multitenant" = $false
}

New-BCContainer @databaseParams -replaceExternalDatabases `
    -bakFile 'C:\NAME.BAK' `
    -accept_eula `
    -accept_outdated `
    -containerName $containerName `
    -artifactUrl $artifactUrl `
    -auth $auth `
    -Credential $credential `
    -alwaysPull `
    -updateHosts `
    -licenseFile 'C:\devlic.bclicense'  `
    -enableTaskScheduler `
    -dns '8.8.8.8' `
    -isolation hyperv `
    -useBestContainerOS `
    -additionalParameters $additionalParameters

Full output of scripts

BcContainerHelper is version 6.0.20
BcContainerHelper is running as administrator
HyperV is Enabled
Host is Microsoft Windows 10 Pro - 10.0.19045.4894
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is never
UseSslForWinRmSession is True
Docker Client Version is 27.2.0
Docker Server Version is 27.2.0
Removing entries from hosts
Removing NAME from container hosts file
Removing NAME-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\NAME
Starting Database Restore job from https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/onprem/23.4.15643
.15715/it
C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.20\Import-BcContainerHelper.ps1
Fetching all docker images
Fetching all docker volumes
Pulling image mcr.microsoft.com/businesscentral:ltsc2019
ltsc2019: Pulling from businesscentral
Digest: sha256:c65428b47791534cad2d4f5827ebdf77dff9b0f76ed806b22784626101eee18e
Status: Image is up to date for mcr.microsoft.com/businesscentral:ltsc2019
mcr.microsoft.com/businesscentral:ltsc2019
Using image mcr.microsoft.com/businesscentral:ltsc2019
Creating Container NAME
Style: onprem
Multitenant: No
Version: 23.4.15643.15715
Platform: 23.0.15712.0
Generic Tag: 1.0.2.46
Container OS Version: 10.0.17763.6293 (ltsc2019)
Host OS Version: 10.0.19045.4894 (22H2)
Using hyperv isolation
Using locale it-IT
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file C:\devlic.bclicense
Additional Parameters:
--storage-opt size=80GB
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\NAME\my:
- AdditionalOutput.ps1
- HelperFunctions.ps1
- license.bclicense
- MainLoop.ps1
- SetupDatabase.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container NAME from image mcr.microsoft.com/businesscentral:ltsc2019
Using Shared Encryption Key file
9f2bb944a2bd517e5d878403c018652beda6bd513e7b0616e7890f6426f2cdb0
Waiting for container NAME to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/onprem/23.4.15643.15715/it
Using installer from C:\Run\210-new
Installing Business Central: multitenant=False, installOnly=False, filesOnly=False, includeTestToolkit=Fa
lse, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, app
ArtifactPath=c:\dl\onprem\23.4.15643.15715\it, platformArtifactPath=c:\dl\onprem\23.4.15643.15715\platfor
m, databasePath=, licenseFilePath=c:\dl\onprem\23.4.15643.15715\it\database\Cronus.bclicense, rebootConta
iner=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\onprem\23.4.15643.15715\platform\ServiceTier\Program Files
c:\dl\onprem\23.4.15643.15715\platform\ServiceTier\System64Folder
Copying PowerShell Scripts
c:\dl\onprem\23.4.15643.15715\platform\WindowsPowerShellScripts\Cloud\NAVAdministration
c:\dl\onprem\23.4.15643.15715\platform\WindowsPowerShellScripts\WebSearch
Copying Web Client Files
c:\dl\onprem\23.4.15643.15715\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\onprem\23.4.15643.15715\platform
c:\dl\onprem\23.4.15643.15715\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\onprem\23.4.15643.15715\platform\ConfigurationPackages
Copying Test Assemblies
C:\dl\onprem\23.4.15643.15715\platform\Test Assemblies
Copying Applications
C:\dl\onprem\23.4.15643.15715\it\Applications
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 26 seconds
Installation complete
Initializing...
Setting host.docker.internal to 10.110.10.25 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 10.110.10.25 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.29.32.1 in container hosts file
Starting Container
Hostname is NAME
PublicDnsName is NAME
WARNING: Container starts with TimeZone = ora solare Europa occidentale, which is not recognized in the l
ist of TimeZones.
Using NavUserPassword Authentication
Waiting for database creation to finish
Error restoring databases. Error was The database restore operation failed due to the following error ret
urned by SQL Server:
Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server
 is not responding.
The backup or restore was aborted.
RESTORE DATABASE is terminating abnormally.
Operation cancelled by user.
in <ScriptBlock>, <Nessun file>: riga 106Error
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/onprem/23.4.15643.15715/it
Using installer from C:\Run\210-new
Installing Business Central: multitenant=False, installOnly=False, filesOnly=False, includeTestToolkit=Fa
lse, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, app
ArtifactPath=c:\dl\onprem\23.4.15643.15715\it, platformArtifactPath=c:\dl\onprem\23.4.15643.15715\platfor
m, databasePath=, licenseFilePath=c:\dl\onprem\23.4.15643.15715\it\database\Cronus.bclicense, rebootConta
iner=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\onprem\23.4.15643.15715\platform\ServiceTier\Program Files
c:\dl\onprem\23.4.15643.15715\platform\ServiceTier\System64Folder
Copying PowerShell Scripts
c:\dl\onprem\23.4.15643.15715\platform\WindowsPowerShellScripts\Cloud\NAVAdministration
c:\dl\onprem\23.4.15643.15715\platform\WindowsPowerShellScripts\WebSearch
Copying Web Client Files
c:\dl\onprem\23.4.15643.15715\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\onprem\23.4.15643.15715\platform
c:\dl\onprem\23.4.15643.15715\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\onprem\23.4.15643.15715\platform\ConfigurationPackages
Copying Test Assemblies
C:\dl\onprem\23.4.15643.15715\platform\Test Assemblies
Copying Applications
C:\dl\onprem\23.4.15643.15715\it\Applications
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 26 seconds
Installation complete
Initializing...
Setting host.docker.internal to 10.110.10.25 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 10.110.10.25 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.29.32.1 in container hosts file
Starting Container
Hostname is NAME
PublicDnsName is NAME
WARNING: Container starts with TimeZone = ora solare Europa occidentale, which is not recognized in the l
ist of TimeZones.
Using NavUserPassword Authentication
Waiting for database creation to finish
Error restoring databases. Error was The database restore operation failed due to the following error ret
urned by SQL Server:
Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server
 is not responding.
The backup or restore was aborted.
RESTORE DATABASE is terminating abnormally.
Operation cancelled by user.
in <ScriptBlock>, <Nessun file>: riga 106
New-BCContainer Telemetry Correlation Id: ac5ab625-ed51-490e-91fc-52e982619c24
Initialization of container NAME failed
In C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.20\ContainerHandling\Wait-NavContain
erReady.ps1:42 car:17
+ ...             throw "Initialization of container $containerName failed" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Initialization of container NAME failed:String) [], Ru 
   ntimeException
    + FullyQualifiedErrorId : Initialization of container NAME failed

Additional context

freddydk commented 3 days ago

Can you try to remove the -replaceExternalDatabases switch and instead restore the databases beforehand, using:

Remove-BcDatabase `
    -databaseServer $databaseServer `
    -databaseInstance $databaseInstance `
    -databaseName "$($databasePrefix)%"
Restore-BcDatabaseFromArtifacts `
    -artifactUrl $artifactUrl `
    -databaseServer $databaseServer `
    -databaseInstance $databaseInstance `
    -databasePrefix $databasePrefix `
    -databaseName $databaseName `
    -multitenant:$multitenant `
    -sqlTimeout $timeout

Here, you can set the timeout on restore.

After this create the container with all the other parameters pointing to the database as before.

Please let me know if this works for you.