Skip to content

Commit

Permalink
fix read environment variable when backup or restoring db (#3615)
Browse files Browse the repository at this point in the history
In some situations the reading of environment variables from the
container not works as expected with the `Invoke-ScriptInBcContainer`
cmdlt, f.i. the latest online sandbox (version 24.4.22295.23050) for
Italy on a self-hosted agent not returns any value, on an on-prem
sandbox (version 23 and also version 24) instead returns a value as
expected.

The following statement was launched on pwsh 7.4.2 with docker version
20.10.21, but returns no value:

```pwsh
Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { $env:IsBcSandbox }
```

Using the following fix for this issue works as expected, and is much
more faster then invoking the script:

```pwsh
$inspect = docker inspect $containerName | ConvertFrom-Json
$inspect.Config.Env | Where-Object { $_ -eq "IsBcSandbox=Y" }
```

---------

Co-authored-by: Freddy Kristiansen <[email protected]>
  • Loading branch information
lukas-pfeifhofer and freddydk committed Aug 21, 2024
1 parent 52ddaa4 commit 8352263
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Bacpac/Backup-NavContainerDatabases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ try {
}
elseif (!$bakFolder.Contains('\')) {
$navversion = Get-BcContainerNavversion -containerOrImageName $containerName
if ((Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { $env:IsBcSandbox }) -eq "Y") {
$inspect = docker inspect $containerName | ConvertFrom-Json
$isBcSandbox = $inspect.Config.Env | Where-Object { $_ -eq "IsBcSandbox=Y" }
if ($isBcSandbox) {
$folderPrefix = "sandbox"
}
else {
Expand Down
4 changes: 3 additions & 1 deletion Bacpac/Restore-DatabasesInNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ try {
}
elseif (!$bakFolder.Contains('\')) {
$navversion = Get-BcContainerNavversion -containerOrImageName $containerName
if ((Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { $env:IsBcSandbox }) -eq "Y") {
$inspect = docker inspect $containerName | ConvertFrom-Json
$isBcSandbox = $inspect.Config.Env | Where-Object { $_ -eq "IsBcSandbox=Y" }
if ($isBcSandbox) {
$folderPrefix = "sandbox"
}
else {
Expand Down

0 comments on commit 8352263

Please sign in to comment.