如何解决作为将本地数据仓库迁移到 Azure 的一部分,是否需要重新发布 powerBI 报告
我的组织将从内部部署的 sql server 数据仓库迁移到 azure sql 数据库。
目前,我们使用网关来允许连接到本地数据仓库
作为迁移的一部分,azure 数据库将被重命名。
这是否意味着需要重新发布所有 PowerBI 报告并指向新的 azure DWH?
解决方法
如果数据库架构保持不变,那么您可以简单地使用 Power BI REST API 到 change the datasource 和 patch the credentials。例如,这可以通过使用 Power BI Management CmdLets 的 PowerShell 来完成。首先,以管理员身份启动 PowerShell 并通过执行以下脚本安装 CmdLets:
Install-Module MicrosoftPowerBIMgmt
如果您在计算机上没有管理员权限,或者由于某些其他原因不想为所有用户安装这些,您可以只为当前用户安装:
Install-Module MicrosoftPowerBIMgmt -Scope CurrentUser
更新前几行的值以指向 Azure SQL 数据库和发布的报告,然后执行脚本更改数据源:
# Fill these ###################################################
$workspaceName = "The name of the workspace where the report is published"
$datasetName = "The name of the report"
$sqlDatabaseServer = "servername.database.windows.net"
$sqlDatabaseName = "Database name"
$username = "powerbiuser@yourcompany.com"
$password = "the password of the power bi user" | ConvertTo-SecureString -asPlainText -Force
################################################################
Import-Module MicrosoftPowerBIMgmt
Clear-Host
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Connect-PowerBIServiceAccount -Credential $credential | Out-Null
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $datasetName
$datasource = Get-PowerBIDatasource -WorkspaceId $workspace.Id -DatasetId $dataset.Id
# Construct url
$workspaceId = $workspace.Id
$datasetId = $dataset.Id
$datasourceUrl = "groups/$workspaceId/datasets/$datasetId/datasources"
# Call the REST API to get gateway Id,datasource Id and current connection details
$datasourcesResult = Invoke-PowerBIRestMethod -Method Get -Url $datasourceUrl | ConvertFrom-Json
# Parse the response
$datasource = $datasourcesResult.value[0]
$gatewayId = $datasource.gatewayId
$datasourceId = $datasource.datasourceId
$sqlDatabaseServerCurrent = $datasource.connectionDetails.server
$sqlDatabaseNameCurrent = $datasource.connectionDetails.database
# Construct url for update
$datasourePatchUrl = "groups/$workspaceId/datasets/$datasetId/Default.UpdateDatasources"
# create HTTP request body to update datasource connection details
$postBody = @{
"updateDetails" = @(
@{
"connectionDetails" = @{
"server" = "$sqlDatabaseServer"
"database" = "$sqlDatabaseName"
}
"datasourceSelector" = @{
"datasourceType" = "Sql"
"connectionDetails" = @{
"server" = "$sqlDatabaseServerCurrent"
"database" = "$sqlDatabaseNameCurrent"
}
"gatewayId" = "$gatewayId"
"datasourceId" = "$datasourceId"
}
})
}
$postBodyJson = ConvertTo-Json -InputObject $postBody -Depth 6 -Compress
# Execute POST operation to update datasource connection details
Invoke-PowerBIRestMethod -Method Post -Url $datasourePatchUrl -Body $postBodyJson
# NOTE: dataset credentials must be reset after updating connection details
现在更新以下脚本开头的值并执行它以修补生产数据库的凭据:
# Fill these ###################################################
$workspaceName = "The name of the workspace where the report is published"
$reportName = "The name of the report"
$sqlUserName = "user name"
$sqlUserPassword = "password"
$username = "powerbiuser@yourcompany.com"
$password = "the password of the power bi user" | ConvertTo-SecureString -asPlainText -Force
################################################################
Import-Module MicrosoftPowerBIMgmt
Clear-Host
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Connect-PowerBIServiceAccount -Credential $credential | Out-Null
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $reportName
$workspaceId = $workspace.Id
$datasetId = $dataset.Id
$datasources = Get-PowerBIDatasource -WorkspaceId $workspaceId -DatasetId $datasetId
foreach($datasource in $datasources) {
$gatewayId = $datasource.gatewayId
$datasourceId = $datasource.datasourceId
$datasourePatchUrl = "gateways/$gatewayId/datasources/$datasourceId"
Write-Host "Patching credentials for $datasourceId"
# HTTP request body to patch datasource credentials
$userNameJson = "{""name"":""username"",""value"":""$sqlUserName""}"
$passwordJson = "{""name"":""password"",""value"":""$sqlUserPassword""}"
$patchBody = @{
"credentialDetails" = @{
"credentials" = "{""credentialData"":[ $userNameJson,$passwordJson ]}"
"credentialType" = "Basic"
"encryptedConnection" = "NotEncrypted"
"encryptionAlgorithm" = "None"
"privacyLevel" = "Organizational"
}
}
# Convert body contents to JSON
$patchBodyJson = ConvertTo-Json -InputObject $patchBody -Depth 6 -Compress
# Execute PATCH operation to set datasource credentials
Invoke-PowerBIRestMethod -Method Patch -Url $datasourePatchUrl -Body $patchBodyJson
}
$datasetRefreshUrl = "groups/$workspaceId/datasets/$datasetId/refreshes"
Write-Host "Refreshing..."
Invoke-PowerBIRestMethod -Method Post -Url $datasetRefreshUrl
当然,这些脚本可以扩展为自动处理工作区中的所有报告,或者枚举所有工作区等,但这取决于您组织中的部署,我们不知道详细信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。