Views: 3479
Number of votes: 6
Average rating:

Plugin for deleting unreferenced media

Sometimes you need to synch a dev-environment with production database and media and the blob-storage is huge with likely a lot of unreferenced media or perphaps want to clean up a test-environment.

To help in those two scenarios I threw togheter a small plugin that lets you delete all or just selected unreferenced media. Really nothing to say about the code than it can be found over at my Gist.

It looks like this:

Image cleaner.jpg

Sep 05, 2017

( By valdis, 9/6/2017 8:44:26 AM)

where you were couple weeks ago? when we had ~ 1TB of unreferenced media ?? :) great plugin

( 9/6/2017 9:13:29 AM)

Valdis: Thanks. Actually did this before the vacations but haven't got around blogging for quite a while. Been thinking about doing a scheduled job version for a more hardcore approach to keeping the assets folder clean :)

( By GOSSO, 9/6/2017 1:55:37 PM)

The wheel is already invented =)

Removed about 12% on production server, take backup in case.

( 9/6/2017 3:06:32 PM)

Gosso: I googled before I made the plugin but not good enough. But my version has cherry picking of files. :)

( By GOSSO, 9/6/2017 3:56:53 PM)

Also check out the mega super awesome amazing DownloadIfMissingFileBlogProvider for dev and staging environment.

with that addon you can

  • ... delete all blobs - and it takes care of downloading the images/documents you need
  • ... use diskspace to other things... It only downloads the blobs you're using
  • ... go home earlier, since you'll never ever need to download the blob-directory anymore.

Try it =)

( 9/6/2017 4:16:26 PM)

I agree that your DownloadIfMissingFileBlogProvider is the best thing since slice bread. :)

( By valdis, 9/7/2017 5:59:12 PM)

I guys will leave you there :D

Johan Book
( By Johan Book, 2/17/2018 10:31:09 AM)

I just wrote a quick script to remove blobs that have no entry in CMS, then I found this post :D

To Per's defence, his version does indeed go one extra step by checking what's actually referenced, and not only what exists in CMS. The DownloadIfMissing plugin looks awesome, but if you can't use it for some reason you'll need to do a combination of both approaches to slim it to the maxx. Thanks Per!

( 2/26/2018 11:44:31 PM)

Glad you found it usefull.

Please login to comment.