执行数据库维护
定期执行数据库维护,包括在 Automation Suite 中备份、完整性检查和旧数据清理。
保持数据库整洁有序,这一点很重要。 为此,我们建议执行以下操作:
使用 SQL Server 维护解决方案
SQL Server 维护解决方案是一组脚本,让您可以从 2005 版本开始在所有版本的 Microsoft SQL Server 上运行备份、完整性检查以及索引和统计信息维护。请参阅此 GitHub 项目以获取更多信息。有关详细信息,请参阅SQL Server 维护解决方案 GitHub 项目。
备份数据库
我们建议对 SQL Server 数据库实施定期备份,例如每周完整备份或每日增量备份。
此外,我们建议使用通过SQL Server 备份中描述的脚本创建的 DatabaseBackup 存储程序。
定期删除旧数据
共享的 Suite 功能
在删除项目之前,创建一个单独的数据库来保存项目。此数据库充当因某些原因(例如审核)可能需要存储的项目的存档。
-
创建一个新的调用数据库,例如
UiPathArchives:create database UiPathArchivescreate database UiPathArchives -
创建以下备份表:
ArchiveAuditEvent,其结构与AuditEvent表相同:SELECT * INTO [UiPathArchives].[dbo].[ArchiveAuditEvent] from [AutomationSuite_Platform].[adt].[AuditEvent] where 1 = 2SELECT * INTO [UiPathArchives].[dbo].[ArchiveAuditEvent] from [AutomationSuite_Platform].[adt].[AuditEvent] where 1 = 2 -
将数据存档。
要将审核事件记录存档,请使用以下示例脚本:
DECLARE @NumberOfDaysToKeep INT DECLARE @CurrentDate DATETIME -- Specify the number of days SET @NumberOfDaysToKeep = 60 -- Archive the list of audit event records that you want to delete SET @CurrentDate = GetDate() BEGIN TRANSACTION INSERT INTO [UiPathArchives].[dbo].[ArchiveAuditEvent] SELECT [Id],[CreatedOn],[Version],[OrganizationId],[Source],[Category],[Action],[IsUserEvent], [UserId],[FullName],[Email],[DetailsVersion],[Details],[OperationId] FROM [adt].[AuditEvent] WHERE DateDiff(day, CreatedOn, @CurrentDate) > @NumberOfDaysToKeep -- Delete the audit events DELETE FROM [adt].[AuditEvent] WHERE EXISTS (SELECT 1 FROM [UiPathArchives].[dbo].[ArchiveAuditEvent] WHERE Id = [adt].[AuditEvent].[Id]) COMMIT TRANSACTIONDECLARE @NumberOfDaysToKeep INT DECLARE @CurrentDate DATETIME -- Specify the number of days SET @NumberOfDaysToKeep = 60 -- Archive the list of audit event records that you want to delete SET @CurrentDate = GetDate() BEGIN TRANSACTION INSERT INTO [UiPathArchives].[dbo].[ArchiveAuditEvent] SELECT [Id],[CreatedOn],[Version],[OrganizationId],[Source],[Category],[Action],[IsUserEvent], [UserId],[FullName],[Email],[DetailsVersion],[Details],[OperationId] FROM [adt].[AuditEvent] WHERE DateDiff(day, CreatedOn, @CurrentDate) > @NumberOfDaysToKeep -- Delete the audit events DELETE FROM [adt].[AuditEvent] WHERE EXISTS (SELECT 1 FROM [UiPathArchives].[dbo].[ArchiveAuditEvent] WHERE Id = [adt].[AuditEvent].[Id]) COMMIT TRANSACTION使用以下查询时,在删除旧数据之前,会将旧数据先复制到这些档案中。
-
删除表格中的数据。
重要提示:在运行以下脚本之前,请确保使其适应您的环境。
审核事件:
declare @NumberOfDaysToKeep int declare @CurrentDate datetime -- Specify the number of days SET @NumberOfDaysToKeep = 60 -- Create temporary table with the list of audit event records that you want to delete SET @CurrentDate = GetDate() SELECT [Id],[CreatedOn],[Version],[OrganizationId],[Source],[Category],[Action],[IsUserEvent], [UserId],[FullName],[Email],[DetailsVersion],[Details],[OperationId] INTO #TempAuditRecordsToDelete FROM [adt].[AuditEvent] WHERE DateDiff(day, CreatedOn, @CurrentDate) > @NumberOfDaysToKeep -- Review the audit event records to be deleted SELECT * FROM #TempAuditRecordsToDelete -- Delete the audit events BEGIN TRANSACTION DELETE FROM [adt].[AuditEvent] WHERE EXISTS (SELECT 1 FROM #TempAuditRecordsToDelete WHERE Id = [adt].[AuditEvent].[Id]) DROP TABLE #TempAuditRecordsToDelete COMMIT TRANSACTIONdeclare @NumberOfDaysToKeep int declare @CurrentDate datetime -- Specify the number of days SET @NumberOfDaysToKeep = 60 -- Create temporary table with the list of audit event records that you want to delete SET @CurrentDate = GetDate() SELECT [Id],[CreatedOn],[Version],[OrganizationId],[Source],[Category],[Action],[IsUserEvent], [UserId],[FullName],[Email],[DetailsVersion],[Details],[OperationId] INTO #TempAuditRecordsToDelete FROM [adt].[AuditEvent] WHERE DateDiff(day, CreatedOn, @CurrentDate) > @NumberOfDaysToKeep -- Review the audit event records to be deleted SELECT * FROM #TempAuditRecordsToDelete -- Delete the audit events BEGIN TRANSACTION DELETE FROM [adt].[AuditEvent] WHERE EXISTS (SELECT 1 FROM #TempAuditRecordsToDelete WHERE Id = [adt].[AuditEvent].[Id]) DROP TABLE #TempAuditRecordsToDelete COMMIT TRANSACTION
身份服务器
在删除项目之前,创建一个单独的数据库来保存项目。此数据库充当因某些原因(例如审核)可能需要存储的项目的存档。
仅在使用 SQL Server 内部部署 SQL 时才支持本节中提供的数据库维护脚本。它不适用于 Azure SQL。如果您的 Automation Suite 部署使用 Azure SQL,请不要运行此脚本。
-
创建一个新的调用数据库,例如
UiPathIdentityArchives:create database UiPathIdentityArchivescreate database UiPathIdentityArchives -
创建以下备份表:
ArchiveLoginAttempts,其结构与UserLoginAttempts表相同:select * into [UiPathIdentityArchives].[dbo].[ArchiveUserLoginAttempts] from [AutomationSuite_Platform].[identity].[UserLoginAttempts] where 1=2select * into [UiPathIdentityArchives].[dbo].[ArchiveUserLoginAttempts] from [AutomationSuite_Platform].[identity].[UserLoginAttempts] where 1=2使用以下查询时,在删除旧数据之前,会将旧数据先复制到这些档案中。
-
删除表格中的数据。
重要提示:在运行以下脚本之前,请确保使其适应您的环境。
例如,要删除超过 60 天的登录尝试,请使用以下查询。它可以手动执行,也可以在 SQL Server 作业中计划。
declare @NumberOfDaysToKeep int set @NumberOfDaysToKeep = 60 if OBJECT_ID('[UiPathIdentityArchives].[dbo].[UserLoginAttemps]') = NULL begin select * into [UiPathIdentityArchives].[dbo].[UserLoginAttemps] from [identity].UserLoginAttempts where 1=2 end begin transaction set identity_insert [UiPathIdentityArchives].[dbo].[UserLoginAttemps] on insert into [UiPathIdentityArchives].[dbo].[UserLoginAttemps] ([Id],[PartitionId],[UserId],[UserNameOrEmailAddress],[ClientIpAddress],[ClientName],[BrowserInfo],[Result],[CreationTime],[AuthenticationProvider],[PartitionName]) select [Id],[PartitionId],[UserId],[UserNameOrEmailAddress],[ClientIpAddress],[ClientName],[BrowserInfo],[Result],[CreationTime],[AuthenticationProvider],[PartitionName] from [identity].UserLoginAttempts where DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep delete from [identity].UserLoginAttempts where DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep commit transactiondeclare @NumberOfDaysToKeep int set @NumberOfDaysToKeep = 60 if OBJECT_ID('[UiPathIdentityArchives].[dbo].[UserLoginAttemps]') = NULL begin select * into [UiPathIdentityArchives].[dbo].[UserLoginAttemps] from [identity].UserLoginAttempts where 1=2 end begin transaction set identity_insert [UiPathIdentityArchives].[dbo].[UserLoginAttemps] on insert into [UiPathIdentityArchives].[dbo].[UserLoginAttemps] ([Id],[PartitionId],[UserId],[UserNameOrEmailAddress],[ClientIpAddress],[ClientName],[BrowserInfo],[Result],[CreationTime],[AuthenticationProvider],[PartitionName]) select [Id],[PartitionId],[UserId],[UserNameOrEmailAddress],[ClientIpAddress],[ClientName],[BrowserInfo],[Result],[CreationTime],[AuthenticationProvider],[PartitionName] from [identity].UserLoginAttempts where DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep delete from [identity].UserLoginAttempts where DateDiff(day, CreationTime, GetDate()) > @NumberOfDaysToKeep commit transaction
Orchestrator
有关如何定期删除 Orchestrator 数据库中旧数据的详细信息,请参阅清理 Orchestrator 数据库。
Automation Hub
Automation Hub 依赖其运行时视图和仪表板的历史数据,并且由于其性质,它没有清理旧数据的概念。 与其他服务类似,建议通过每周完整备份或每日增量备份等方法定期备份 Automation Hub 数据库。
Process Mining
Automation Suite 上的 Process Mining 提供内置的自动数据库清理功能,可确保实现最佳效率和性能。这可确保定期删除不必要的数据,从而保持数据库清理并正常运行,而无需执行任何手动操作来释放资源。