Cron Kills free space on Server by creating Backups.

Cron Kills free space on Server by creating Backups.

by Vlad Tyzun -
Number of replies: 3

Moodlers, hi there! 

  1. Moodle ver: 3.9
  2. Database: MySQL

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.


Results of select SQL request
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 managerIn 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!


Average of ratings: Useful (2)
In reply to Vlad Tyzun

Re: Cron Kills free space on Server by creating Backups.

by Ken Task -
Picture of Particularly helpful Moodlers

Thanks!  Just a word of caution for others that might read his great summary of how-2 ... this method isn't really recommended as one is directly modifying tables and removing files from moodledata/filedir/ ... must be exacting and it works best if one is not suffering from 'clas' (command line avoidance syndrome').

Dis-calmer ... nope, spelled it right!   Am not responsible for those who try this and are not exacting, cautious, and who suffer from 'clas'. smile

'SoS', Ken


In reply to Vlad Tyzun

Re: Cron Kills free space on Server by creating Backups.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The thing that concerns me here.... what caused this in the first place?

As Ken says - I would regard this as somewhere between advanced and desperation. There's probably a safer way.

...and...

"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"

This is the first post you have made in these forums. 
In reply to Howard Miller

Re: Cron Kills free space on Server by creating Backups.

by Ken Task -
Picture of Particularly helpful Moodlers

'First post' ... OP is shy? smile

Agreed ... leans towards desperation, but ... have been involved in two others like this ... unfortunately, for one, DB server in an all in one box.  Had autobackups set to 'keep all' ... no space = corrupted DB on that server.   What a mess!

Which leads to something that probably should be a plugin or added to core moodle for admins ... a resource usage panel ... difficult to program for all possible hosting.  Shared hosting folks are at risk all the time.

Someone shared screen shot of their system recently that showed such a thing in Moodle.   Is there a plugin?

I use a thing called 'Logwatch' (not a moodle plugin) ... sends a daily summary of yesterdays activity ... at bottom of that shows disk info.

'expert' is sometime defined as one who can recognize the same mistake they made before! smile

My 2 cents! smile

'SoS', Ken