从报告数据库中提取 SSRS RDL 文件

Extract SSRS RDL files from Reporting database

我有一个 SSRS 报告数据备份,我已经在我的本地机器上恢复了。

我使用了一个从目录 table 返回 RDL 原始 XML 的查询,但我发现服务器有超过 10 个报告,我什至无法在其中查看生产数据库。

我的问题是我在哪里可以找到 RDL 文件,而报告服务器显示 72 RDL 而报告数据库中的目录 table 仅显示 10.

您可以运行使用以下脚本备份所有部署的报告。

  • 使用以下命令行远程访问报表服务器

%systemroot%/system32/mstsc.exe

  • 然后将以下过程保存为 .rss 文件,并 运行 将参数 parentFolder="" 作为零字符串保存,以保存包含所有报告的整个文件夹结构。

命令行:

rs -s http://localhost/reportserver -i D:\Scripts\Backup_Reports.rss -e Mgmt2010 -v backupFolder="D:\Scripts\BackupReports" -v parentFolder=""

报告备份程序:

Public Sub Main()
    '--------------------------------------------------------------------------------------------------------------------
    ' Purpose:   Script to backup reports from a folder on ReportServer
    '            Save file as .rss extension and run using rs.exe from command line.
    ' Reference: http://bhushan.extreme-advice.com/back-up-of-ssrs-reports-using-rs-utility/
    '            https://docs.microsoft.com/en-us/sql/reporting-services/tools/rs-exe-utility-ssrs?view=sql-server-2017
    ' Example:   rs -s http://localhost/reportserver -i D:\Scripts\Backup_Reports.rss -e Mgmt2010 -v backupFolder="D:\Scripts\BackupReports" -v parentFolder="/IndividualReportFolderNameHere"
    '            rs -s http://localhost/reportserver -i D:\Scripts\Backup_Reports.rss -e Mgmt2010 -v backupFolder="D:\Scripts\BackupReports" -v parentFolder=""
    '--------------------------------------------------------------------------------------------------------------------
    Try
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials
        Dim items As CatalogItem() = Nothing

        If String.IsNullOrEmpty(parentFolder) Then
            items = rs.ListChildren("/", True)
        Else
            items = rs.ListChildren(parentFolder, False)
        End If

        Console.WriteLine()
        Console.WriteLine("...Backup Started...")

        For Each item As CatalogItem In items
            If item.TypeName = "Report" Then
                Console.WriteLine(item.Path)
                Dim reportPath As String = item.Path
                parentFolder = Path.GetDirectoryName(item.Path) ' comment out this line to save the reports in one folder
                Dim reportDefinition As Byte() = rs.GetItemDefinition(item.Path)
                Dim rdlReport As New System.Xml.XmlDocument
                Dim Stream As New MemoryStream(reportDefinition)
                Dim backupPath As String = Path.Combine(backupFolder, Date.Now().ToString("yyyy.MM.dd") + "\" + parentFolder)

                If (Not System.IO.Directory.Exists(backupPath)) Then
                    System.IO.Directory.CreateDirectory(backupPath)
                End If

                rdlReport.Load(Stream)
                rdlReport.Save(Path.Combine(backupPath, item.Name + ".rdl"))

                Console.WriteLine(item.Name + ".rdl")
            End If
        Next

        Console.WriteLine("...Backup Completed...")
        Console.WriteLine()

    Catch e As Exception
        Console.WriteLine(e.Message)

    End Try

End Sub