Clean up my Gallery2 iNodes

by Jérôme ~ August 12, 2008

Last months I received an email from HostGator saying that I had more than 50,000 iNodes and it was above the limit stated on the TOS.Those emails started complains at HostGator and client started to get out of the WebHost. The only options HG left to the clients was either reduce the number of iNodes or migrate to a dedicated server.

The first option implies that you need to delete files, most of the time emails and cache files. Deleting cache files is one thing, emails, it’s another. Most of the users do not want to do that.
The second option was out of question for most of all the clients: switching from a shared hosting at $8/month to a dedicated server at $150/month. No way, so client started to complains.
In response, HG issued a post asking their clients to ignore the email, saying that it was a bug in their cron. Was it a bug, well, I don’t think so, with my experience in HG, when there is a bug, they try to fix it right away and certainly not waiting one month to adknowledge this. I do think, it was their intention to enforce their TOS and when they realized their clients’ reactions, HG backed up to their previous internal policy which was just monitoring the iNodes counts and inform those who clearly are above the limit: 500,000 and silently stopping backups for the account above the TOS iNodes limit.

Why having an iNode limit? Well, it is pretty clear, they are performing a weekly backup of all the accounts and lots of small files are slow to backup and also increase the server load, on CPU usage and hard drive. Those raised few questions: are those backups needed when you do your own backups? Yes they are, for one sigle reason: what happen if the server crashes and some hardware fails, the account needs to be moved to another location. To do that, HG needs the backup. But the main question is, I have the smallest package: 350GB, and I am above the limit by just using 1% of the space, why offering so must space when you cannot use it. I think at this level, HG marketing department wanted to show how great HG packages can be and the Tech department, said yes but. And these buts did not appear on the packages descriptions.

Back to my problem. Even if HG backed up and will let my account alive, I’d rather follow the rules as a good Web citizen for them to backup my accounts as long as I don’t have to delete important data.
After futher investigation, I found out that Gallery2 creates resized and thumbnails on-the-fly and stores them on its cache directory, I had more than 28,000 iNodes in there.

Deleting G2 cache files by hand is not a problem because Gallery2 recreates the files when requested. So I needed a script that I could set on a cron job to monitor the iNode counts and delete the cache files when it’s above.
I have created this script. It will find all your gallery installations, cleanup the caches and progressively delete the derivatives (based on the last time it have been accessed, the less accessed will be deleted first) until it reaches the given threshold. Feel free to modify it regarding your needs. I distribute this script AS IT with no Warranty. And remember to always backup you files.

One Response to “Clean up my Gallery2 iNodes”

  1. chris Says:

    this is cool, i might implement it. just spent a few hours manually deleting about 200,000 inodes from my cache. cant believe there’s nothing something built in to Gallery2 to disable it or limit it from creating so many cache files

Leave a Reply