In this post let us see how we can automate the back up of SSRS reports using RS Utility. If you want to know about the RS utility and where you can find it in your system please refer to one of my blog click here.
Let us get into the real world scenario, generally we all do deployment we provide the document and code to the operations team and they will perform the deployment on behalf of us. Since the operations team does not work on only one project at a time they have very limited time to perform their activities. They tend to get bored when you want to back up huge number of reports and deploy the latest reports. Since in SSRS it takes few steps to backup the reports
1. Connect to the report manager
2. Click on the report which you want to backup
3. Click on Properties
4. Click on Download to back up the report
If we have few reports then it is not a time consuming process. Think if we have some 25 reports or 30 reports we will be wasting a lot of time in this process. So we decided to help them by automating the back up of reports using the rs utility.
I will take you through a small utility which is used to backup the reports. It has two files
1) Reporting Service Script File (.rss)
2) Batch File (.bat)
RSS File – This is a file which contains the actual script to take the backup of the reports.
Batch File – This batch file is used to call the rs utilti using some of the parameters.
The code block specified below is the script file
Public Sub Main() Try rs.Credentials = System.Net.CredentialCache.DefaultCredentials Dim Items as CatalogItem() Dim Item as CatalogItem Dim ReportName As String Items = rs.ListChildren(ItemPath, false) Console.Writeline() Console.Writeline("Backing up of reports started....") For Each Item in Items ReportName = ItemPath + "/" + Item.Name Dim reportDefinition As Byte() = Nothing Dim rdlReport As New System.Xml.XmlDocument reportDefinition = rs.GetReportDefinition(ReportName) Dim Stream As New MemoryStream(reportDefinition) rdlReport.Load(Stream) rdlReport.Save(BackupFolder + "\" + Item.Name +".rdl") Console.Writeline("Report " + Item.Name +".rdl Backed up Successfully") Next Console.Writeline("Backing up of reports completed....") Console.Writeline() catch e As Exception Console.Writeline(e.Message) End Try End Sub
Let us see what the script file does. It takes all the items under the path we provide, loop though each of the items, get the report definition from the server, Load the stream data and save it has a rdl file under the backup location passed using the command file.
Now let us see the batch file which is used to call the rs utility with the required details. The code block specifies the command file
set ItemPath=/Order Details set ReportServerURL=http://localhost/Reportserver set BackupFolder=D:\Project\Back_Up_Reports\BackUp rs -i "D:\Project\Back_Up_Reports\Backup_Report.rss" -s %ReportServerURL% -v ItemPath="%ItemPath%" -v BackupFolder="%BackupFolder%"
The ItemPath specifies the location where the reports are present in the report server. The above batch file specifies that it is placed under /Order Details from home page. See the screenshot below.
The ReportServerURL specifies the URL of the report server where the report is deployed. eg., Http://localhost/reportserver it says the report server installed in the local system.
BackupFolder is the folder location where the final downloaded report will be saved. In this example it will be saved under D:\Project\Back_Up_Reports\BackUp See the screen shot below.
The last statement rs is used to call the utility by specifying the location where the rss script file is saved(D:\Project\Back_Up_Reports) and the other information required by the script file.
Now let us see how to execute the script using the command file. Open command Prompt using the account which has the access to the report server. Navigate to the location where you have placed the batch file. Type the command file name and press Enter. see the screen shot below.
The final result will be as follows and the report will be copied to the location specified above in the backupLocation. Refer to the screen shot below.
Refer to the below screenshot for the file that is backed up.
Using the above mentioned script file, one can download any number of report files in the same folder. If the files are located in multiple folder then each time update the ItemPath and run the batch file to backup from different folders.
The code is placed in the following location http://sdrv.ms/LfQf77