Advice on mass deleting backup files

Advice on mass deleting backup files

by Ehsan Anwar -
Number of replies: 3

Our users create backups of their courses but forget to delete resulting in our moodle data filling up.  I would like to create a simple php file that will run with the cron daily and delete any course backups that are over a certain period.  These are backups manually made by the user and are not automated backups.  I understand how the mdl_files tables associate with the moodle data through the contenthash; that when deleting a backfile through moodle, the file moves from fildir folder to trashdir to be deleted after 24 hours. 

I did a test and created a course and a backfile not used anywhere else.  Using a sql delete command I delete the id from the mdl_file tables but when checking filedir it has stayed there rather than going to trashdir so presume i'll need to use the file delete function.

Does anyone know where the function is located that is used for the delete confirmation box when deleting files (screenshot attached)?


Regards

Ehsan


Attachment delete.JPG
Average of ratings: -
In reply to Ehsan Anwar

Re: Advice on mass deleting backup files

by Ken Task -
Picture of Particularly helpful Moodlers

From the time you deleted the backup in the Moodle UI until you check to see if the file had been moved to trashdir, did the cron job run?

File system is really two fold .... the mdl_files table is the meta data ... removing the record that points to a contenthashed file in filedir means Moodle doesn't know anything about that file anymore ... becomes orphaned.

IF you remove a row in mdl_files that pointed to a file you must also find that file via contenthash sluething and remove the file @ moodledata/filedir/xx/xx/contenthashname.

Learned this while assisting a site admin after run-away automated backups (keep all???!!!!) filled up a 2 TB partition where moodledata lived.

You might check into using moosh ... for your purposes.

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Advice on mass deleting backup files

by Ehsan Anwar -

Yes the cron is running; deleting a backup from moodle website moves the filedir file to trashdir instantly.  As it was done through the moodle website the filedir file moved as normal but deleting a field through the database doesnt.  So was wondering if you know the function that the delete button uses as it will save time instead of deleting from the database and then going into the filedir and also delete.. not feasable if i have hundreds of backups to delete.  I have never used moosh before.. how can thag benefit me?


In reply to Ehsan Anwar

Re: Advice on mass deleting backup files

by Ken Task -
Picture of Particularly helpful Moodlers

See:

https://moosh-online.com/commands/

The commands: file-bbcheck and file-delete

The second command above:

Example 4: Remove all automated backups and reclaim the space

'spirit of sharing', Ken



Average of ratings: Useful (2)