下载所有 SSRS 报告
Download all SSRS reports
我想获取一台服务器中所有 .rdl 文件的副本。
我可以一次手动下载一个报告,但这很耗时,尤其是这个服务器有大约 1500 个报告。
有什么方法或工具可以让我下载所有 .rdl 文件并复制一份吗?[=10=]
这是基于 SQL2016/SSRS2016 但我认为它应该适用于 2012。
SELECT 'http://mySQLServerName/reports/api/v1.0/catalogitems(' + cast(itemid as varchar(256))+ ')/Content/$value' AS url
FROM ReportServer.dbo.Catalog
这将为您提供一份 URL 的列表,每个报告一个。
如果以上方法在 SSRS 2012 中不起作用,请转至报告管理器,就像您要从那里下载文件一样。检查下载按钮上的 URL,您可能会看到一个 URL,其中嵌入了项目 ID。只需调整上面的代码以匹配 url 结构。
这之后你要做什么取决于你。
就我个人而言,我会使用 Chrome 商店 here 中名为 'Tab Save' 的 Chrome 扩展。您只需将上面创建的所有 URL 复制并粘贴到其中,然后点击下载按钮...
如果您只是出于备份目的或类似目的需要它,这可能会有用:Where does a published RDL file sit?
该线程的相关查询是:
select convert(varchar(max), convert(varbinary(max), content))
from catalog
where content is not null
最初的答案是使用 2005 年,我在 2016 年使用过,所以我想它应该适用于 2008 年和 2012 年。
当我不得不使用它时,我也将路径添加到查询中,这样我就知道哪个报告是哪个。
警告:在 SSMS v18 之前,网格结果限制为每个元组 64KB,结果文本限制为每个元组 8,192 个字符。如果您的报告定义大于这些限制,您将无法获得完整的定义。
在 SSMS v18 中,对于网格报告和文本结果,这些限制已增加到每个元组 2MB。
有一种完整且更简单的方法可以使用 PowerShell 执行此操作。
此代码将以与报表服务器完全相同的结构导出所有报表内容。查看 Github wiki 了解其他选项和命令
#------------------------------------------------------
#Prerequisites
#Install-Module -Name ReportingServicesTools
#------------------------------------------------------
#Lets get security on all folders in a single instance
#------------------------------------------------------
#Declare SSRS URI
$sourceRsUri = 'http://ReportServerURL/ReportServer/ReportService2010.asmx?wsdl'
#Declare Proxy so we dont need to connect with every command
$proxy = New-RsWebServiceProxy -ReportServerUri $sourceRsUri
#Output ALL Catalog items to file system
Out-RsFolderContent -Proxy $proxy -RsFolder / -Destination 'C:\SSRS_Out' -Recurse
我创建了这个 powershell 脚本来将它们复制到 ZIP 中。您必须提供 SQL 服务器数据库详细信息。
Add-Type -AssemblyName "System.IO.Compression.Filesystem"
$dataSource = "SQLSERVER"
$user = "sa"
$pass = "sqlpassword"
$database = "ReportServer"
$connectionString = "Server=$dataSource;uid=$user; pwd=$pass;Database=$database;Integrated Security=False;"
$tempfolder = "$env:TEMP\Reports"
$zipfile = $PSScriptRoot + '\reports.zip'
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()
$allreports = $connection.CreateCommand()
$allreports.CommandText = "SELECT ItemID, Path, CASE WHEN Type = 2 THEN '.rdl' ELSE '.rds' END AS Ext FROM Catalog WHERE Type IN(2,5)"
$result = $allreports.ExecuteReader()
$reportable = new-object "System.Data.DataTable"
$reportable.Load($result)
[int]$objects = $reportable.Rows.Count
foreach ($report in $reportable) {
$cmd = $connection.CreateCommand()
$cmd.CommandText = "SELECT CAST(CAST(Content AS VARBINARY(MAX)) AS XML) FROM Catalog WHERE ItemID = '" + $report[0] + "'"
$xmldata = [string]$cmd.ExecuteScalar()
$filename = $tempfolder + $report["Path"].Replace('/', '\') + $report["Ext"]
New-Item $filename -Force | Out-Null
Set-Content -Path ($filename) -Value $xmldata -Force
Write-Host "$($objects.ToString()).$($report["Path"])"
$objects -= 1
}
Write-Host "Compressing to zip file..."
if (Test-Path $zipfile) {
Remove-Item $zipfile
}
[IO.Compression.Zipfile]::CreateFromDirectory($tempfolder, $zipfile)
Write-Host "Removing temporarly data"
Remove-Item -LiteralPath $tempfolder -Force -Recurse
Invoke-Item $zipfile
我尝试了此脚本的多种排列组合,但一直收到“无法创建代理连接”错误。这是“应该”起作用的那个:
#------------------------------------------------------
#Prerequisites
#Install-Module -Name ReportingServicesTools
#------------------------------------------------------
#Lets get security on all folders in a single instance
#------------------------------------------------------
#Declare SSRS URI
$sourceRsUri = "http://hqmnbi:80/ReportServer_SQL08/ReportService2010.asmx?wsdl"
#Declare Proxy so we dont need to connect with every command
$proxy = New-RsWebServiceProxy -ReportServerUri $sourceRsUri
#Output ALL Catalog items to file system
Out-RsFolderContent -Proxy $proxy -RsFolder / -Destination 'C:\Users\arobinson\source\Workspaces\EDW\MAIN\SSRS\HQMNBI' -Recurse
这是我遇到的错误:
无法建立与 http:///hqmnbi/ReportServer_SQL08/ReportService2010.asmx 的代理连接:HTML 文档不包含
Web 服务发现信息。
在 C:\Program Files\WindowsPowerShell\Modules\ReportingServicesTools[=36=].0.6.6\Functions\Utilities\New-RsWebServiceProxy.ps1:136 char:9
-
throw (New-Object System.Exception("Failed to establish proxy ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 类别信息:操作已停止:(:)[],异常
- FullyQualifiedErrorId:无法建立到 http:///hqmnbi/ReportServer_SQL08/ReportService2010.asmx 的代理连接:
HTML 文档不包含 Web 服务发现信息。
我已经尝试过使用 http:// 的 URI,如果没有,我尝试过包含端口号。等等。仍然无法使它真正起作用。我们还有另外两个 SSRS 实例,我能够 运行 这没有问题。
找到并使用它没有任何问题。无需安装,只需添加我的 url,然后粘贴到 Powershell。
https://microsoft-bitools.blogspot.com/2018/09/ssrs-snack-download-all-ssrs-reports.html
万一 link 中断,这里是 link 中的代码:
###################################################################################
# Download Reports and DataSources from a SSRS server and create the same folder
# structure in the local download folder.
###################################################################################
# Parameters
###################################################################################
$downloadFolder = "c:\temp\ssrs\"
$ssrsServer = "http://myssrs.westeurope.cloudapp.azure.com"
###################################################################################
# If you can't use integrated security
#$secpasswd = ConvertTo-SecureString "MyPassword!" -AsPlainText -Force
#$mycreds = New-Object System.Management.Automation.PSCredential ("MyUser", $secpasswd)
#$ssrsProxy = New-WebServiceProxy -Uri "$($ssrsServer)/ReportServer/ReportService2010.asmx?WSDL" -Credential $mycreds
# SSRS Webserver call
$ssrsProxy = New-WebServiceProxy -Uri "$($ssrsServer)/ReportServer/ReportService2010.asmx?WSDL" -UseDefaultCredential
# List everything on the Report Server, recursively, but filter to keep Reports and DataSources
$ssrsItems = $ssrsProxy.ListChildren("/", $true) | Where-Object {$_.TypeName -eq "DataSource" -or $_.TypeName -eq "Report"}
# Loop through reports and data sources
Foreach($ssrsItem in $ssrsItems)
{
# Determine extension for Reports and DataSources
if ($ssrsItem.TypeName -eq "Report")
{
$extension = ".rdl"
}
else
{
$extension = ".rds"
}
# Write path to screen for debug purposes
Write-Host "Downloading $($ssrsItem.Path)$($extension)";
# Create download folder if it doesn't exist (concatenate: "c:\temp\ssrs\" and "/SSRSFolder/")
$downloadFolderSub = $downloadFolder.Trim('\') + $ssrsItem.Path.Replace($ssrsItem.Name,"").Replace("/","\").Trim()
New-Item -ItemType Directory -Path $downloadFolderSub -Force > $null
# Get SSRS file bytes in a variable
$ssrsFile = New-Object System.Xml.XmlDocument
[byte[]] $ssrsDefinition = $null
$ssrsDefinition = $ssrsProxy.GetItemDefinition($ssrsItem.Path)
# Download the actual bytes
[System.IO.MemoryStream] $memoryStream = New-Object System.IO.MemoryStream(@(,$ssrsDefinition))
$ssrsFile.Load($memoryStream)
$fullDataSourceFileName = $downloadFolderSub + "\" + $ssrsItem.Name + $extension;
$ssrsFile.Save($fullDataSourceFileName);
}
来自这个问题:SQL Reporting Services - COPY reports to another folder
我发现这个工具可以下载和上传报告。此外,它还列出了文件夹和子文件夹。
我想获取一台服务器中所有 .rdl 文件的副本。 我可以一次手动下载一个报告,但这很耗时,尤其是这个服务器有大约 1500 个报告。
有什么方法或工具可以让我下载所有 .rdl 文件并复制一份吗?[=10=]
这是基于 SQL2016/SSRS2016 但我认为它应该适用于 2012。
SELECT 'http://mySQLServerName/reports/api/v1.0/catalogitems(' + cast(itemid as varchar(256))+ ')/Content/$value' AS url
FROM ReportServer.dbo.Catalog
这将为您提供一份 URL 的列表,每个报告一个。
如果以上方法在 SSRS 2012 中不起作用,请转至报告管理器,就像您要从那里下载文件一样。检查下载按钮上的 URL,您可能会看到一个 URL,其中嵌入了项目 ID。只需调整上面的代码以匹配 url 结构。
这之后你要做什么取决于你。 就我个人而言,我会使用 Chrome 商店 here 中名为 'Tab Save' 的 Chrome 扩展。您只需将上面创建的所有 URL 复制并粘贴到其中,然后点击下载按钮...
如果您只是出于备份目的或类似目的需要它,这可能会有用:Where does a published RDL file sit?
该线程的相关查询是:
select convert(varchar(max), convert(varbinary(max), content))
from catalog
where content is not null
最初的答案是使用 2005 年,我在 2016 年使用过,所以我想它应该适用于 2008 年和 2012 年。
当我不得不使用它时,我也将路径添加到查询中,这样我就知道哪个报告是哪个。
警告:在 SSMS v18 之前,网格结果限制为每个元组 64KB,结果文本限制为每个元组 8,192 个字符。如果您的报告定义大于这些限制,您将无法获得完整的定义。
在 SSMS v18 中,对于网格报告和文本结果,这些限制已增加到每个元组 2MB。
有一种完整且更简单的方法可以使用 PowerShell 执行此操作。
此代码将以与报表服务器完全相同的结构导出所有报表内容。查看 Github wiki 了解其他选项和命令
#------------------------------------------------------
#Prerequisites
#Install-Module -Name ReportingServicesTools
#------------------------------------------------------
#Lets get security on all folders in a single instance
#------------------------------------------------------
#Declare SSRS URI
$sourceRsUri = 'http://ReportServerURL/ReportServer/ReportService2010.asmx?wsdl'
#Declare Proxy so we dont need to connect with every command
$proxy = New-RsWebServiceProxy -ReportServerUri $sourceRsUri
#Output ALL Catalog items to file system
Out-RsFolderContent -Proxy $proxy -RsFolder / -Destination 'C:\SSRS_Out' -Recurse
我创建了这个 powershell 脚本来将它们复制到 ZIP 中。您必须提供 SQL 服务器数据库详细信息。
Add-Type -AssemblyName "System.IO.Compression.Filesystem"
$dataSource = "SQLSERVER"
$user = "sa"
$pass = "sqlpassword"
$database = "ReportServer"
$connectionString = "Server=$dataSource;uid=$user; pwd=$pass;Database=$database;Integrated Security=False;"
$tempfolder = "$env:TEMP\Reports"
$zipfile = $PSScriptRoot + '\reports.zip'
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()
$allreports = $connection.CreateCommand()
$allreports.CommandText = "SELECT ItemID, Path, CASE WHEN Type = 2 THEN '.rdl' ELSE '.rds' END AS Ext FROM Catalog WHERE Type IN(2,5)"
$result = $allreports.ExecuteReader()
$reportable = new-object "System.Data.DataTable"
$reportable.Load($result)
[int]$objects = $reportable.Rows.Count
foreach ($report in $reportable) {
$cmd = $connection.CreateCommand()
$cmd.CommandText = "SELECT CAST(CAST(Content AS VARBINARY(MAX)) AS XML) FROM Catalog WHERE ItemID = '" + $report[0] + "'"
$xmldata = [string]$cmd.ExecuteScalar()
$filename = $tempfolder + $report["Path"].Replace('/', '\') + $report["Ext"]
New-Item $filename -Force | Out-Null
Set-Content -Path ($filename) -Value $xmldata -Force
Write-Host "$($objects.ToString()).$($report["Path"])"
$objects -= 1
}
Write-Host "Compressing to zip file..."
if (Test-Path $zipfile) {
Remove-Item $zipfile
}
[IO.Compression.Zipfile]::CreateFromDirectory($tempfolder, $zipfile)
Write-Host "Removing temporarly data"
Remove-Item -LiteralPath $tempfolder -Force -Recurse
Invoke-Item $zipfile
我尝试了此脚本的多种排列组合,但一直收到“无法创建代理连接”错误。这是“应该”起作用的那个:
#------------------------------------------------------
#Prerequisites
#Install-Module -Name ReportingServicesTools
#------------------------------------------------------
#Lets get security on all folders in a single instance
#------------------------------------------------------
#Declare SSRS URI
$sourceRsUri = "http://hqmnbi:80/ReportServer_SQL08/ReportService2010.asmx?wsdl"
#Declare Proxy so we dont need to connect with every command
$proxy = New-RsWebServiceProxy -ReportServerUri $sourceRsUri
#Output ALL Catalog items to file system
Out-RsFolderContent -Proxy $proxy -RsFolder / -Destination 'C:\Users\arobinson\source\Workspaces\EDW\MAIN\SSRS\HQMNBI' -Recurse
这是我遇到的错误:
无法建立与 http:///hqmnbi/ReportServer_SQL08/ReportService2010.asmx 的代理连接:HTML 文档不包含 Web 服务发现信息。 在 C:\Program Files\WindowsPowerShell\Modules\ReportingServicesTools[=36=].0.6.6\Functions\Utilities\New-RsWebServiceProxy.ps1:136 char:9
-
throw (New-Object System.Exception("Failed to establish proxy ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 类别信息:操作已停止:(:)[],异常
- FullyQualifiedErrorId:无法建立到 http:///hqmnbi/ReportServer_SQL08/ReportService2010.asmx 的代理连接:
HTML 文档不包含 Web 服务发现信息。
我已经尝试过使用 http:// 的 URI,如果没有,我尝试过包含端口号。等等。仍然无法使它真正起作用。我们还有另外两个 SSRS 实例,我能够 运行 这没有问题。
找到并使用它没有任何问题。无需安装,只需添加我的 url,然后粘贴到 Powershell。
https://microsoft-bitools.blogspot.com/2018/09/ssrs-snack-download-all-ssrs-reports.html
万一 link 中断,这里是 link 中的代码:
###################################################################################
# Download Reports and DataSources from a SSRS server and create the same folder
# structure in the local download folder.
###################################################################################
# Parameters
###################################################################################
$downloadFolder = "c:\temp\ssrs\"
$ssrsServer = "http://myssrs.westeurope.cloudapp.azure.com"
###################################################################################
# If you can't use integrated security
#$secpasswd = ConvertTo-SecureString "MyPassword!" -AsPlainText -Force
#$mycreds = New-Object System.Management.Automation.PSCredential ("MyUser", $secpasswd)
#$ssrsProxy = New-WebServiceProxy -Uri "$($ssrsServer)/ReportServer/ReportService2010.asmx?WSDL" -Credential $mycreds
# SSRS Webserver call
$ssrsProxy = New-WebServiceProxy -Uri "$($ssrsServer)/ReportServer/ReportService2010.asmx?WSDL" -UseDefaultCredential
# List everything on the Report Server, recursively, but filter to keep Reports and DataSources
$ssrsItems = $ssrsProxy.ListChildren("/", $true) | Where-Object {$_.TypeName -eq "DataSource" -or $_.TypeName -eq "Report"}
# Loop through reports and data sources
Foreach($ssrsItem in $ssrsItems)
{
# Determine extension for Reports and DataSources
if ($ssrsItem.TypeName -eq "Report")
{
$extension = ".rdl"
}
else
{
$extension = ".rds"
}
# Write path to screen for debug purposes
Write-Host "Downloading $($ssrsItem.Path)$($extension)";
# Create download folder if it doesn't exist (concatenate: "c:\temp\ssrs\" and "/SSRSFolder/")
$downloadFolderSub = $downloadFolder.Trim('\') + $ssrsItem.Path.Replace($ssrsItem.Name,"").Replace("/","\").Trim()
New-Item -ItemType Directory -Path $downloadFolderSub -Force > $null
# Get SSRS file bytes in a variable
$ssrsFile = New-Object System.Xml.XmlDocument
[byte[]] $ssrsDefinition = $null
$ssrsDefinition = $ssrsProxy.GetItemDefinition($ssrsItem.Path)
# Download the actual bytes
[System.IO.MemoryStream] $memoryStream = New-Object System.IO.MemoryStream(@(,$ssrsDefinition))
$ssrsFile.Load($memoryStream)
$fullDataSourceFileName = $downloadFolderSub + "\" + $ssrsItem.Name + $extension;
$ssrsFile.Save($fullDataSourceFileName);
}
来自这个问题:SQL Reporting Services - COPY reports to another folder
我发现这个工具可以下载和上传报告。此外,它还列出了文件夹和子文件夹。