Conjunto de dados de eventos do DPM

Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.DPMEventDataset (DataWarehouseDataSet)

Conjunto de dados de eventos do DPM.

Element properties:

AccessibilityPublic

Source Code:

<DataWarehouseDataSet ID="Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.DPMEventDataset" Accessibility="Public">
<Dependencies>
<DataWarehouseScript>SCDW!Microsoft.SystemCenter.DataWarehouse.Script.DatasetDebuggingSupport</DataWarehouseScript>
<DataWarehouseScript>SCDW!Microsoft.SystemCenter.DataWarehouse.Script.StandardDatasetSupport</DataWarehouseScript>
</Dependencies>
<Configuration/>
<Install>
---------------------------------------------------------------------
-- DPMBackup - Initial Storage
---------------------------------------------------------------------

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE [name] = 'DPMBackup')
BEGIN
EXECUTE('CREATE SCHEMA DPMBackup')
END
GO

-- change schema ownership to allow index rebuild and reorganize
ALTER AUTHORIZATION ON SCHEMA::DPMBackup TO OpsMgrWriter
GO

-- change schema alter to allow domain table index rebuild
GRANT ALTER ON SCHEMA::dbo TO OpsMgrWriter
GO

-- grant create table permissions
GRANT CREATE TABLE TO OpsMgrWriter
GO

-----------------------------------------------------------------------------------------
-- Staging table definition
-----------------------------------------------------------------------------------------

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'tbl_DPM_BackupEvents_Stage' AND TABLE_SCHEMA = 'DPMBackup')
BEGIN
CREATE TABLE DPMBackup.tbl_DPM_BackupEvents_Stage
(
DatasetId uniqueidentifier NOT NULL
,ManagementGroupGuid uniqueidentifier NOT NULL
,DatasourceId uniqueidentifier NOT NULL
,ReferentialDatasourceId uniqueidentifier NULL
,TaskId uniqueidentifier NOT NULL
,BackupTime datetime NOT NULL
,BackupResult nvarchar(30) NOT NULL
,BackupType nvarchar(30) NOT NULL
,FailureErrorCode int NULL
,ManagedEntityRowId int NULL
,InsertReadyInd AS (ISNULL(ManagedEntityRowId, 0))
,DWCreatedDateTime datetime NOT NULL DEFAULT(GETUTCDATE())
)

END
GO

GRANT SELECT, INSERT, UPDATE, DELETE ON DPMBackup.tbl_DPM_BackupEvents_Stage TO OpsMgrWriter
GO


--------------------------------------------------------------------------------------------------
-- DPMBackup - StandardDataset
--------------------------------------------------------------------------------------------------

SET NOCOUNT ON

EXEC StandardDatasetDelete @DatasetId = '$Config/DatasetId$'
GO

INSERT StandardDataset (
DatasetId
,SchemaName
,DefaultAggregationIntervalCount
,RawInsertTableCount
,StagingProcessorStoredProcedureName
,BlockingMaintenanceDailyStartTime
)
VALUES
(
'$Config/DatasetId$'
,'DPMBackup'
,0 -- DefaultAggregationIntervalCount
,1 -- RawInsertTableCount
,'DPMBackupEventProcessStaging'
,'00:00' -- BlockingMaintenanceDailyStartTime
)


------------------------------------------------------------------------
-- DPMBackup - StandardDatasetAggregation
------------------------------------------------------------------------

SET NOCOUNT ON

INSERT INTO StandardDatasetAggregation
(
DatasetId
,AggregationTypeId
,AggregationIntervalDurationMinutes
,AggregationStartDelayMinutes
,BuildAggregationStoredProcedureName
,DeleteAggregationStoredProcedureName
,GroomStoredProcedureName
,IndexOptimizationIntervalMinutes
,MaxDataAgeDays
,GroomingIntervalMinutes
,MaxRowsToGroom
,LastGroomingDateTime
,DataFileGroupName
,IndexFileGroupName
)
VALUES
(
'$Config/DatasetId$'
,0 -- Aggregation Type Raw
,NULL -- AggregationIntervalDurationMinutes
,0
,NULL -- Aggregation Type Raw
,NULL -- Aggregation Type Raw
,'DPMBackupGroom'
,240
,400 -- Max data age in days
,240 -- GroomingIntervalMinutes
,300000 -- MaxRowsToGroom
,GETUTCDATE()
,NULL -- DefaultDataFileGroupName
,NULL -- DefaultIndexFileGroupName
)

GO

------------------------------------------------------------------------
-- DPMBackup - StandardDatasetAggregationStorage
------------------------------------------------------------------------

SET NOCOUNT ON

INSERT INTO StandardDatasetAggregationStorage
(
DatasetId
,AggregationTypeId
,BaseTableName
,DependentTableInd
,TableTemplate
,CoverViewSelectClause
,MaxTableRowCount
,MaxTableSizeKb
)
VALUES
(
'$Config/DatasetId$'
,0
,'tbl_DPM_BackupEvents'
,0
,'
CREATE TABLE ' + QUOTENAME('DPMBackup') + '.' + QUOTENAME('tbl_DPM_BackupEvents' + '_$Guid$') + '('+
'ManagedEntityRowId int NOT NULL
,TaskId uniqueidentifier NOT NULL
,ReferentialDatasourceId uniqueidentifier NULL
,BackupTime datetime NOT NULL
,BackupResult nvarchar(30) NOT NULL
,BackupType nvarchar(30) NOT NULL
,FailureErrorCode int NULL
,DateTime AS BackupTime
,DWCreatedDateTime datetime NOT NULL DEFAULT(GETUTCDATE())

,CONSTRAINT' + QUOTENAME( 'PK_tbl_DPM_BackupEvents' + '_$Guid$') + ' PRIMARY KEY CLUSTERED ('
+ 'ManagedEntityRowId' + ',TaskId) ON $DataFileGroupName$
) ON $DataFileGroupName$
'
,' SELECT
ManagedEntityRowId
,TaskId
,ReferentialDatasourceId
,BackupTime
,BackupResult
,BackupType
,FailureErrorCode
'
,10000000
,NULL
)


GO


-------------------------------------------------------------------------------------------
-- DPMBackup - StandardDatasetAggregationStorageIndex
-------------------------------------------------------------------------------------------

SET NOCOUNT ON
GO

-- create [DateTime] field indexes for all aggregation levels
DECLARE
@AggregationTypeId int
,@Statement nvarchar(max)
,@IndeGuid uniqueidentifier

SET @AggregationTypeId = -1

WHILE EXISTS (SELECT *
FROM StandardDatasetAggregation
WHERE (DatasetId = '$Config/DatasetId$')
AND (AggregationTypeId &gt; @AggregationTypeId)
)
BEGIN
SELECT @IndeGuid = NEWID()

SELECT TOP 1
@AggregationTypeId = AggregationTypeId
,@Statement = ' EXEC StandardDatasetIndexDelete'
+ ' @DatasetId = ''$Config/DatasetId$'''
+ ' ,@IndexGuid = ''' + CAST(@IndeGuid AS varchar(100)) + ''''
+ ' ,@DeleteIndexOnExistingTablesInd = 0'
+ ' EXEC StandardDatasetIndexInsert'
+ ' @DatasetId = ''$Config/DatasetId$'''
+ ' ,@AggregationTypeId = ' + CAST(AggregationTypeId AS varchar(10))
+ ' ,@DependentTableInd = 0'
+ ' ,@TableTag = NULL'
+ ' ,@UniqueInd = 0'
+ ' ,@IndexGuid = ''' + CAST(@IndeGuid AS varchar(100)) + ''''
+ ' ,@IndexDefinition = ''(BackupTime)'''
+ ' ,@CreateIndexOnExistingTablesInd = 0'
FROM StandardDatasetAggregation
WHERE (DatasetId = '$Config/DatasetId$')
AND (AggregationTypeId &gt; @AggregationTypeId)
ORDER BY AggregationTypeId

EXECUTE (@Statement)
END
GO

EXEC StandardDatasetAllocateStorage @DatasetId = '$Config/DatasetId$', @AggregationTypeId=0
GO

-----------------------------------------------------------------------------------------------------
-- DPMBackup - DPMBackupEventProcessStaging
-----------------------------------------------------------------------------------------------------

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'DPMBackupEventProcessStaging')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.DPMBackupEventProcessStaging AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.DPMBackupEventProcessStaging
@DatasetId uniqueidentifier
AS
BEGIN

SET NOCOUNT ON
DECLARE
@ErrorInd bit
,@ErrorMessage nvarchar(max)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)
,@ErrorMessageText nvarchar(max)

SET @ErrorInd = 0

BEGIN TRY

DECLARE
@DebugLevel int
,@SchemaName sysname
,@ExecResult int
,@LockResourceName sysname
,@InsertTableName sysname
,@InsertTableGuid uniqueidentifier
,@InsertStartedDateTime datetime
,@Statement nvarchar(max)
,@MessageText varchar(max)
,@OperationDurationMs bigint

SELECT
@DebugLevel = DebugLevel
,@SchemaName = SchemaName
FROM StandardDataset
WHERE DatasetId = @DatasetId

-- groom records that are &gt; month old from staging.
DELETE DPMBackup.tbl_DPM_BackupEvents_Stage WITH (TABLOCK)
WHERE (DWCreatedDateTime &lt; DATEADD(month, -1, GETUTCDATE()))


-- process events in staging setting ME id if it is not yet determined

UPDATE DPMBackupStage
SET DPMBackupStage.ManagedEntityRowId = me.ManagedEntityRowId
FROM DPMBackup.tbl_DPM_BackupEvents_Stage DPMBackupStage
JOIN vManagementGroup mg ON (DPMBackupStage.ManagementGroupGuid = mg.ManagementGroupGuid)
JOIN vManagedEntity me ON ((me.Name = CAST(DPMBackupStage.DatasourceId AS nvarchar(70))) AND (mg.ManagementGroupRowId = me.ManagementGroupRowId))
WHERE (DPMBackupStage.DatasetId = @DatasetId)
AND (DPMBackupStage.InsertReadyInd = 0)

BEGIN TRAN

-- lock table map to ensure we insert into table opened for insertion
SET @LockResourceName = CAST(@DatasetId AS varchar(50)) + '_TableMap'

EXEC @ExecResult = sp_getapplock
@Resource = @LockResourceName
,@LockMode = 'Shared'
,@LockOwner = 'Transaction'

IF (@ExecResult &lt; 0)
BEGIN
RAISERROR(777971001, 16, 1, 'Shared:StandardDatasetTableMap', @ExecResult)
END

EXEC dbo.StandardDatasetGetInsertTableGuid @DatasetId, 0, @InsertTableGuid OUTPUT

SELECT @InsertTableName = BaseTableName + '_' + REPLACE(CAST(@InsertTableGuid AS varchar(50)), '-', '')
FROM StandardDatasetAggregationStorage
WHERE (DatasetId = @DatasetId)
AND (AggregationTypeId = 0)
AND (DependentTableInd = 0)

SELECT @Statement =
' INSERT ' + QUOTENAME(@SchemaName) + '.' + QUOTENAME(@InsertTableName) + ' ('
+ ' ManagedEntityRowId'
+ ' ,TaskId'
+ ' ,ReferentialDatasourceId'
+ ' ,BackupTime'
+ ' ,BackupResult'
+ ' ,BackupType'
+ ' ,FailureErrorCode'
+ ' )'
+ ' SELECT '
+ ' DPMStage.ManagedEntityRowId'
+ ' ,DPMStage.TaskId'
+ ' ,DPMStage.ReferentialDatasourceId'
+ ' ,DPMStage.BackupTime'
+ ' ,DPMStage.BackupResult'
+ ' ,DPMStage.BackupType'
+ ' ,DPMStage.FailureErrorCode'
+ ' FROM DPMBackup.tbl_DPM_BackupEvents_Stage DPMStage'
+ ' WHERE (DatasetId = ''' + CAST(@DatasetId AS varchar(50)) + ''')'
+ ' AND (InsertReadyInd &gt; 0)'
+ ' AND NOT EXISTS (SELECT * FROM '
+ QUOTENAME(@SchemaName) + '.' + QUOTENAME(@InsertTableName)
+ ' WHERE ManagedEntityRowId = DPMStage.ManagedEntityRowId'
+ ' AND TaskId = DPMStage.TaskId)'

IF (@DebugLevel &gt; 3)
BEGIN
SELECT @MessageText = 'Starting to insert state raw change event(s) into ' + @InsertTableName

SET @InsertStartedDateTime = GETUTCDATE()

EXEC DebugMessageInsert
@DatasetId = @DatasetId
,@MessageLevel = 4
,@MessageText = @MessageText
END

EXECUTE(@Statement)

-- remove rows from staging
DELETE DPMBackup.tbl_DPM_BackupEvents_Stage WITH (TABLOCK)
WHERE (DatasetId = @DatasetId)
AND (InsertReadyInd &gt; 0)

IF (@DebugLevel &gt; 3)
BEGIN
SET @MessageText = 'Finished inserting DPM backup events into ' + @InsertTableName
SET @OperationDurationMs = ABS(DATEDIFF(ms, GETUTCDATE(), @InsertStartedDateTime))

EXEC DebugMessageInsert
@DatasetId = @DatasetId
,@MessageLevel = 4
,@MessageText = @MessageText
,@OperationDurationMs = @OperationDurationMs
END

COMMIT

END TRY
BEGIN CATCH
IF (@@TRANCOUNT &gt; 0)
ROLLBACK TRAN

SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

-- report error if any
IF (@ErrorInd = 1)
BEGIN
IF (@DebugLevel &gt; 0)
BEGIN
DECLARE @DebugMessageText nvarchar(max)

SET @DebugMessageText = N'Failed to process data in the state data set staging area. Error ' + CAST(@ErrorNumber AS varchar(15))
+ ', Procedure ' + @ErrorProcedure
+ ', Line ' + CAST(@ErrorLine AS varchar(15))
+ ', Message: '+ @ErrorMessageText

EXEC DebugMessageInsert
@DatasetId = @DatasetId
,@MessageLevel = 1
,@MessageText = @DebugMessageText
END

DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, 1
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END
END
GO


--------------------------------------------------------------------------------------------------------------
-- DPMBackup - DPMBackupEventGrooming
--------------------------------------------------------------------------------------------------------------

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'DPMBackupGroom')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.DPMBackupGroom AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.DPMBackupGroom
@DatasetId uniqueidentifier
,@AggregationTypeId tinyint
,@TableGuid uniqueidentifier
,@CutoffDateTime datetime
,@MaxRowsToGroom int
,@RowsDeleted int OUTPUT
AS
BEGIN
SET NOCOUNT ON

DECLARE
@ErrorInd bit
,@ErrorMessage nvarchar(4000)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)
,@ErrorMessageText nvarchar(4000)

SET @ErrorInd = 0

DECLARE
@TableName sysname
,@Statement nvarchar(max)
,@DebugLevel tinyint
,@SchemaName sysname

BEGIN TRY
SELECT
@DebugLevel = DebugLevel
,@SchemaName = SchemaName
FROM StandardDataset
WHERE DatasetId = @DatasetId

-- there are no dependent tables in state data set
SELECT @TableName = BaseTableName + '_' + REPLACE(CAST(@TableGuid AS varchar(50)), '-', '')
FROM StandardDatasetAggregationStorage
WHERE (DatasetId = @DatasetId)
AND (AggregationTypeId = @AggregationTypeId)
AND (DependentTableInd = 0)

SET @Statement = 'DELETE TOP (' + CAST(@MaxRowsToGroom AS varchar(15)) + ')'
+ ' FROM ' + QUOTENAME(@SchemaName) + '.' + QUOTENAME(@TableName)
+ ' WHERE (DWCreatedDateTime &lt; CONVERT(datetime, ''' + CONVERT(varchar(50), @CutoffDateTime, 120) + ''', 120))'

EXECUTE (@Statement)
SET @RowsDeleted = @@ROWCOUNT

-- groom staging of data for rejected MGs
DELETE DPMBackup.tbl_DPM_BackupEvents_Stage
WHERE ManagementGroupGuid NOT IN (SELECT ManagementGroupGuid
FROM ManagementGroup mg
WHERE (ConnectConfirmedDateTime IS NOT NULL)
AND (ConnectRejectedInd = 0)
)
END TRY
BEGIN CATCH
IF (@@TRANCOUNT &gt; 0)
ROLLBACK TRAN

SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

-- report error if any
IF (@ErrorInd = 1)
BEGIN
IF (@DebugLevel &gt; 0)
BEGIN
DECLARE @DebugMessageText nvarchar(max)

SET @DebugMessageText = N'Failed to groom data for state data set. Error ' + CAST(@ErrorNumber AS varchar(15))
+ ', Procedure ' + @ErrorProcedure
+ ', Line ' + CAST(@ErrorLine AS varchar(15))
+ ', Message: '+ @ErrorMessageText

EXEC DebugMessageInsert
@DatasetId = @DatasetId
,@MessageLevel = 1
,@MessageText = @DebugMessageText
END

DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, 1
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END

RETURN @RowsDeleted
END
GO


</Install>
<Uninstall/>
<UpgradeUnsupported>true</UpgradeUnsupported>
</DataWarehouseDataSet>