转移订阅报告服务

时间:2010-08-17 00:40:39

标签: sql sql-server-2008

您是否会建议将订阅从一个报告服务转移(或复制)到另一个服务器中的另一个报告服务的最佳和最简单的方法?

3 个答案:

答案 0 :(得分:5)

在@ S.Juarez的答案的基础上,这个脚本修复了他的错误,该错误打破了参数(从而阻止订阅工作),并且还跨相关的计划和计划用户记录进行传输。它在源和目标上保持相同的GUID。

使用此脚本的起点是在您已经传输报告之后(例如使用工具ReportSync),并且您已在目标服务器上的所有报告文件夹上手动配置了安全性。对于源服务器上存在UserName但不存在于目标服务器上的情况,您还需要确定目标服务器上的哪些用户记录与订阅关联。 (这可能发生在您决定不在目标上重新创建用户的情况下,或者由于该人不再是域中的有效帐户(即他们已离开您的组织)而无法重新创建用户的情况。

在开始之前,我建议针对源和目标ReportServer数据库运行这个小脚本并保存结果。此外,整个数据库的完整备份。这些步骤使您能够回滚小的和大的更改。

SELECT u.UserName, c.Path, Parameters, s.ExtensionSettings, s.Report_OID, SubscriptionID, u.UserID
FROM dbo.[Subscriptions] s
JOIN users u 
on s.OwnerID = u.UserID
JOIN catalog c
on c.ItemID = s.Report_OID

下一个脚本的第一部分将传输订阅,然后是计划,然后是报告,订阅和计划之间的链接记录。您需要输入目标和源服务器的名称,默认用户的名称(必须已存在于目标Users表中),然后在源服务器上执行此操作。

DECLARE @Default_User varchar(50) 
SELECT @Default_User = UserID FROM [SourceServer].ReportServer.dbo.Users WHERE UserName = '[DOMAIN\YourDefaultUserNameGoesHere]'

INSERT INTO [TargetServer].ReportServer.dbo.Subscriptions(
    SubscriptionID, OwnerID, Report_OID,  Locale, InactiveFlags, ExtensionSettings, ModifiedByID, ModifiedDate, 
    [Description], LastStatus, EventType, MatchData, LastRunTime, [Parameters], DataSettings, DeliveryExtension, Version
    )
SELECT 
    --cSource.Path,
    --uSource.UserName,
    SubscriptionID,
    --u.UserName,
    --LastStatus,
    COALESCE(uTarget.UserID, @Default_User) AS OwnerID,
    cTarget.ItemID,
    Locale, InactiveFlags, ExtensionSettings,
    @Default_User AS ModifiedByID,
     GETDATE(),
    sSource.[Description], LastStatus, EventType, MatchData, LastRunTime, [Parameters], DataSettings, DeliveryExtension, Version

FROM [SourceServer].ReportServer.dbo.Subscriptions sSource
    LEFT JOIN [SourceServer].ReportServer.dbo.Catalog cSource ON cSource.ItemId = sSource.Report_OID
    LEFT JOIN [SourceServer].ReportServer.dbo.Users uSource ON sSource.OwnerID = uSource.UserID
    LEFT JOIN [TargetServer].ReportServer.dbo.Catalog cTarget ON cTarget.Path = cSource.Path
    LEFT JOIN [TargetServer].ReportServer.dbo.Users uTarget ON uTarget.UserName = uSource.UserName
WHERE sSource.SubscriptionID NOT IN 
(
SELECT SubscriptionID FROM [TargetServer].ReportServer.dbo.Subscriptions
)


INSERT INTO [TargetServer].ReportServer.dbo.Schedule
(
ScheduleID, Name, StartDate, Flags, NextRunTime, LastRunTime, EndDate, RecurrenceType, MinutesInterval, DaysInterval, WeeksInterval, DaysOfWeek, DaysOfMonth, [Month], MonthlyWeek, State, LastRunStatus, ScheduledRunTimeout, EventType, EventData, Type, ConsistancyCheck, Path, CreatedById
)
SELECT
ScheduleID, Name, StartDate, Flags, NextRunTime, LastRunTime, EndDate, RecurrenceType, MinutesInterval, DaysInterval, WeeksInterval, DaysOfWeek, DaysOfMonth, [Month], MonthlyWeek, State, LastRunStatus, ScheduledRunTimeout, EventType, EventData, Type, ConsistancyCheck, Path, 
COALESCE(uTarget.UserID, @Default_User) AS CreatedById
FROM [SourceServer].ReportServer.dbo.Schedule s
INNER JOIN [SourceServer].ReportServer.dbo.Users uSource
ON s.CreatedById = uSource.UserID
LEFT JOIN [TargetServer].ReportServer.dbo.Users uTarget
ON uSource.UserName = uTarget.UserName
WHERE ScheduleID NOT IN (SELECT ScheduleID FROM [TargetServer].ReportServer.dbo.Schedule)


INSERT INTO [TargetServer].ReportServer.dbo.ReportSchedule
(
ScheduleID, ReportID, SubscriptionID, ReportAction
)
SELECT
    rsSource.ScheduleID, cTarget.ItemID, rsSource.SubscriptionID, rsSource.ReportAction
FROM [SourceServer].ReportServer.dbo.ReportSchedule rsSource
INNER JOIN [TargetServer].ReportServer.dbo.Schedule sTarget
ON rsSource.ScheduleID = sTarget.ScheduleID
INNER JOIN [SourceServer].ReportServer.dbo.Catalog cSource
On cSource.ItemID = rsSource.ReportID
INNER JOIN [TargetServer].ReportServer.dbo.Catalog cTarget
ON cSource.Path = cTarget.Path
LEFT JOIN [TargetServer].ReportServer.dbo.ReportSchedule rsTarget
ON  rsSource.ScheduleID = rsTarget.ScheduleID
AND rsSource.ReportID = rsTarget.ReportID
AND rsSource.SubscriptionID = rsTarget.SubscriptionID
WHERE rsTarget.ReportID IS NULL

要测试您的迁移是否正常运行,您可以针对目标服务器执行这样的语句。 GUID应该是Subscriptions表中的SubscriptionID,理想情况下是用于传递到收件箱的内容。

exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='cb38a708-7735-4b5a-8ff3-e03ee1b18edb'

如果有效,那么您应该在约20秒内收到一封电子邮件。如果失败,我发现查找故障排除信息的最佳位置是SSRS日志文件described here

答案 1 :(得分:2)

有多少订阅?

如果数量最少则最简单的方法是在另一台服务器上手动重新创建它们。

如果我们谈论相当数量,那么有一个数据库报告服务来存储我认为称为dbo.Subscriptions的订阅数据。我建议首先查看是否可以看到订阅。

否则,如果您要转移整个报告服务器数据库(包括计划),则可能会使用以下链接:

MSDN Moving the Report Server Databases to Another Computer

答案 2 :(得分:2)

以下是我们用于将订阅从2008 SSRS复制到2012 SSRS服务器的内容。您需要提前正确设置数据源。

INSERT INTO Mercury.ReportServer.dbo.Subscriptions(SubscriptionID, OwnerID, Report_OID,  Locale, InactiveFlags, ExtensionSettings, ModifiedByID, ModifiedDate, Description, LastStatus, EventType, MatchData, LastRunTime, Parameters, DataSettings, DeliveryExtension, Version)
SELECT 
    --Path,
    SubscriptionID
    ,(SELECT UserID FROM <Destination Linked Server>.ReportServer.dbo.Users WHERE UserName = '<User from DB>')  OwnerID
    ,(select ItemId from <Destination Linked Server>.ReportServer.dbo.Catalog mCatalog where mCatalog.Path = Catalog.Path )Report_OID
    ,Locale, InactiveFlags, ExtensionSettings
    ,(SELECT UserID FROM <Destination Linked Server>.ReportServer.dbo.Users WHERE UserName = 'User from DB') ModifiedByID
    , GETDATE()
    ,Sub.Description, LastStatus, EventType, MatchData, LastRunTime, Parameter, DataSettings, DeliveryExtension, Version

FROM ReportServer..Subscriptions Sub
    LEFT JOIN ReportServer.dbo.Catalog ON Catalog.ItemId = Sub.Report_OID
WHERE Path NOT IN 
  (
    SELECT Path
    FROM <Destination Linked Server>.ReportServer.dbo.Subscriptions
      LEFT JOIN <Destination Linked Server>.ReportServer.dbo.Catalog ON Catalog.ItemId = Subscriptions.Report_OID
  )
--AND
--  PATH LIKE '...'