It’s a good idea to periodically run the UNMAP command on all your thin-provisioned LUNs. This allows the storage system to reclaim deleted blocks. (What is SCSI UNMAP?)
The format of the command is:
1 |
esxcli storage vmfs unmap -l <volume_label> |
I wanted to make a script to run this on all attached datastores so here’s what I came up with:
1 2 3 4 5 |
#!/bin/sh for datastore in `esxcli storage filesystem list | grep "VMDATA" | awk -F " " '{print $2}'`; do echo "Performing UNMAP on $datastore ..." esxcli storage vmfs unmap -l $datastore done |
The esxcli storage filesystem list
command outputs a list of datastores attached to the system. The second column is what I am interested in, so that’s what awk
takes care for me. I don’t want to target any local datastores, so I use grep
to filter out the ones I am interested in.
Next step would be to add this to a cron
job. Got to follow the instructions here, it looks like.