How can I delete old media files from the server (Moodledata folder)?

Re: How can I delete old media files from the server (Moodledata folder)?

by Sylvia B. Hayes -
Number of replies: 6

I am having the same issue. I cannot find the video files I have deleted, but they are still showing up in my storage??? 

In reply to Sylvia B. Hayes

תשובה ל: Re: How can I delete old media files from the server (Moodledata folder)?

by lilach bareket -

Hi

We have a similar question: is it possible to delete files from moodle data, attached to one of the moodle categories ?

In reply to Sylvia B. Hayes

Re: How can I delete old media files from the server (Moodledata folder)?

by Matej Topolovec -

Hello everyone,

Is there any possibility of deleting files that were uploaded through the Moodle Repository? In particular, these are quite large .MP4 files used as video lessons. We recently embedded video lessons via Vimeo, but these previous ones are still in the repository.

I have reviewed all the answers to the forums related to this topic and do not find a specific answer anywhere. I am sure .mp4 files are not used anywhere in the course, Cron works regularly, it has been a long time after which the files were supposedly to wipe themselves, but nothing happened. There is not a single file in the trash.

The course is so large that I cannot even do backup and I occupy an extremely large server space.


Thanks in advance for your answers!

Matej Topolovec

In reply to Matej Topolovec

Re: How can I delete old media files from the server (Moodledata folder)?

by Ken Task -
Picture of Particularly helpful Moodlers

@Matej - others - this may/may not apply to your situation ...

Newer versions of Moodle have a 'recyclebin' which makes .mbz backups of what you delete in a course and retains that backup in moodledata/filedir/ until the setting for how long to retain has expired.  Then those files are moved to trashdir and in 4 days time finally removed.

So, check recyclebin settings site wide and set to retain least amount of time - which is 1 second ... that hurries along deletions.   Also set recyclebin link to show all the time in the course admin menu.   You can then see what's there and manually delete.

There is no recyclebin for courses you delete.

Please see:

https://docs.moodle.org/401/en/Recycle_bin

If cron isn't cleaning up, and you have command line access to your server, you could install moosh - a command line utility for moodle.  It has a couple of commands related to orphaned files - finding - also deleting.

https://moodle.org/plugins/view.php?id=522

https://moosh-online.com/

'SoS', Ken


In reply to Ken Task

Re: How can I delete old media files from the server (Moodledata folder)?

by Matej Topolovec -

Thanks for the answer @Ken Task!

Recycle bin has been set to 1 hour for a long time, but here I will change for 1 second, though I don't believe it will help. Also, I set up to be visible all the time. I also attach a picture in this answer.

I approach the server via CPanel so I have to see if I can use Moosh.

Best regards!

Attachment recycle_bin.png
In reply to Matej Topolovec

Re: How can I delete old media files from the server (Moodledata folder)?

by Ken Task -
Picture of Particularly helpful Moodlers

@Matej

If you have set those to least amount of time and always display, then go to the course you can't backup, with edit mode on, see if there is a Recyclebin link in the course admin menu.   Click it.   See anything listed?   If so, there should be an option there to delete.   Click them.

That should move those items to trashdir.   In your cPanel file browser, go to trashdir and see if it's populated with anything.   If it has anything in it, delete.   That will not harm your moodle.

Things could be stuck in adhoc task.   So set the path to php-cli in paths ... the path is the same you see in setting up the cron job.  Once you get that set up, go to the scheduled task list ... look for 'clean up' task.   Should be a link for 'run now'.  If you have a back log of files to be deleted, it will consume a lot of memory and take quite a long time to complete - if that fails, then you might also have to increase PHP variables for time for a script to run as well as max memory to use in Easy Apache setup.  You also might have to 'run now' multple times to get things caught up.

Am not an expert in cPanel - don't use it myself - but ... in your cPanel, do you see a Terminal icon?   If so, you can run moodle cli commands found in multiple directories of Moodle code.   Those take your web service out of the loop and it's just php talking to your database/file system to execute.

All this, as you can tell, has had a 'dominoe' affect. sad

If you are on a shared hosting plan, you might not have enough access to be able to clean this up from cli and have to suffer via GUI.

'SoS', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: How can I delete old media files from the server (Moodledata folder)?

by Ken Task -
Picture of Particularly helpful Moodlers

Follow up to own post ... trying to keep separate for @Matej

The other source of large files etc. in a course are course backups.   Teacher might have multiple backups and has never cleaned up old ones in the teachers private file area.   You as admin may not see those.

So ... there's a plugin for site admins:

https://moodle.org/plugins/report_allbackups

Make sure you get the version that is compat with your version of Moodle.

'SoS', Ken


Average of ratings: Useful (1)