Quantcast
Viewing all articles
Browse latest Browse all 123

HOW TO Refresh NAV database in NAV Container without the need to Recreate the container

This post actually started with an Issue I created in NavContainerHelper GitHub.

Image may be NSFW.
Clik here to view.
💡
I’m working in a script for Continuous Integration and although the creation of a container requires few minutes I was looking how to optimize the time of execution of the whole build process.

Freddy Kristiansen is a Microsoft Evangelist that is working hard to make it easier to work with NAV using Docker Containers, thanks again Freddy.

Freddy initially marked my issue with label “WONTFIX” Image may be NSFW.
Clik here to view.
🙁
but after I explained to him my motivation he changed the label to “ENHANCEMENT” Image may be NSFW.
Clik here to view.
😀

He did not include any new functionality to NavContainerHelper but he kindly provided me with the script to copy and paste, and as I always do, I like to share good things.

Solution:
Right after the creation of a NAV Container, run the following script:

# To add just after the creation of the NAV Container
$containerName = "scadev"
$config = Get-NavContainerServerConfiguration -ContainerName $containerName
Invoke-ScriptInNavContainer -containerName $containerName -scriptblock { 
  Param($DatabaseServer, $DatabaseInstance, $DatabaseName, $NewDatabaseName)
    Copy-navDatabase -DatabaseServer $DatabaseServer -DatabaseInstance 
  $DatabaseInstance -SourceDatabaseName $DatabaseName -DestinationDatabaseName 
  $NewDatabaseName
} -argumentList $config.DatabaseServer, $config.DatabaseInstance, $config.DatabaseName, "backup"

So next time you run the build process, just verify that the Container exists and in case replace the database with the backup taken previously (it takes 10-20 seconds)

$containerName = "scadev"
if (Test-NavContainer $containerName) {
  $config = Get-NavContainerServerConfiguration -ContainerName $containerName
  Invoke-ScriptInNavContainer -containerName $containerName -scriptblock { 
    Param($DatabaseServer, $DatabaseInstance, $DatabaseName, $NewDatabaseName)
    Copy-navDatabase -DatabaseServer $DatabaseServer -DatabaseInstance 
    $DatabaseInstance -SourceDatabaseName $DatabaseName -DestinationDatabaseName 
    $NewDatabaseName
  } -argumentList $config.DatabaseServer, $config.DatabaseInstance, "backup", $config.DatabaseName
} else {
# Creation of NAV Container
}

Source: https://github.com/Microsoft/navcontainerhelper/issues/315

Did my HOW TO help you? Leave a reply.


Viewing all articles
Browse latest Browse all 123

Trending Articles