10-16-2023 08:52 PM - edited 10-17-2023 08:09 PM
Hello
I am looking to create a SQL query to list the top folders archived on a particular archive or vault store, if possible.
For example: In the last 1 year, list the top 5 folders that contributed writing to archival storage.
I was able to list the archives, but not able to find a way to list the folders.
Thanks in advance for your insights.
Solved! Go to Solution.
10-17-2023 06:22 PM - edited 10-17-2023 06:32 PM
The script can be an easy one based on Plaudone1's (run it against your FSA VS DB and assume the EVD db is also on the same SQL instance):
SELECT TOP 5
FolderPath,
SUM(ItemSize)/1024 AS 'Archived Size (MB)'
FROM
EnterpriseVaultDirectory.dbo.root r1
JOIN EnterpriseVaultDirectory.dbo.Root r2 on r1.RootIdentity = r2.ContainerRootIdentity
JOIN EnterpriseVaultDirectory.dbo.ArchiveFolder on r2.RootIdentity = ArchiveFolder.RootIdentity
JOIN Vault on r2.VaultEntryId = Vault.Vaultid
JOIN Saveset ss on Vault.VaultIdentity = ss.VaultIdentity
JOIN SavesetProperty sp on ss.savesetidentity = sp.SavesetIdentity
WHERE ss.ArchivedDate BETWEEN '2020-08-03 23:03:00.000' AND '2022-08-03 23:03:00.000'
GROUP BY
FolderPath
ORDER BY
'Archived Size (MB)' desc
Just update the date range as you wish, or as you asked, a year for the current time.
SELECT TOP 5
FolderPath,
SUM(ItemSize)/1024 AS 'Archived Size (MB)'
FROM
EnterpriseVaultDirectory.dbo.root r1
JOIN EnterpriseVaultDirectory.dbo.Root r2 on r1.RootIdentity = r2.ContainerRootIdentity
JOIN EnterpriseVaultDirectory.dbo.ArchiveFolder on r2.RootIdentity = ArchiveFolder.RootIdentity
JOIN Vault on r2.VaultEntryId = Vault.Vaultid
JOIN Saveset ss on Vault.VaultIdentity = ss.VaultIdentity
JOIN SavesetProperty sp on ss.savesetidentity = sp.SavesetIdentity
WHERE ss.ArchivedDate <DATEADD(YEAR, -1, GETUTCDATE())
GROUP BY
FolderPath
ORDER BY
'Archived Size (MB)' desc
10-17-2023 08:07 AM - edited 10-17-2023 08:08 AM
I had this in my bag of tricks and do not have a lab to run it against. I think it brings a count per folder. I thought perhaps it could help your hunt.
----This is to find items per folderpath
Use EnterpriseVaultStore ----------------replace with your file server vaultstore
declare @folderpath Varchar(300)
set @folderpath = '\\cs2.dodo1.local\users7\Userdata' ----- --replace your foldername there
select folderpath, PartitionRootPath
+ '\' + convert(char(4),datepart(year, IdDatetime))
+ '\' + case when datepart(month, IdDatetime) < 10 then '0' + convert(char(1),datepart(month, IdDatetime)) else convert(char(2),datepart(month, IdDatetime)) end
+ '\' + case when datepart(day, IdDatetime) < 10 then '0' + convert(char(1),datepart(day, IdDatetime)) else convert(char(2),datepart(day, IdDatetime)) end
+ '\' + case when datepart(hour, IdDatetime) < 10 then '0' + convert(char(1),datepart(hour, IdDatetime)) else convert(char(2),datepart(hour, IdDatetime)) end
+ '\' + LEFT(CAST(idchecksumhigh as varchar(7))+'0000000', 7)
+ left (CAST(idchecksumlow as varchar(8)) + '00000000', 8)
+ '~'
+ REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(varchar(200),iddatetime,121),'.',''),':',''),'-',''),' ','') + '0~'
+ CAST (iduniqueno as varchar (1))
+ '.dvs'
as dvs_path, idtransaction from saveset
join vault on saveset.vaultidentity = vault.vaultidentity
join enterprisevaultdirectory..root on vault.vaultid = enterprisevaultdirectory..root.vaultentryid
join enterprisevaultdirectory..archivefolder on enterprisevaultdirectory..root.rootidentity = enterprisevaultdirectory..archivefolder.rootidentity
join EnterpriseVaultDirectory..VaultEntryView VaultEntryView on Vault.VaultId = VaultEntryView.VaultEntryId
join EnterpriseVaultDirectory..PartitionEntry PartitionENtry on Saveset.IdPartition = PartitionEntry.IdPartition and PartitionEntry.VaultStoreEntryId = VaultEntryView.VaultStoreEntryId
where folderpath like @folderpath
Perhaps it can send you in the right direction?
10-17-2023 11:22 AM
Thank you, @Prone2Typos.
Tested the query and it shows the folder and the vault store partition location where the items are stored.
I am looking to create a query that lists the top 5 folders that contributed writing to archival storage during the last 1 month for an entire file server/vault store.
10-17-2023 01:52 PM
Hi Virgil,
This may work for you. You can add the Archive Name or Id in one of the SET lines to perform against just that archive. Otherwise it will run against the entire vault store. You will then need to take the results to Excel and perform some sorting and filtering and such. This will only pull items with an archived date greater than GETUTCDATE() -30.
USE VAULT_STORE_DB_NAME -- REPLACE WITH CORRECT VS DB NAME
10-17-2023 02:10 PM
Thank you, Plaudone1!
The query is closer to what I need indeed, it lists all folders and the files inside the folders.
It would be great if instead of listing all files, it would show the count of files per folder or even better the size of files in each folder.
Could you help with this?
10-17-2023 06:22 PM - edited 10-17-2023 06:32 PM
The script can be an easy one based on Plaudone1's (run it against your FSA VS DB and assume the EVD db is also on the same SQL instance):
SELECT TOP 5
FolderPath,
SUM(ItemSize)/1024 AS 'Archived Size (MB)'
FROM
EnterpriseVaultDirectory.dbo.root r1
JOIN EnterpriseVaultDirectory.dbo.Root r2 on r1.RootIdentity = r2.ContainerRootIdentity
JOIN EnterpriseVaultDirectory.dbo.ArchiveFolder on r2.RootIdentity = ArchiveFolder.RootIdentity
JOIN Vault on r2.VaultEntryId = Vault.Vaultid
JOIN Saveset ss on Vault.VaultIdentity = ss.VaultIdentity
JOIN SavesetProperty sp on ss.savesetidentity = sp.SavesetIdentity
WHERE ss.ArchivedDate BETWEEN '2020-08-03 23:03:00.000' AND '2022-08-03 23:03:00.000'
GROUP BY
FolderPath
ORDER BY
'Archived Size (MB)' desc
Just update the date range as you wish, or as you asked, a year for the current time.
SELECT TOP 5
FolderPath,
SUM(ItemSize)/1024 AS 'Archived Size (MB)'
FROM
EnterpriseVaultDirectory.dbo.root r1
JOIN EnterpriseVaultDirectory.dbo.Root r2 on r1.RootIdentity = r2.ContainerRootIdentity
JOIN EnterpriseVaultDirectory.dbo.ArchiveFolder on r2.RootIdentity = ArchiveFolder.RootIdentity
JOIN Vault on r2.VaultEntryId = Vault.Vaultid
JOIN Saveset ss on Vault.VaultIdentity = ss.VaultIdentity
JOIN SavesetProperty sp on ss.savesetidentity = sp.SavesetIdentity
WHERE ss.ArchivedDate <DATEADD(YEAR, -1, GETUTCDATE())
GROUP BY
FolderPath
ORDER BY
'Archived Size (MB)' desc
10-17-2023 08:16 PM - edited 10-18-2023 09:50 AM
Thank you Jack!