Forums | Mahara Community

Developers /
Mahara Deleted file Retention

Andrew Boag's profile picture
Posts: 2

17 May 2016, 15:52

Hi all,

This question comes from the discussions with client around backup and recovery stuff.

Context: in Moodle when a file from the Moodle local file store is deleted. The actually underlying file stays around on the file system for a few days, after it's flagged in the DB as "deleted". The file is not available via the web application and the system thinks it's gone, but it's still there under the hood on the file system.

Eventually a cron job cleans up the deleted files that have been there for X (say 3 days). The reason for this is that then a daily file system snapshot always includes all of the files added that day. If it was possible to add, then delete a file. Then a daily snapshot filesystem snapshot might not include a copy of the file.

Question: does Mahara "retain" deleted files on disk for awhile before deleting the files.

Or do the files get deleted straight away?

Ghada El-Zoghbi's profile picture
Posts: 122

24 May 2016, 20:58

Hi Andrew,

Apologies for the late reply.

I've had a look through the code and Mahara will delete a file right away. It doesn't retain it for a while before deleting like Moodle does.

If other artefacts point to it (say it's attached to one of your plans), it won't delete it immediately.

For your purpose, the daily file system snapshot will most likely not backup lone files that get deleted.





Kristina Hoeppner's profile picture
Posts: 4043

25 May 2016, 8:28

Hello Andrew,

I just added a wishlist item as a client asked us about trashbin functionality:




Dirk Meyer's profile picture
Posts: 425

26 May 2016, 8:58

I could never understand the rationale in Moodle for having deleted files stay around for a while. They certainly are not accessible by the students or teachers in Moodle. On top of that finding particular files in the dataroot is quite a puzzle as file names or course locations are not included in the actual files names.

A trash bin seems old school to me. I'd much rather see a snap shot type setup where  a user could manually create a snapshot (can already I suppose by creating backup) or automatically any number of snapshots so that a user can browse, perhaps by date, and see what their portfolio looked like at a certain point in time. Restoring select items from past snapshots would be a nice feature to go along with that.

Andrew Boag's profile picture
Posts: 2

26 May 2016, 11:49

Hi Dirk,

Firstly, some of the behavior of Moodle file deletion has changed in Moodle 3.1, but here is a brain dump around earlier versions of Moodle that we have been involved with.

One of the operational advantages in Moodle's file deletion behavior is around backup and restore policy for files i.e. reliably being able to restore an arbitrary file that has been uploaded into the Moodle application at some point in time. Even though this may well require some DB wrestling and a Moodle expert getting involved (not necessarily possible via GUI by Moodle admin or teacher).

This is to do with the way that many organisations like Universities take backup snapshots of applications like Moodle. They generally consist of:

  • Regular full database snapshots (better option is DB PITR but this is not always feasible)
  • Regular Full copies / snapshots of the "sitedata" filesystem component of the application - where all the Moodle files live.

Let's say a University takes full system backups of their Moodle every 6 hours, consider the following timeline:

NOTE: I'm not talking about Moodle course backups here. Full application backups are a different thing.

  • 6:00am - Moodle snapshot/backup taken
  • 8:15am - student uploads assignment submission Word file story.doc to Moodle course
  • 9:20am - student deletes Word file story.doc from Moodle course
  • 12:00pm - Moodle snapshot/backup taken
  • 13:00pm Uni decides that the need to restore story.doc that was submitted (even thought it was deleted). Perhaps plagiarism, offensive material, or student saying "I never deleted that file, I only submitted it, please check the logs."

If Moodle deleted the file completely at 9:20am then there is no copy to restore from system backups.

But Moodle instead:

  • flags the file as deleted in the database (meaning it's not visible or available in Moodle).
  • leaves the database record for the file with a "deleted" flag.
  • properly deletes the file from the file system via cron job after a few days (not sure of the exact number).

Ultimately, this a configurable behavior.

This is the background for the initial query here.

Anyway, enough about Moodle, this is a Mahara forum :-)

I agree with your thoughts that a trash bin is a bit old school, I'm not sure what the implementation/development implications are Mahara to build either a Trash Bin or Snapshots as you propose.

Let's see how the dev goes for Kristina's wishlist item.

Kristina Hoeppner's profile picture
Posts: 4043

26 May 2016, 13:30

Hello Dirk,

Good question around trashbin vs. snapshot. I think there may be a place for both. Consider this simple scenario:

A student creates a portfolio page which includes a folder with files and a reflection. The latter was created using a text box. The student deletes a file without carefully reading the pop-up window letting her know that it'll be gone from the page. She then goes into the page and makes changes to her reflection and adds a video.

It is only at the end of the editing that she notices that one of her files is missing. She goes to the trashbin and restores it.

A snapshot wouldn't work in this instance as the portfolio itself has already progressed after the deletion. It would only work if it is somehow possible to selectively restore items as you mention.

A trashbin might be an easier initial implementation or a quick way to access deleted content.

There is an initial patch from Nigel Cunningham at which starts the process of looking into timelines. Unfortunately, he hasn't had time to work on it since to progress it.




Jane Tracy's profile picture
Posts: 1

08 July 2020, 22:45

Hello Andrew

As far as I know this behavior is only seems to work with the old versions of Moodle and the support told me that it’s because you can change your mind and restore the  file after you have deleted it ( for a short period of time )

Here you will find fresh guide -

7 results