1+ Public Sub Main()
2+ '--------------------------------------------------------------------------------------------------------------------
3+ ' Purpose: Script to backup reports from a folder on ReportServer
4+ ' Save file as .rss extension and run using rs.exe from command line.
5+ ' Reference: http://bhushan.extreme-advice.com/back-up-of-ssrs-reports-using-rs-utility/
6+ ' https://docs.microsoft.com/en-us/sql/reporting-services/tools/rs-exe-utility-ssrs?view=sql-server-2017
7+ ' Example: rs -s http://localhost/reportserver -i D:\Scripts\Backup_Reports.rss -e Mgmt2010 -v backupFolder="D:\Scripts\BackupReports" -v parentFolder="/Salesforce"
8+ ' rs -s http://localhost/reportserver -i D:\Scripts\Backup_Reports.rss -e Mgmt2010 -v backupFolder="D:\Scripts\BackupReports" -v parentFolder=""
9+ '--------------------------------------------------------------------------------------------------------------------
10+ Try
11+ rs.Credentials = System.Net.CredentialCache.DefaultCredentials
12+ Dim items As CatalogItem() = Nothing
13+
14+ If String .IsNullOrEmpty(parentFolder) Then
15+ items = rs.ListChildren( "/" , True )
16+ Else
17+ items = rs.ListChildren(parentFolder, False )
18+ End If
19+
20+ Console.WriteLine()
21+ Console.WriteLine( "...Reports Back Up Started..." )
22+
23+ For Each item As CatalogItem In items
24+ If item.TypeName = "Report"
25+ Console.WriteLine(item.Path)
26+ Dim reportPath As String = item.Path
27+ parentFolder = Path.GetDirectoryName(item.Path) ' comment out this line to save the reports in one folder
28+ Dim reportDefinition As Byte () = rs.GetItemDefinition(item.Path)
29+ Dim rdlReport As New System.Xml.XmlDocument
30+ Dim Stream As New MemoryStream(reportDefinition)
31+ Dim backupPath As String = Path.Combine(backupFolder, Date .Now().ToString( "yyyy.MM.dd" ) + "\" + parentFolder)
32+
33+ If ( Not System.IO.Directory.Exists(backupPath)) Then
34+ System.IO.Directory.CreateDirectory(backupPath)
35+ End If
36+
37+ rdlReport.Load(Stream)
38+ rdlReport.Save(Path.Combine(backupPath, item.Name + ".rdl" ))
39+
40+ Console.WriteLine(item.Name + ".rdl" )
41+ End If
42+ Next
43+
44+ Console.WriteLine( "...Reports Back Up Completed..." )
45+ Console.WriteLine()
46+
47+ Catch e As Exception
48+ Console.WriteLine(e.Message)
49+
50+ End Try
51+
52+ End Sub
0 commit comments