Moodlers, hi there!
History:
Recently our school faced super unexpected problem: Cron that was running on the server started to gobble all free space on Hosting. And only within a night (8–9 hrs) it gobbled up the whole free space there. As a result our platform stopped working and we lost more than 3 business days of income. Our students suffered from the poor platform performance.
I was looking for a solution across the web and couldn't find it. Moreover, I found an "expert" on Fiverr who guarantied that he knew how to solve my issue with Cron. As a result - 2 more days were wasted.
I almost gave up, but decided to try to contact some of the Moodle Forum experts. I even bumped into similar problem in one of the forum's topic, but it wasn't clear enough to me: lot's of code examples and weird words that didn't help me at all (Despite that fact that I possess a technical degree long time ago and for the last 8 years I'been working as a Product UI Designer) 😅.
So I contacted Ken Task and explained to him the technical issue. I decided to try my luck. And within couple of hours he got back to me with the solution.
_______________________________________
The Solution:
Via DB client either CLI or PHPMyAdmin, query to find backup files:
SQL Query: Select rows (helps us to select & find rows in database that contain all that backups specificly with file format *.mbz )
select id,contenthash,filename,filesize from mdl_files where filename like '%.mbz';
Find the dup .mbz you want to remove ... and note it's contenthash value (actual name of the backup file).
For examples below using the * line below.
ID | contenthash | File Name | Bytes |
---|---|---|---|
3650885 | 30f8f3b48dc932162bd2d673f7fdb01387cea58c | backup-moodle2-course-9-pre-calculus-20180601-1332-nu.mbz | 429238267 |
3650886 | 78f64e3876c4a6e0e3ca2aa97e4e278e75fbea0d | backup-moodle2-course-9-pre-calculus-20190531-1029-nu.mbz | 215092440 |
3650888 | 408a1f03939d8adcd0e538f358e96b6399faf9ce | backup.mbz | 164258176 |
etc... Amount of rows depends on how long the Cron task was running.
In above example, I want to delete the row with ID –> 3650885 above
It's contenthash is: 30f8f3b48dc932162bd2d673f7fdb01387cea58c
From something that allows finding files – command line best. Or you can use File manager. In moodledata/filedir/ (in my case it was onlinedata/filedir/):
cd /path/to/moodledadata/filedir/
find ./ -name [contenthashvalue]
find ./ -name 30f8f3b48dc932162bd2d673f7fdb01387cea58c
That will display something like:
./30/f8/30f8f3b48dc932162bd2d673f7fdb01387cea58c
To delete the file
rm ./30/f8/30f8f3b48dc932162bd2d673f7fdb01387cea58c
Now go back to the DB and remove the Row that has that id number.
id in example is: 3650885
SQL Query: Delete row
DELETE FROM `mdl_files` WHERE `id` = 3650885;
Wash, rinse, repeat there after AS MANY TIMES AS IT REQUIRES. 😀
Terminal commands:
pwd - present working directory - shows where you are
cd - change directories ... into moodledata/filedir/ for example
ls - list files/folders
rm - remove a file ... *use with caution and be very accurate ... no wildcards
cat - show contents of an ascii (text file)
When clicking terminal you are in your home directory. pwd shows path to your home directory ls and look for a public_html directory
cd public_html
ls config.php ... is it there?
cat config.php ... looks at contents of file given ... look for path to mooodledata
cd [pathtomoodledata]/filedir/
Now you can use the find command shared earlier
and you can use rm ... *carefully*
Kudos to Ken Task!
If you need help or any advice regarding fixing Moodle issues, Ken is definitely a to-go person!