Deleting old tests on a private WebPageTest server

In a prior post I mentioned that I had ran out of disk space on my private webpagetest instance. I temporarily fixed it by mounting another drive for the results, but what happens when that disk filled up? I’d be in the same situation all over again!

I decided in order to avoid another full disk I wanted to delete old tests to make space for new ones. I really don’t need to be keeping every old tests around, as the site most likely had changed if it was that long ago, thus the results are obsolete.

Where to delete old tests

Luckily the structure of the results is made in such a way that deleting old tests is extremely easy. Everything is first organized into folders by year, then mounth, then day.

For example, a test I ran yesterday (Jan 8th, 2015) is stored in /www/webpagetest/result/15/01/08/….
If I don’t want any of the tests from yesterday, I can delete that ’08’ directory.

I can login every once in a while and manually delete old months, years, etc with a simple ‘rm -rf’ command on the directory I want to remove. This is the easiest solution to perform, but requires regular maintenance.

Automatically deleting old tests

I hate the idea of manually deleting old tests, as it takes work for me to remember to do that, and who wants more work? Let’s figure out a way to do it automatically so I never have to login and the server will hum along just fine years from now.

If you’re a unix guru you could probably whip up a shell script that would delete old files. But WebPageTest already has something better than that built in – the ‘archiving’ feature. By default, you set how many days to keep tests locally and then after that old tests will be sent to an archive location.

We don’t need the tests archived, but after they are archived they are deleted. All we need to do is disable the archiving, but let the deleting continue and we have our solution.

It’s really simple to modifiy archive.php to not archive, just delete, by commenting out a block of code in the CheckTest function of archive.php

Here’s the code I commented out:


Now all you need to do is add the cli/archive.php script as a cron job so it will be run regularly and we’re set!

[root]$ sudo crontab -u apache -e
0 * * * * php archive.php

Finally set archive_days and archive_dir in settings.ini. Although the archive_dir isn’t used, it must be set to something for the archive script to run properly.

Note: If you copied your previous test results contents to the new results disk, every test will have a recent ‘last accessed’ time, so you’ll need to wait at least as many days you specified in your archive_days before it starts archiving any of your previous tests.

You’re done, hope that helps!