This commit is contained in:
Thierry Schork
2025-05-14 15:26:32 +02:00
parent 86f48765e2
commit b9cfbda6dc
2 changed files with 67 additions and 19 deletions

View File

@@ -263,7 +263,7 @@ enum backupBehavior{
restore product_superset : 00:05:40
#>
#push-superset -supersetToCopy sl2007_superset -backupAutoBehavior Auto
push-superset -supersetToCopy sl2007_superset -backupAutoBehavior Auto
push-superset -supersetToCopy Artikel_History_Superset -backupAutoBehavior Auto
#push-superset -supersetToCopy product_superset -backupAutoBehavior Auto
push-superset -supersetToCopy product_superset -backupAutoBehavior Auto

View File

@@ -9,6 +9,37 @@ function log-out{
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") :: $msg"
}
<#1
.SYNOPSIS
Check if a db with the specified name exists on the managed instant
.PARAMETER
[string] $superset
The name of the database to check if it exists on the managed instance
#>
function find-db-exists-MI{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string] $superset
)
$ret = $false
$sql_check="
select 1 as ret
from sys.databases d
where name = '$superset'
"
$check_result = Invoke-Sqlcmd -ServerInstance $MIInstance -Query $sql_check -Credential $credentialMI
if($check_result -and $check_result["ret"] -eq "1"){
$ret = $true
}
return $ret
}
<#
.SYNOPSIS
Push a superset from prodDB to the BAG Azure managed sql instance
@@ -343,30 +374,47 @@ END
}
#restore superset
$url=$backupFile
$sqlRestore="RESTORE DATABASE [$supersetToCopy] FROM URL = N'$url'; "
$retryCount = 0
$success = $false
while (-not $success -and $retryCount -lt $maxRetries) {
try{
Invoke-Sqlcmd -ServerInstance $MIInstance -Query $sqlRestore -Credential $credentialMI
log-out -msg "Restored $supersetToCopy"
$success=$true
#restore superset if not found on the MI instance
$db_retry_count = 0
$db_retry_max_count = 5
$db_exists = find-db-exists-MI -superset $supersetToCopy
while(($db_exists -eq $false) -and ($db_retry_count -lt $db_retry_max_count) ){
$url=$backupFile
$sqlRestore="RESTORE DATABASE [$supersetToCopy] FROM URL = N'$url'; "
$retryCount = 0
$success = $false
while (-not $success -and $retryCount -lt $maxRetries) {
try{
Invoke-Sqlcmd -ServerInstance $MIInstance -Query $sqlRestore -Credential $credentialMI
log-out -msg "Restored $supersetToCopy"
$success=$true
}
catch{
$retryCount++
Start-Sleep -Seconds $retryInterval
}
}
catch{
$retryCount++
if(-not $success){
write-error "Error restoring db $supersetToCopy"
exit 1
}
$db_retry_count += 1
$db_exists = find-db-exists-MI -superset $supersetToCopy
if(-not($db_exists)){
Start-Sleep -Seconds $retryInterval
}
}
if(-not $success){
write-error "Error restoring db $supersetToCopy"
#check that after all tries, we have a db
if(-not(find-db-exists-MI -superset $supersetToCopy)){
Write-Error "Superset $supersetToCopy is not present after restore !"
exit 1
}
#create user for sql-au_bag_apv
$sqlUser="