Merge pull request #1264 from getalex/patch-2

Major update: ssrs_migration.rss
This commit is contained in:
Umachandar Jayachandran
2024-03-26 07:04:58 -07:00
committed by GitHub
@@ -18,16 +18,17 @@
' 3) Run the following command (in one line):
' rs.exe -i ssrs_migration.rss -e Mgmt2010
'
' -s SOURCE_URL 'URL of the source RS server.
' -u domain\username -p password 'Credentials for source server. OPTIONAL, default credentials are used if missing.
' -v st="SITE" 'Specifies SharePoint site, in case source server is in SharePoint integrated mode
' -v f="SOURCEFOLDER" 'Set to "/" for migrating everything, or to something like "/folder/subfolder" for partial migration. Everything within this folder will be copied. OPTIONAL, default is "/".
' -s SOURCE_URL 'URL of the source RS server.
' -u domain\username -p password 'Credentials for source server. OPTIONAL, default credentials are used if missing.
' -v st="SITE" 'Specifies SharePoint site, in case source server is in SharePoint integrated mode
' -v f="SOURCEFOLDER" 'Set to "/" for migrating everything, or to something like "/folder/subfolder" for partial migration. Everything within this folder will be copied. OPTIONAL, default is "/".
'
' -v ts="TARGET_URL" 'URL of the target RS server"
' -v tu="domain\username" -v tp="password" 'Credentials for target server. OPTIONAL, default credentials are used if missing.
' -v tst="SITE" 'Specifies SharePoint site, in case target server is in SharePoint integrated mode
' -v tf="TARGETFOLDER" 'Set to "/" for migrating into the root level, or to something like "/folder/subfolder" for copying into some folder, which must be already existing. Everything within "SOURCEFOLDER" will be copied into "TARGETFOLDER". OPTIONAL, default is "/".
' -v security= "True/False" 'If set to "False", destination catalog items will inherit security setting according to the settings of the target system. Default is false.
' -v ts="TARGET_URL" 'URL of the target RS server"
' -v tu="domain\username" -v tp="password" 'Credentials for target server. OPTIONAL, default credentials are used if missing.
' -v tst="SITE" 'Specifies SharePoint site, in case target server is in SharePoint integrated mode
' -v tf="TARGETFOLDER" 'Set to "/" for migrating into the root level, or to something like "/folder/subfolder" for copying into some folder, which must be already existing. Everything within "SOURCEFOLDER" will be copied into "TARGETFOLDER". OPTIONAL, default is "/".
' -v security= "True/False" 'If set to "False", destination catalog items will inherit security setting according to the settings of the target system. Default is false.
' -v logprefix="PREFIX" 'Prefix name to the output log file.
'
' Example: rs.exe -i ssrs_migration.rss -e Mgmt2010 -s http://server1/reportserver -v ts="http://server2/_vti_bin/reportserver"
' Example: rs.exe -i ssrs_migration.rss -e Mgmt2010 -s http://server1/reportserver -u domain1\user1 -p password1 -v f="/SOURCEFOLDER" -v ts="http://server2/_vti_bin/reportserver" -v tu="domain1\user2" -v tp="password2" -v tf="/TARGETFOLDER"
@@ -49,7 +50,6 @@
' Open http://servername/_vti_bin/reportserver in a browser to see the non-virtual folder structure.
' This is helpful for setting SrcFolder and SnkFolder to something other than "/" for a server in SharePoint integrated mode.
Private RsSrc As ReportingService2010
Private SrcProtocol As String = "http"
Private SrcServer As String
@@ -75,6 +75,7 @@ Private policies As Policy() = Nothing
Private srcSiteUrl As String = Nothing
Private snkSiteUrl As String = Nothing
Private logFilePath As String = "MigrationLog.txt"
''''''''''''''''''''''''''''''''''''''''''''''
Sub Main()
@@ -151,6 +152,11 @@ Sub Main()
If Not Me.GetType().GetField("security") Is Nothing Then
MigrateSecurity = (Me.GetType().GetField("security").GetValue(Me).ToLower = "true")
End If
' Update the migration log path to prefix if speficied
If Not Me.GetType().GetField("logprefix") Is Nothing Then
logFilePath = Me.GetType().GetField("logprefix").GetValue(Me) + "_" + logFilePath
End If
SnkFolder = SnkSite + SnkFolder
@@ -225,13 +231,35 @@ Sub Main()
' Create destination folder if not present
Try
RsSnk.CreateFolder(SnkFolder.Substring(1), "/", Nothing)
Catch ex As Exception
If (ex.Message.Contains("Microsoft.ReportingServices.Diagnostics.Utilities.ItemAlreadyExistsException"))
Console.WriteLine("Folder already exists.")
Else
Console.WriteLine(ex.Message + Environment.NewLine)
End If
If SnkFolder.Contains("/") And Not SnkFolder = "/" Then
Dim targetFolders As String() = SnkFolder.Substring(1).Split("/"c)
Dim parentFolder As String = "/"
For Each folderName As String In targetFolders
Try
RsSnk.CreateFolder(folderName, parentFolder, Nothing)
Catch er As Exception
If (er.Message.Contains("Microsoft.ReportingServices.Diagnostics.Utilities.ItemAlreadyExistsException"))
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Folder already exists.")
Console.ResetColor()
Else
Throw ' Unknown Exception
End If
End Try
If parentFolder <> "/" Then
parentFolder = parentFolder + "/" + folderName
Else
parentFolder = "/" + folderName
End If
Next
End If
Catch ex As Exception
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
End Try
Try
@@ -311,11 +339,11 @@ Sub Main()
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("GENERAL", "Exception", ex.Message)
End Try
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''' Migrate global settings'''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
@@ -338,6 +366,7 @@ Sub MigrateSchedules()
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(e.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("SCHEDULES", s.Name, e.Message)
End Try
Next
@@ -345,6 +374,7 @@ Sub MigrateSchedules()
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("SCHEDULES", "Exception", ex.Message)
End Try
End Sub
@@ -357,7 +387,6 @@ Sub MigrateRoles()
Console.WriteLine("Migrating roles.")
Try
For Each r As Role In roles
Try
Console.Write("Migrating role: " + r.Name)
@@ -376,6 +405,7 @@ Sub MigrateRoles()
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(e.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("ROLES", r.Name, e.Message)
End Try
Next
@@ -383,6 +413,7 @@ Sub MigrateRoles()
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("ROLES", "Exception", ex.Message)
End Try
End Sub
@@ -402,6 +433,7 @@ Sub MigrateSystemPolicies()
Console.WriteLine("... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("POLICIES", "Exception", ex.Message)
End Try
End Sub
@@ -423,6 +455,7 @@ Function MigrateFolder(srcItem As CatalogItem) As CatalogItem
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("FOLDER", srcItem.Path, ex.Message)
End Try
Return result
End Function
@@ -441,8 +474,12 @@ Function MigrateDataSource(srcItem As CatalogItem) As CatalogItem
If definition.CredentialRetrieval = CredentialRetrievalEnum.Store Then
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("You need to re-enter the password for user '" + definition.UserName + "' in data source '" + result.Path + "'")
Dim warningMsg as String = "You need to re-enter the password for user '" + definition.UserName + "' in data source '" + result.Path + "'"
Console.WriteLine(warningMsg)
Console.ResetColor()
LogErrorToFile("CATALOGITEM", "Warning", warningMsg)
End If
Catch ex As Exception
@@ -450,6 +487,7 @@ Function MigrateDataSource(srcItem As CatalogItem) As CatalogItem
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("DATASOURCE", srcItem.Path, ex.Message)
End Try
Return result
End Function
@@ -489,6 +527,7 @@ Function MigrateLinkedReport(srcItem As CatalogItem) As CatalogItem
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("LINKEDREPORT", srcItem.Path, ex.Message)
End Try
Return result
End Function
@@ -524,8 +563,11 @@ Function MigrateCatalogItem(srcItem As CatalogItem) As CatalogItem
Dim dsd As DataSourceDefinition = d.Item
If dsd.CredentialRetrieval = CredentialRetrievalEnum.Store Then
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("You need to re-enter the password for user '" + dsd.UserName + "' in data source '" + d.Name + "' contained in " + result.TypeName + " '" + result.Path + "'")
Dim warningMsg as String = "You need to re-enter the password for user '" + dsd.UserName + "' in data source '" + d.Name + "' contained in " + result.TypeName + " '" + result.Path + "'"
Console.WriteLine(warningMsg)
Console.ResetColor()
LogErrorToFile("CATALOGITEM", "Warning", warningMsg)
End If
End If
Next
@@ -548,13 +590,12 @@ Function MigrateCatalogItem(srcItem As CatalogItem) As CatalogItem
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(Environment.NewLine + ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("CATALOGITEM", srcItem.Path, ex.Message)
End Try
Return result
End Function
'Re-link DataSources of a Report or a Model
Sub RelinkDataSources(snkReport As CatalogItem, srcReport As CatalogItem)
Console.Write("Re-linking data source for item " + snkReport.Name)
@@ -593,6 +634,7 @@ Sub RelinkDataSources(snkReport As CatalogItem, srcReport As CatalogItem)
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("RELINKDATASOURCE", snkReport.Name, ex.Message)
End Try
End Sub
@@ -628,12 +670,12 @@ Sub RelinkItemReferences(snkItem As CatalogItem, srcItem As CatalogItem)
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("RELINKREFERENCES", snkItem.Name, ex.Message)
End Try
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''' Migrate report artefacts ''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
@@ -710,8 +752,12 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
Dim dsd As DataSourceDefinition = dataRetrievalPlan.Item
If dsd.CredentialRetrieval = CredentialRetrievalEnum.Store Then
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("You need to re-enter the password for user '" + dsd.UserName + "' in data-driven subscription '" + description + "' contained in report '" + snkReport.Path + "'")
Console.ResetColor()
Dim warningMsg as String = "You need to re-enter the password for user '" + dsd.UserName + "' in data-driven subscription '" + description + "' contained in report '" + snkReport.Path + "'"
Console.WriteLine(warningMsg)
Console.ResetColor()
LogErrorToFile("SUBSCRIPTIONS", "Warning", warningMsg)
End If
End If
@@ -745,8 +791,12 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
End If
Next
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("You need to re-enter the password for user '" + username + "' in file share subscription '" + description + "' contained in report '" + snkReport.Path + "'.")
Console.ResetColor()
Dim warningMsg as String = "You need to re-enter the password for user '" + username + "' in file share subscription '" + description + "' contained in report '" + snkReport.Path + "'."
Console.WriteLine(warningMsg)
Console.ResetColor()
LogErrorToFile("SUBSCRIPTIONS", "Warning", warningMsg)
End If
Next
@@ -755,6 +805,7 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("SUBSCRIPTIONS", snkReport.Name, ex.Message)
End Try
End Sub
@@ -788,6 +839,7 @@ Sub MigrateCacheRefreshPlans(snkReport As CatalogItem, srcReport As CatalogItem)
Console.WriteLine(" ... FAILURE")
Console.WriteLine(e.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("CACHEREFRESH", snkReport.Name, e.Message)
End Try
Next
@@ -795,6 +847,7 @@ Sub MigrateCacheRefreshPlans(snkReport As CatalogItem, srcReport As CatalogItem)
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("CACHEREFRESH", "Exception", ex.Message)
End Try
End Sub
@@ -817,6 +870,7 @@ Sub MigrateReportParameters(snkReport As CatalogItem, srcReport As CatalogItem)
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("REPORTPARAMETERS", snkReport.Name, ex.Message)
End Try
End Sub
@@ -840,6 +894,7 @@ Sub MigrateReportExecutionOptions(snkReport As CatalogItem, srcReport As Catalog
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("EXECUTIONOPTIONS", snkReport.Name, ex.Message)
End Try
End Sub
@@ -863,6 +918,7 @@ Sub MigrateReportCacheOptions(snkReport As CatalogItem, srcReport As CatalogItem
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("CACHEOPTIONS", snkReport.Name, ex.Message)
End Try
End Sub
@@ -892,6 +948,7 @@ Sub MigrateReportHistorySettings(snkReport As CatalogItem, srcReport As CatalogI
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("HISTORYSETTINGS", snkReport.Name, ex.Message)
End Try
End Sub
@@ -922,12 +979,11 @@ Sub MigrateItemPolicies(snkReport As CatalogItem, srcReport As CatalogItem)
Console.WriteLine(" ... FAILURE:")
Console.WriteLine(ex.Message + Environment.NewLine)
Console.ResetColor()
LogErrorToFile("ITEMPOLICIES", snkReport.Name, ex.Message)
End Try
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''' Helper Functions '''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
@@ -1128,3 +1184,25 @@ Function SortParentFoldersFirst(first As CatalogItem, second As CatalogItem) As
Return String.Compare(first.Path, second.Path)
End If
End Function
Sub LogErrorToFile(source As String, errItem as String, message As String)
Dim writer as StreamWriter
Try
' Create a StreamWriter object
writer = New StreamWriter(logFilePath, True)
' Format log message with timestamp
Dim timeStamp As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
Dim formattedMessage as String = String.Format("{0}, {1}, {2}, ""{3}""", timeStamp, source, errItem, message.Replace(Environment.NewLine, ""))
' Write the log entry to file
writer.WriteLine(formattedMessage)
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
If Not writer Is Nothing Then
writer.Close()
End If
End Try
End Sub