sync
This commit is contained in:
@@ -263,7 +263,7 @@ enum backupBehavior{
|
|||||||
restore product_superset : 00:05:40
|
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 Artikel_History_Superset -backupAutoBehavior Auto
|
||||||
#push-superset -supersetToCopy product_superset -backupAutoBehavior Auto
|
push-superset -supersetToCopy product_superset -backupAutoBehavior Auto
|
||||||
|
|
||||||
@@ -8,7 +8,38 @@ function log-out{
|
|||||||
)
|
)
|
||||||
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") :: $msg"
|
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
|
.SYNOPSIS
|
||||||
Push a superset from prodDB to the BAG Azure managed sql instance
|
Push a superset from prodDB to the BAG Azure managed sql instance
|
||||||
@@ -343,30 +374,47 @@ END
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#restore superset
|
#restore superset if not found on the MI instance
|
||||||
$url=$backupFile
|
$db_retry_count = 0
|
||||||
$sqlRestore="RESTORE DATABASE [$supersetToCopy] FROM URL = N'$url'; "
|
$db_retry_max_count = 5
|
||||||
$retryCount = 0
|
$db_exists = find-db-exists-MI -superset $supersetToCopy
|
||||||
$success = $false
|
|
||||||
while (-not $success -and $retryCount -lt $maxRetries) {
|
while(($db_exists -eq $false) -and ($db_retry_count -lt $db_retry_max_count) ){
|
||||||
try{
|
$url=$backupFile
|
||||||
Invoke-Sqlcmd -ServerInstance $MIInstance -Query $sqlRestore -Credential $credentialMI
|
$sqlRestore="RESTORE DATABASE [$supersetToCopy] FROM URL = N'$url'; "
|
||||||
log-out -msg "Restored $supersetToCopy"
|
$retryCount = 0
|
||||||
$success=$true
|
$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
|
Start-Sleep -Seconds $retryInterval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(-not $success){
|
#check that after all tries, we have a db
|
||||||
write-error "Error restoring db $supersetToCopy"
|
if(-not(find-db-exists-MI -superset $supersetToCopy)){
|
||||||
|
Write-Error "Superset $supersetToCopy is not present after restore !"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#create user for sql-au_bag_apv
|
#create user for sql-au_bag_apv
|
||||||
$sqlUser="
|
$sqlUser="
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user