Clear out unused/old media files

Clear out unused/old media files

by Tim F -
Number of replies: 9

My moodledata folder is 11GB and I want to clear out unused media and put media onto youtube - any ideas for best workflow?


I think over 70% of that media is unused but there are so many folders i couldn't find anything./organizationally...

Average of ratings: -
In reply to Tim F

Re: Clear out unused/old media files

by Ken Task -
Picture of Particularly helpful Moodlers

There is no admin tool that will list all video files uploaded and served from Moodle code.  Best way is to query moodle db mdl_files table seeking all files whose filename extension matches what you uploaded ... mp4's?

select filename,filesize,component,userid,contenthash from mdl_files where filename like '%.mp4';

change mp4 to whatever you might have used in query above .. hopefully not .flv's.

contenthash value is the location of the file in moodledata/filedir/XX/YY/name (which is the contenthash value).

Before removing those from a course, suggest getting the streaming service video content in place first, then remove.

Once new is in place and working, remove the older.

'SoS', Ken

In reply to Ken Task

Re: Clear out unused/old media files

by Tim F -
Yes - mostly are .mp4 and the occasional mp3
We don't have students at moment so the naming is not an issue - some of the enrollment flows will need to be reworked but that is ok.

Yes the second option is much more realistic - and actually I think alot of them are in old courses that i have kept in the "previous courses" caetegory (I guess for Nastalgia) and in case I needed an activity but it sounds like the best practice will be to remove those.

And if I am understanding the flow - that if we continually update our courses and slowly moved all media onto servers/cloud services and deleted old courses that we would also be "reducing" the file size as we evolved and introduced new courses with media on youtube etc and deleted old courses where media was uploaded into our platform...is this understanding correct and anything I am overseeing or you think is relevant in a flow like that? Thank you!
In reply to Tim F

Re: Clear out unused/old media files

by Ken Task -
Picture of Particularly helpful Moodlers

Kinda.  One thing is constant ... and that is change!   Besides that, 'flow' and process for the entire site and courses is kinda a thing that every site admin working with teachers has to work out for themselves.

Without getting details about server (like version of Moodle, where and how hosted, memory, *free space*, etc.) from ya cept your goal + 'about 11Gig' + 'Nastalga' ... am venturing a guess you've a small site and space is a concern.

I think your understanding is correct .... however, now to throw a curve .... the media you will be moving to 'cloud services' ... what is your expectation of that media going 'viral'?

If no concern there then ... plan as best you can your flow ... and go forth!

What is it that is said ... 'plan your work ... work your plan!' smile

'SoS', Ken

In reply to Ken Task

Re: Clear out unused/old media files

by Tim F -
Ken! Yes I want to keep the space down to stay under the free limit for Amazon AWS at the moment!

And I want to give us the ability to swap out media and not have to worry about "wasting space" (i think that term is still relevant on the cloud smile

I am not concerned about the media we have created "going viral" and all of the videos are hosted on youtube as "unlisted" - which doesn't guarantee it is not available to others it does reduce the chances.

This flow of the copy of new courses with new names and "flushing out" the old media I think is the best solution for us personally. I do have some concerns about migrating student progress and enrollments to the new courses as theoretically

we would create
Course 1 NO AV on Monday
and then it would take a day or two to make sure it is clear and contains correct media refrences - during that time the student would continue to work normally on Course 1 ORIGINAL

Then on Wendsday we would want to put all students and their progress into new COURSE 1 NO AV and delete COURSE 1 CLASSIC - and update link references to that course (on "dashboard" we have some HTML blocks linking into the courses)

I guess there are some best practices / flows that we need to work out that will allow us to constantly change and update/upgrade our courses and content within.
In reply to Tim F

Re: Clear out unused/old media files

by Ken Task -
Picture of Particularly helpful Moodlers

Your description of your 'imagined' flow would require programming me thinks - don't think it currently exist ... but I haven't really looked at plugins to see.

While you are 'converting media' in a course that has been restored, students continuing to work in the original course ... even one day ... means you'd have to find a way to 'import' the students activity for X days opr X hours ... however long it took to 'convert media'.   More customization?

What if you created the YouTube media in advance and had those url's or whatever ready  to replace the media uploaded to the course.   How long would it take a course designer to replace each - old media to new media?

To retain all students work/tracking/completion, etc. would think both courses would have to be hidden until media conversion finished if there is a ton of media conversion to do ... then only the new course made visible again.

There's a 'catch 22' if one is doing tracking/completion/sequencing ... you are replacing old media (links to files?) that have already been checked off as completed.  Think you'd have to make new media self checked and if there is a sequence students must follow that needs to be checked as well to see how much trouble students will have (don't want to put them in a 'catch 22').

'SoS', Ken

In reply to Tim F

Re: Clear out unused/old media files

by Ken Task -
Picture of Particularly helpful Moodlers

As is normal ... nothing like what you need to do is straight forward and has an 'easy button' ....

In addition, you need to check recyclebin settings and set those to lowest/shortest amount of time.  Also set recyclebin to display all the time in courses. 

When you delete a resource like a link to a video/audio file you've uploaded to moodle, that deletion, creates a recylebin backup of that resource.  

So if recyclebin settings are left at defaults, space usage will actually increase for the length of time set to keep recyclebin backups.

Please see: https://docs.moodle.org/310/en/Recycle_bin

What is 'the free limit for Amazon AWS'?

'SoS', Ken

In reply to Ken Task

Re: Clear out unused/old media files

by Tim F -
So after some more digging I found that my "trashdir" file in MOODLE is 8GB - How can I delete this? I have some people helping me with server stuff and I was thinking to set a CRON job to clear it but I was wondering what is best practice and to double check that this is not actually being used that this "trashdir" folder in MOODLEDATA is in fact the trash...thanks!
In reply to Tim F

Re: Clear out unused/old media files

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
When you delete a file in Moodle, it removes the reference to the file content from the database.

Once all references to a particular piece of content are removed, the file itself is transferred into the "trashdir".

If, after a bit of time (I think it's a couple of days, but I don't know for certain), the file has not been reclaimed from the "trashdir", then it is automatically deleted by a scheduled task.

Off the top of my head, I believe the files in "trashdir" can probably be safely deleted (it's a bit like the recycle bin in Windows - there as a last-chance to recover files, but won't break anything if you clear it early).
Average of ratings: Useful (2)
In reply to Tim F

Re: Clear out unused/old media files

by Ken Task -
Picture of Particularly helpful Moodlers

Another way ... if first too techie for ya ... and something you probably should be doing anyway ... or should learn how to do ....

Make backups of courses (11 Gig doesn't sound like many courses).  Step through the stages of the backup screens and when getting to the screen for what resources to include in the backup, deselect any audio/video.   When naming the backup include something like '-noav-' in the name to make those different from other backups you might have.

Those backups can be restored to same category - slightly different names and hidden for a little while, until you get the new audio/video links in place.   Once everthing in place, un-hide the new and hide the old.

Students accounts and their work should still be present but they might need to know in advance what you are doing and that the new courses have slightly different names so as not to freak them out! ;)

That won't reduce the space, not until you detele the old courses.   When doing that, recyclebin kicks in and backups of those deleted courses are made - in case you change your mind - for about 7 days.   Then, those recyclebin backups are moved to the trashdir and 4 days later, cron jobs see no longer linked anywhere and finally removed.

So if using above ... check how much space you have to work with ... how much?   Well, 11G x 3 would be a safe minimum *guess* I think.

'SoS', Ken