General help

Deleting old courses (moodledata)

 
Picture of Mark Hayes
Deleting old courses (moodledata)
 

Moodle 3.2.2 on Ubuntu 14.04 LTS

We old course which I would like to delete.
Does deleting a course remove the artifacts related to the course (uploaded files, etc) that are stored in moodledata?

We have some old courses that grew very large because teachers stored things in the course which should have been stored in an external repository of some sort. I want to ensure that this extra baggage is also removed.

(Prior to course deletion, does a course backup (.MBZ) file include all the artifacts from moodledata?)

 
Average of ratings: -
Picture of Mark Hayes
Re: Deleting old courses (moodledata)
 

sorry,

We have old courses...

 
Average of ratings: -
Picture of Mark Hayes
Re: Deleting old courses (moodledata)
 

Just did some testing.

I reset a course, backed up the course, downloaded the .mbz file, deleted the course.

Then from within another course, I attempted to access, via the File Picker, files that were part of the course I just deleted, and the files were not available.

Can I conclude that the files associated with the deleted course have in fact been removed from the moodledata folder, or are they just not accessible?

 
Average of ratings: -
Picture of Ken Task
Re: Deleting old courses (moodledata)
Particularly helpful Moodlers

Files associated with a course are not removed if the files are linked in another course.

If files are removed (from view), they are moved from the normal storage area (moodledata/filedir/) to moodledata/trashdir and remain there until the cron/task job runs to empty the trash - last I checked that was 4 days from the time of the deletion.

The file system itself ... no longer are files stored in humanly recognizable names, but rather, a contenthash value and the humanly recognizable filename is associated with the contenthash in a column of mdl_files in the DB.

So working with/finding deleted files might require a DB query:

select filearea,userid,filename,filesize,contenthash,timecreated,timemodified  from mdl_files where filearea like '%recycle%';

From a bash-shell script I have to do the query above and dump to a text file, looks like:

[root@server cli]# ./getrecycle
filearea    userid    filename    filesize    contenthash    timecreated    timemodified
recyclebin_course    2    backup.mbz    1581308    65d80bf797a246d0d737214d460a6d9a6187c54c    1540932182    1540932182
recyclebin_course    2    .    0    da39a3ee5e6b4b0d3255bfef95601890afd80709    1540932182    1540932182
recyclebin_course    2    backup.mbz    1603299    efd3b7750647f503fb65bca66f066321765b0b84    1540942382    1540942383
recyclebin_course    2    .    0    da39a3ee5e6b4b0d3255bfef95601890afd80709    1540942383    1540942383
recyclebin_course    2    backup.mbz    1601119    85188b6b7fe42c490ea3cf0c90ecb85ede78a9f0    1540942982    1540942982
recyclebin_course    2    .    0    da39a3ee5e6b4b0d3255bfef95601890afd80709    1540942982    1540942982

The time columns are epoch time stamps.

Taking the 2nd to last line above and executing the following commands from moodledata/filedir:


[root@server filedir]# find ./ -name 85188b6b7fe42c490ea3cf0c90ecb85ede78a9f0
./85/18/85188b6b7fe42c490ea3cf0c90ecb85ede78a9f0

[root@server filedir]# ls -l ./85/18/85188b6b7fe42c490ea3cf0c90ecb85ede78a9f0
-rw-rw-rw- 1 root root 1601119 Oct 30 19:43 ./85/18/85188b6b7fe42c490ea3cf0c90ecb85ede78a9f0

[root@server filedir]# file -b ./85/18/85188b6b7fe42c490ea3cf0c90ecb85ede78a9f0
gzip compressed data, from Unix

Personally, I'd like to see a recyclebin directory in moodledata to deal with deleted files/courses/backups etc. by themselves rather than having to mess with filedir ... especially when server has a space crunch ... needing space *NOW* ... would know where to go and know that removing files manually (never advised but, we do what we must) would not have adverse affects.  But also know that something that sounds simple, isn't ... when it comes to the core code.   That's my 2 cents as a hacker ... ie, not a true programmer.

Also, not sure when this recyclebin stuff showed up in moodle code ... above from a 3.3.8+ version of Moodle and know same is present in a 3.4 and a 3.5.   Below that?

A lot of this is automated via task which run when the main cron is run ... which should run every minute now.  Check the task list for scheduling the clean ups.  Is your cron running every minute?

Also, there is a command line utility for Moodle called 'moosh'.   It has a few commands for files/filedir and meta data in DB.    See: http://moosh-online.com/ and http://moosh-online.com/commands/

'spirit of sharing', Ken


 
Average of ratings: -