Hello to all... Yet another question about disk space on the forum
Our Moodle installation is almost 15 years old, the fist graduation category is tracing to 2005. In this time period we scaled from 500GB to 1TB than to 2TB of disk space. But now it's time to make a cleanup. Legislation in Brazil requires the files to be saved for 5 years, so we decided to remove all courses older than 2015. The courses are allocated on the categories based on the period it happens.
So.. I decided to use the moodle API to remove old courses. The moodle version is 3.5.9 and the code i used was this snippet:
<?php
define('CLI_SCRIPT', true);
require_once(__DIR__.'/../../../config.php');
$category_list = [1, 2, 3, 4, 5 ...];
$category_list = implode(', ', $category_list);
$courses = $DB->get_records_sql("SELECT mco.id, mco.fullname, mcc.name
FROM {course} mco, {course_categories} mcc
WHERE mcc.id = mco.category AND category IN ($category_list)");
$ammount = sizeof($courses); $item = 1;
foreach($courses as $key => $course){
try{
echo "Category $course->name -- Course $course->fullname $item / $ammount \n";
delete_course($course->id);
$item++;
}
catch(Exception $e) {
//code to print caught exception
}
}
I noted down the disk usage, executed the script with some categories to test and executed the crontab function to clear unused files
php admin/tool/task/cli/schedule_task.php --execute='\core\task\file_temp_cleanup_task'
php admin/tool/task/cli/schedule_task.php --execute='\core\task\file_trash_cleanup_task
php admin/tool/task/cli/schedule_task.php --execute='\core_files\task\conversion_cleanup_task'
Before the first test the system had 27289 courses and was using 1,7T / 2,0T
#df -h | grep /var
/dev/sdb1 2,0T 1,7T 217G 89% /var
#Postgres Select
moodle=# select count(id) from mdl_course; count ------- 27289 (1 registro)
After the test, the system had 20395 courses ( -6,894 courses ) and somehow the disk usage increased to 1,9T / 2T
#df -h | grep /var
/dev/sdb1 2,0T 1,9T 45G 98% /var
#Postgres Select
moodle=# select count(id) from mdl_course; count ------- 20395 (1 registro)So..
What is the correct way of removing old courses to free disk space? Preferable not moosh