VMware {code} Community
LinuxMonkey
Contributor
Contributor
Jump to solution

How do I get the size of files in a datastore?

I've been using the dsbrowse.pl file as a starting point to collect information about the data stores for various planned reports.

A new requirement is to provide the size of each file found in a datastore folder.

Does anyone have any guides, pointers, or code they can share?

Thank you.

Reply
0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

All this information is available using the vSphere API, specifically: *SearchDatastoreSubFolders_Task() which allows for all types of complex queries including specific type of files, patterns, etc.

Take a look at this script:

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

View solution in original post

Reply
0 Kudos
5 Replies
VMStreak
Enthusiast
Enthusiast
Jump to solution

You can run a plain "du -h " on ESX.

PS: Please award points if any of the above information is useful.

PS: Please award points if any of the above information is useful.
Reply
0 Kudos
LinuxMonkey
Contributor
Contributor
Jump to solution

I don't think that will work for me. I should have been clearer in my description. I have the size of the data store and it's capacity used already.

What I'd like to collect in addition to that is the size of eachof the files within a folder on the datastore.

NOTE: I am running the toolkit on a dedicated (virtualized) server and connecting to the virtual center server using the Util::Connect mechanism and It is preferred if this task be done using the perl tookit and/or API.

For example, in my output I have the following for a single datastore:

Data Store: DataStoreNumberOne

Type: VMFS

Size: 599.75 GB

Free: 92.7 GB

Folder Path: DataStoreNumberOne -> VMNumberOne/

Files Present:

VMNumberOne-flat.vmdk

VMNumberOne.vmdk

VMNumberOne-ctk.vmdk

vmware-6.log

vmware-7.log

svmware-8.log

What I'm looking for is a process to retrieve the size for each of the files located under "Files Present" using perl and the vmware vitookit/API.

Thank you.

Message was edited by: LinuxMonkey to correct formatting issue.

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

All this information is available using the vSphere API, specifically: *SearchDatastoreSubFolders_Task() which allows for all types of complex queries including specific type of files, patterns, etc.

Take a look at this script:

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
LinuxMonkey
Contributor
Contributor
Jump to solution

This appears to be exactly the type of example I was looking for.

Thank you for the insight, it is appreciated.

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

np. Don't forget to award 'correct' or 'helpful' points Smiley Wink

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".