SQL query to search for expired savesets?
OK last SQL Query i promise, this one does the following
- Makes sure the user is enabled for expiry (enterpriseVaultDirectory.dbo.DeleteExpiredItems = 1)
- Discounts items in the SavesetHold table (if they're on hold, they would not be deleted)
- Links to the Archive table and not the ExchangeMailboxEntry table (so that it encompasses archives without users, shared archives etc)
SELECT A.ArchiveName, COUNT(DISTINCT(S.IdTransaction)) AS ItemsToExpire, RCE.RetentionCategoryNameFROM EnterpriseVaultDirectory.dbo.Archive A,
EnterpriseVaultDirectory.dbo.Root R,
EnterpriseVaultDirectory.dbo.RetentionCategoryEntry RCE,
EVVaultStore.dbo.Saveset S,
EVVaultStore.dbo.ArchivePoint AP,
EVVaultstore.dbo.HoldSaveset HSWHERE S.ArchivePointIdentity = AP.ArchivePointIdentity
AND AP.ArchivePointId = R.VaultEntryId
AND R.RootIdentity = A.RootIdentity
AND S.RetentionCategoryIdentity = RCE.RetentionCategoryIdentity
AND S.SavesetIdentity != HS.SavesetIdentity
AND S.ArchivePointIdentity != HS.ArchivePointIdentity
AND S.IdDateTime < DateAdd(year, -1, GetDate())
AND RCE.RetentionCategoryName = 'Business'
AND A.DeleteExpiredItems = 1GROUP BY A.ArchiveName, RCE.RetentionCategoryName
ORDER BY A.ArchiveName