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

时间:2018-11-16 19:01:04

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

我有一个SSRS报告数据备份,已在本地计算机上还原。

我使用了一个查询,该查询从目录表返回了RDL原始XML,但是我发现服务器有10多个报告,甚至我都无法在生产数据库中查看。

我的问题是,我在哪里找到RDL文件,而Reporting Server显示72 RDL,而报告数据库中的目录表仅显示10。

1 个答案:

答案 0 :(得分:2)

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

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

%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