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

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

by Zhivko Z -
Number of replies: 26

Hello,

Most of my server space is taken by pictures and PDF documents, which the online students have to upload on my Moodle sites.

When I clone the site - all these pictures and documents get cloned and the Moodledata files get bigger and bigger. Even when I delete the old user accounts - the old documents don't get deleted from the server. Eventhough the files haven't been used for 2 years, they are still there (on the original site moodledata and on the cloned moodledata) and take a lot of my server space.

How can I delete them from the Moodledata folder?? Is there are way or a plugin for it? 

Thanks a lot!

Moodle 3.1.2

Average of ratings: Useful (1)
In reply to Zhivko Z

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

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Let me assume that you mean they have uploaded them to Assignments?

Delete the Assignments - the files will be deleted too.

One caveat - file deletion is done by a background process, so Cron *must* be running and it can take a few days for the cleanup to complete.
Average of ratings: Useful (1)
In reply to Howard Miller

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

by Zhivko Z -
Hello Howard,

Yes, they were uploaded to Assignments.

Would you please clarify how can I delete the Assignments? If I go there, the only options I see are: Lock/Unlock, Download selected submissions and Revert to draft.

My cron is running every 10min. Is that good enough or I should do some change untill it's complete.

Also, I had deleted all users on a cloned site assuming that would delete everything about them. However, that didn't delete their assignemnts from the Moodledata. Is that how it should be?

Thanks a lot!
Average of ratings: Useful (1)
In reply to Zhivko Z

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

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

No need to delete the assignments. Since you are on a cloned site you should try to do a course reset, or reset individual assignments.

Average of ratings: Useful (1)
In reply to AL Rachels

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

by Zhivko Z -

Hello Al,

Would you please clarify how can I do a course reset or reset of individual assignments?

Also:

  • I have a lot of hard coded modifications and custom plugins, that's why I clone the site instead of creating a new one. Would course reset not affect those? 
  • This is not the first time I clone the site. The Moodledata has assingment submisions from the very fisrt cloning (from people whose accounts/profiles have been deleted and I don't see their Assignment submissions any more). Those are on the server but I don't see them anywhere in the course. How do I delete those?

Thank you very much!

In reply to Zhivko Z

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

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Zhivko,

Directions will be given for using the Boost theme. You must be logged in to the course as a teacher or admin. Click the gear at the top right, and select Reset.

From there it is just picking what you want to be reset, as you will have a page with General, Roles, Gradebook, Groups, and from that point on, a list of each type of activity in the course. You will need to work your way through the page setting options for each thing you want to reset.

If you want to reset ONLY assignments, ignore everything except, Assignments in the list. There are three choices of what to reset. Other activities may have only one item while some will have more.

Hope this helps.

Average of ratings: Useful (2)
In reply to AL Rachels

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

by Zhivko Z -
Hi Al,

I tested it on a new cloned site and did reset all the assignments. That deleted all the assignments, however, the occupied server space (Moodledata folder) didn't get reduced.

Could this be because I don't have a cron job setup on this site yet? I'm going to setup the cron, should that clear the server space?

Thanks a lot,

Zhivko
In reply to Zhivko Z

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

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
If I am remember correctly, removal is done by cron, so yes you need to set up a cron job.
Average of ratings: Useful (1)
In reply to AL Rachels

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

by Zhivko Z -
Thank you so much, Al! After the cron ran - the job was done!

So:
1. The assignment submissions can be downloaded from Assignment
2. The submissions can be deleted through Course Reset - Assignment

Precious information, highly appreciate it.

A couple of quick question related to this if you don't mind:
1. If I reset Grades, Feedback, Quizzes and Certificates - that will delete only the previous student data and will not affect how these plugins work, right? It is safe to reset all these?
2. If I reset the assignment submissions on an active course with active students on it - can that create issues with the current students (I have downloaded the submissions, they are graded, and seem to remain graded/activity is still marked compete after the deletion)??

Greetings!
Average of ratings: Useful (1)
In reply to Zhivko Z

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

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
1. If you, "reset Grades, Feedback, Quizzes and Certificates," the data controlled by the options you select for reset for them in the course, is gone including those for previous and current students. Each plugin will still work, so, as long as you are wanting to get rid of the data, it is safe to reset.
2. If you, "reset the assignment submissions on an active course with active students on it," the assign submissions for EVERY student, including CURRENT students, is gone. But, as long as you do not reset the options for, Grades, all that data is still there. Also, as long as you do not reset the pertinent items under, General, the competency data is still there.
Average of ratings: Useful (2)
In reply to AL Rachels

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

by Zhivko Z -
Thank you very much, Al.

Best wishes!
In reply to Zhivko Z

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

by Zhivko Z -
Hello Al,

A quick follow up question please.

After I deleted the Assignment submissions, I need to delete the old student accounts (transferred during the cloning). WHAT IS THE BEST WAY TO DO THAT?

I did delete some of them by going to Site Administration – Users – Bulk user actions. However, after the deletion – the occupied server space went up instead of down. I delete them a little by little as I had tried to do all of them at once in the past and that triggered some Moodle backup process, which increased the server space a lot.

Would you please give an advice what is the best way to clean the new (cloned) site from all old user information?

Thanks a lot
In reply to Zhivko Z

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

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

"– the occupied server space went up instead of down." - This is true in many cases as Moodle generally keeps a copy for about a week before actually deleting many things. This is because over the years there were MANY people who would delete things and then realize they made a mistake and actually still needed what they had just deleted. So a few versions ago, the "delayed" delete was created by adding the recycle bin.

My way for deleting users was to do it with a CSV file. I always enrolled students with a CSV file, and it was very easy to include a "deleted" column. Normally, I would have 0 in the column, and when I needed to delete someone, I would change it to 1. Otherwise, I did like ou and used Bulk user actions.

Average of ratings: Useful (2)
In reply to AL Rachels

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

by Zhivko Z -
Thank you, Al!

Would you please share how does it work? 

If I delete the users via Bulk user action - their Assignment submissions are obviously still on the Moodledata folder and I need to reset the Assignment submissions in course to clean it all. 

  • What else is on the Moodledata folder, and will not get deleted using Bulk user action?
  • If I reset the Assignment submissions, and then deleted the users via Bulk user action - would that clean it all?

I appreciate your help.

In reply to AL Rachels

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

by Kashif Kash -
Hi,
I delete some lectures vidoes (meida files) from some courses
But space still shown.
How can I delete old media files from the server (Moodledata folder)?
Kashif
In reply to Kashif Kash

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

by Ken Task -
Picture of Particularly helpful Moodlers

@Kashif

Run cron job.

Then use whatever you have to browse files on server ... command line best.   Linux?

Go to moodledata location

du -h ./trashdir (will show space being used)

cd trashdir

rm -fR *

If there is anything in trashdir above will remove it.

cd ../

du -h ./trashdir

'SoS', Ken

In reply to AL Rachels

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

by Zhivko Z -
Hello Al,
I noticed that after deleting the Assignment submissions via Course Reset - all students get moved from "Submitted" to "Not submitted" in Assignment. This creates issues as they get mixed with new students who I need to monitor and remind to submit...

Is there any way for those students to remain "Submitted" after deleting the Assignment submissions??

Thanks
In reply to Zhivko Z

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

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I would say that what you are seeing is logical. When you reset, their submission is removed and if they are still enrolled in the course, they fall into the category of, "Not submitted."

If you are using continuous enrollment, maybe a better way to handle those users would be to use a separate group for completed students, and place them into the group, while leaving their submissions alone.

If your course enrollments are on a calendar basis, such as a new semester, the way I used to handle that was to start a new course, and hide the old ones. I was required to keep "records" for five years, so when a "hidden" course hit the six year mark, I deleted them.

At one time, I was using a server slightly too small, to handle that many hidden courses, so I would back them up to a portable HD, then deleted the original. If I needed access to the old data, I could reinstall the needed course. Luckily for me, I never had to do that for real, but each year would test restore the new backups as a new course to make sure they worked, before deleting the original and the test restore.


Average of ratings: Useful (1)
In reply to AL Rachels

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

by John Pin -
Hi,
and what about files not associated with assignments. I made my moodle course and uploaded all video mp4 instruction videos into the moodle course server. (around 200 of them) Then sometime later, I placed all my files in a vimeo account and linked the moodle course modules to read from Vimeo - thus not using the video files in moodle. How do i can i go in and delete those files from the server?
In reply to John Pin

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

by Sylvia B. Hayes -

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)