Friday, March 8, 2013

How to list the largest files in a Moodle 2.x site

Earlier this week, I was working with a client whose Moodle server was full. They asked me to help figure out why it was full. This can be a challenging question when using Moodle 2.x due to the fact that files are saved in a single hashed space. In this client's case, 6 SCORM files were using 3/5 of all their storage. Here is the simple query I developed to create the list showing the original filename and path, the storage used in megabytes, the content hash (ie filename used in moodle data folder), and which component of Moodle owns the file. The output is sorted by largest files first with a limit of the 50 largest files.


SELECT DISTINCT filename, filepath, FORMAT( (filesize /1024 /1024), 1 ) AS filesize_MB, contenthash, component
FROM  `mdl_files` 
ORDER BY filesize DESC 
LIMIT 0 , 50


If you are a Remote-Learner hosting client you can run this query via your phpMyAdmin link contained in your customer kit, or request via our support portal.

During this research I also found that its is possible for a file to become orphaned. In this situation the file is still stored in the moodle data folder, but is no longer referenced in the mdl_files table of the database. Look for a future post on how to track down orphaned files.

5 comments:

  1. Thanks. I'm looking forward to the "how to track down orphaned files" post!

    ReplyDelete
  2. hi, i have two moodle and i name it Moodle (A) and Moodle (B)and run it in localhost...

    I want to get the mdl_files resources from Moodle (A) like the files with ext .ppt or .pdf and move it to Moodle (B).

    but i can't find the relation to query the database and move it to Moodle (B).

    the goal is I want to replicate the courses (and the components inside such as forums, files, assignment and resources) from moodle (A) dan move it to Moodle (B)

    can you give me an advice how to do it ?

    i using java and windows to build an application to sync the moodles...I do not use php or linux...thx !

    regards :)

    ReplyDelete
  3. Hi Jonathan,

    It is nice and useful moodle lms information sharing for us. thank you..

    ReplyDelete
  4. Thanks for sharing about moodle 2x.

    ReplyDelete