下载所有SSRS报告

时间:2017-10-17 05:34:38

标签: sql-server reporting-services ssrs-2008 ssrs-2012

我想在一台服务器上获取所有.rdl文件的副本。 我当时可以手动下载一个报告,但这很费时间,特别是该服务器有大约1500个报告。

是否有任何方法或工具允许我下载所有.rdl文件并获取它们的副本?

4 个答案:

答案 0 :(得分:25)

有一个完整的&使用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

答案 1 :(得分:1)

这是基于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。只需调整上面的代码即可匹配该网址结构。

在你做完之后,你做了什么。 我个人会使用Chrome商店here中提供的名为“标签保存”的Chrome扩展程序。您只需将上面创建的所有URL复制并粘贴到其中,然后点击下载按钮......

答案 2 :(得分:1)

如果你只是需要这个用于备份或类似的东西,这可能很有用: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年。

当我不得不使用它时,我也在路径中添加了查询,以便我知道哪个报告是哪个。

答案 3 :(得分:0)

我创建了这个powershell脚本,将其复制到ZIP中。您必须提供SQL Server数据库详细信息。

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