recovery of accidentally deleted courses (v.2.2.6)

Re: recovery of accidentally deleted courses (v.2.2.6)

by Chris Collman -
Number of replies: 12
Picture of Documentation writers

Thanks Sue, Ken and Emma for helping me think of another way.

I am on 2.13.  I do have a 500MB backup of the course I accidentally  deleted on my computer(another story see below).  I am moving it to one of my repositories and as I type restoring my deleted course from there.  My max upload size is 100 MB.  

I know some people can not change max file size but do have an FTP program, so this might work for them.  I think with newer versions you can drag and drop files like Sue described above smile

For those who want to learn what happened and a  trick if you are quick,  here a longer  story:

Yesterday morning I was moving courses around in the course management menu system and decided to hide one.  Must have been asleep because I clicked on the X right next to the open eye, and then automatically clicked OK before I realized  it was the DELETE OK button andd not the OK to move resource I had been doing the previous hour.  I frantically hit the cancel button many times.  I had other backups but not for this course on my computer.  

The trick: I was using Firefox and left it open showing something was processing.  I opened a Chrome browser and was able to get into the course and tell it to download the most recent automatic backup.   I got lucky because 45 minutes later I had a 500 MB.mbz file on my computer.   And when I checked later the course was no longer listed.  As  usual it another 45 minutes to FTP it back to Moodle and more than an hour to restore (I left it running all night).  That was definitely dodging the bullet. 

 I still curse the "new" file system at times like these but that is progress. However, I still remember 1.5 and when I did a lot of edits in docs.moodle with a quill pensmile  I am 90 minutes from the server and don't like Putty.  However I think I better change the max file size to 900MB, next week when the students are gone.   AND MAKE SURE I HAVE  BACKUPS EVERY COURSE OFF SITE (ie on this computer).  We only run a total of  10 courses a year so it is not that  big a deal.

Ken and Emma: I was not looking forward to downloading a bunch of trash files.  I had  a 20 folders with a subfolder containing a file and no quick way to determine what was what. I will re-read Ken's words.  Once I downloaded the backup, I found the only file in trash that had a file of exactly the size of the backup, dated today.   

Another victory for a forum!!!!


In reply to Chris Collman

Re: recovery of accidentally deleted courses (v.2.2.6)

by Kim Solis -

This forum is really great except I just don't get the code talk.  I am sorry, I am new at this and I am the administrator for our site, but I am flying by the seat of my pants trying to learn as I go.  (I desperately need formal training but we just don't have the money for it as we are non-profit learning institution.)  Anyway... I cannot find our moodledata/trashdir directory.  I put in the name of our site www.cursosilebtoluca.org and then did /moodledata/trashdir and it said that the page could not be found.  Is there another way to find it?  I really need to recover a deleted course.  I also went back through my log and cannot find any time where it shows it was deleted.  Is there a site log and not just my private user log? 

And then saying I can locate the trash directory, I don't really understand what to do after that.

I need a handbook Moodle Administration for Dummies!!! 

THanks so much! smile


In reply to Kim Solis

Re: recovery of accidentally deleted courses (v.2.2.6)

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

So firstly, you have reactivated a two year old post which probably doesn't help too much.  On your server, you will have a moodle folder where the code is located and a moodledata folder which contains all the content.  It is in the moodledata that you will find the trashdir folder.  You are not going to find through the web site - you need to actually get on the server where the site is installed.

Average of ratings: Useful (1)
In reply to Emma Richardson

Re: recovery of accidentally deleted courses (v.2.2.6)

by Matt Sullivan -
Many thanks to you and to Ken for this thread. Yours was short and accurate, while aken supplied some of the details I needed to find a 71Mb course in my trashdir. 


For the sake of those in 3.0, my trashdir was in data, not moodledata,  and the file date was approximately the date I deleted the course.

Because I deleted the course 6 weeks before I went to restore it, I had to go into the backups of the www directory on my ISP and get the archive that hadn't yet purged the large trash file.

***It took me 2 days of research to track down his thread, but it still saved me days of rework, and ensured that 6 weeks of Moodle course tweaks didn't get lost. While I still had my recordings and file assets, the only other Moodle backup I had was a skeleton outline with less than 10% of pages/assets added to the course.***


LESSON LEARNED: Backup and download .mbz to a secure location on a regular basis.

Average of ratings: Useful (1)
In reply to Matt Sullivan

Re: recovery of accidentally deleted courses (v.2.2.6)

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

LESSON LEARNED: Backup and download .mbz to a secure location on a regular basis.

A lesson that most people learn just after deleting something (myself included) smile


In reply to Marcus Green

Re: recovery of accidentally deleted courses (v.2.2.6)

by Matt Sullivan -

Am I correct in my theory that the deletion of the course deleted the backup as well?

Or is the backup not stored on the site and needs to be manually downloaded at time of backup?

In reply to Matt Sullivan

Re: recovery of accidentally deleted courses (v.2.2.6)

by Ken Task -
Picture of Particularly helpful Moodlers

From what I understand (which may/may not be accurate with 2.2.6 now as that is old) IF a course is hidden and there is a backup in private files/course backups/automated backups that means there is a link from the course to that file and thus the file would never be sent to trashdir.  Hiding courses doesn't regain any free space ... matter of fact, quite the opposite.

If a course was deleted and that backup file is no longer seen in private files or other areas, or even other courses eventually, the backup file is moved to the trashdir and removed from the system.

The only way to regain space is to remove/erase.  And unless you manually remove contents of trashdir the space gained won't 'show up' until cron/task jobs empties the trash (4 days time from when a file was moved into trashdir).

'spirit of sharing', Ken


In reply to Ken Task

Re: recovery of accidentally deleted courses (v.2.2.6)

by Matt Sullivan -

Thanks Ken, 


That jibes with what I saw: Upon deletion of the course, (what I now understand to be) the backup file was moved to the trashdir.

Fortunately, I was able to recover the trashdir from a system backup that occured in the interval between deletion of the course and before the cron emptied the trash.

Am I understanding that correctly?


Either way, I'll now be somehow disabling the course, rather than deleting it.
For a course that likely runs once per quarter, what's my best approach for shutting down a session and then starting another?

In reply to Matt Sullivan

Re: recovery of accidentally deleted courses (v.2.2.6)

by Ken Task -
Picture of Particularly helpful Moodlers

Now we're off into areas that only you can answer for yourself cause not everyone's situation is the same.

Obviously, you don't want to have to do what you did to recover a backup.

Here's what I might do if I wasn't under a records retention policy or something like that ...

Full backup of the course ... including students enrolled and their work.

Download that backup to archive it ... I can restore that course if needed.

Do another backup this time with no users no data from users, etc.   It's a course shell with the activities/links, etc. in it.

Download that backup for archiving purposes.

After doing both of those, delete the backups found by going to restore in the course.

Now reset the course.   Choose options to remove all students, their data, their forum postings, their files, their grades, etc.   It then becomes like it was before you allowed students to enroll.

Some catch 22's ... iF the full/user backup you've downloaded to archive is larger than the limits to upload, can't use it until upload limits increased.   On some shared remotely hosted situations you don't control that limit.    There's a CAP.   Probably only option is to upgrade the package ... shared hosting to VPS.

The same could be true of the no user backup you downloaded.

See what I mean? smile

'spirit of sharing', Ken


In reply to Ken Task

Re: recovery of accidentally deleted courses (v.2.2.6)

by Matt Sullivan -

Excellent, thank you!

Yes, I already had to track down the php.ini settings with the help of my hosting company. They lock out direct access to php.ini (where, as you know, the upload and post limits are set) but allow a GUI where I was able to set upload to appropriate size.

In reply to Kim Solis

Re: recovery of accidentally deleted courses (v.2.2.6)

by Ken Task -
Picture of Particularly helpful Moodlers

Once you find where the moodle code is located, check the config.php file for the path to your moodledata directory.

That's where Moodle stores files ... including backups.   However, much has changed from 1.9 and one of those changes *IS* Moodles file system.   No longer is there /pathto/moodledata/#/ directories where # is the course ID of a course.  In 2.x and beyond backups files could be in /pathto/moodledata/filedir/ *but* they are not in humanly recognizable names ... like 'backup....blah-blah-blah.zip'.   One has to use the mdl_files table looking for backups to see their names AND use the contenthash to determine actual location in filedir.

A DB query like:

select contenthash,userid,filename from mdl_files where filename like "%.mbz%";

Will show something like the following:

+------------------------------------------+--------+-------------------------------------------------------------------+
| contenthash                              | userid | filename                                                          |
+------------------------------------------+--------+-------------------------------------------------------------------+
| f349a6cf359f9ff6cc95125c5835e28b13f9e6d7 |     99 | backup-moodle2-course-64-kerlegon_chemistry-20130611-1045-nu.mbz  |

If you have PHPMyAdmin ... or any tool that allows you to search the DB, use that.

The user ID will be the user that created the backup ... more than likely the teacher.

The content hash ... if one deciphers it shows the location of the backup file:

In the example above:

moodledata/filedir/f3/49/ there is located a f349a6cf359f9ff6cc95125c5835e28b13f9e6d7 file which is really:

backup-moodle2-course-64-kerlegon_chemistry-20130611-1045-nu.mbz

Sorry, not sure there is a dummies book for this!

'spriit of sharing', Ken

In reply to Ken Task

Re: recovery of accidentally deleted courses (v.2.2.6)

by Ken Task -
Picture of Particularly helpful Moodlers

Follow up .... IF you do the following *before* the cron job empties files in /moodledata/trashdir/ .. you could recover a deleted backup of a course.

Am showing command line ... use whatever tool you have to browse files on your server.   This assumes you have located moodledata directory (again, path to which is found in config.php file of your moodle code directory.

cd /pathto/moodledata/trashdir

ls -lR (this will show all directories/files in trashdir

Might be a long list (depending), but what one is looking for is date (which would be/should be the date the deletion was made), and file size.

Here's an example (the paths probably do NOT exist on your server ... remember this is an example).  [ENTER] is not part of the command but indicates where/when you press the ENTER key on your keyboard.

[root@moodle trashdir]# pwd [ENTER] (shows what directory am located in)
/mnt/data/hs2moodledata/trashdir

ls -lR [ENTER]

Displays something like this:
[root@moodle trashdir]# ls -lR
.:
total 4
drwxrwxrwx 3 apache apache 4096 Jul  1 19:46 bf

./bf:
total 4
drwxrwxrwx 2 apache apache 4096 Jul  1 19:46 51

./bf/51:
total 1772380
-rw-rw-rw- 1 apache apache 1813139102 Mar  5 14:33 bf51f6c603ccf47ec3d1e1f6d7364cc9b370d375

The backup file that was just deleted (it was first created in Mar of this year) is in:

moodledata/trashdir/bf/51/

and it's name is: bf51f6c603ccf47ec3d1e1f6d7364cc9b370d375

One could copy that file out to another location and rename it on the fly:

[root@moodle trashdir]# pwd
/mnt/data/hs2moodledata/trashdir
[root@moodle trashdir]# cd bf/51/
[root@moodle 51]# ls -l
total 1772380
-rw-rw-rw- 1 apache apache 1813139102 Mar  5 14:33 bf51f6c603ccf47ec3d1e1f6d7364cc9b370d375

mv bf51f6c603ccf47ec3d1e1f6d7364cc9b370d375 /home/myhomedir/somebackup.mbz

'somebackup.mbz' is now a file name that the restore process will recognize.

You could do the command line things with whatever you have to browse files.

If you can't do this, contact hosting provider's helpdesk and ask for assistance.  Send them the link to this forum and this thread.

'spirit of sharing', Ken