VM swapfiles: Leftover swapfiles

Every time a VM is started a swapfile is created on the datastore where the VM resides.

The format for these files are .vswp

I was working my way through a customers datastores, trying to find some orphaned VMs or files that could be deleted and I noticed that many of the VM folder had the .vswp files and then some extra ones.

The extra vswp files had a different ending, and that was vswp.xxxxx, where the x’s represent a number.

These files are created when your ESXi hosts crash and when the VM was restarted, the file was still there so it’s renamed and a new .vswp file is created.

For an active VMware environment, you could potentially see a lot of these if you had some ESXi crashing on you in the past. For that environment (around 60 VMs)  I found 34 GB of “dead” .vswp files. That’s a lot when your Datastores are at full capacity.

But you really can’t manually go searching for these unless you like repetitive and brain-damaging work.

This really isn’t a big piece of code and really doesn’t deserve a script by itself 🙂

dir vmstores:\ -Recurse -Include *.vswp.* | Select Name,Folderpath

This will give you a output of:

Note: This will take a lot of time to run on bigger environments. I tried this in a big production environment (40+ Datastores) and it took 5 hours to run. But it found 24GB of emtpy .vswp files.

I hope this helps to find some space on your expensive SAN 🙂

Edit: Raphael Shitz at http://www.hypervisor.fr has a great script for searching for orphaned files on Datastores and he added a search for “*.vswp.*”.  And its a lot faster, only few minutes rather than hours. His site is in french so here is a link to his post through Google translate. And if you can read french, Allez.

About larushjartar
VMware Specialist and IBM Technician.

3 Responses to VM swapfiles: Leftover swapfiles

  1. Pingback: [PSH] Raiders of the Lost VM files – MAJ - Hypervisor.fr

  2. Hi Larus, i modified my script to include the vswp.xxxxxx files. It only takes few minutes on 200+ big datastores and you get all the orphaned files. i also modify the automatic orphaned vswp files remover. Thanks a lot for the idea 🙂

    • larushjartar says:

      Nice, glad I could help 🙂 I will give that script a run tomorrow in my lab. Few minutes sounds much better than 5 hours 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: