Moodle 2.x : Where are the .mbz files stored?

Moodle 2.x : Where are the .mbz files stored?

by Joe Cape -
Number of replies: 31
Picture of Plugin developers

I would like to know where the .mbz files are stored in the Moodle file system so that I can have a back-up on my own machine. Are they stored somewhere in 'Moodledata', or elsewhere?

Average of ratings: -
In reply to Joe Cape

Re: Moodle 2.x : Where are the .mbz files stored?

by SVI eSolutions -

I would also be curious to know where these are stored... Does anyone know or can anyone provide some information on this subject?!

In reply to SVI eSolutions

Re: Moodle 2.x : Where are the .mbz files stored?

by Colin Fraser -
Picture of Documentation writers Picture of Testers

This is a real mystery... but not unsolvable by anyone who seriously wants to look. The first place to look is in the database - yes, the database. This is a part of the general security improvements made to Moodle 2.x over the rather loose v1.x. What is different is the was in which the backup files are stored. The file is created, and stored then referred to in the database and given an alias id which is then matched to another number which is used by the file to display in the moodledata folder - somewhere. How this is done is a seriously nifty piece of coding, and it all means that unless you have the appropriate database keys, you will not be able to easily identify any files let alone the backup files.

Do you think it might be a good practice to download the backup files as soon as they are made. Do not leave them in the Moodle thinking they are safe, perhaps?    

In reply to Joe Cape

Re: Moodle 2.x : Where are the .mbz files stored?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
By default backups are stored in the same way as ordinary files. To cut a long story short - you cannot access them individually. They are (effectively) "hidden".

For scheduled backups (configured in the site administration) you can specify an alternative directory on you server (instead of or as well as) to receive the files. They will be stored as plain, old-fashioned files there. This is what you need if you want to backup the backup.

However, the conventional database and moodledata backups that I hope you are doing (!) should be sufficient to avoid against losing files in a system failure.

I do, though, continue to wonder with this new system what happens if your moodledata and database backups are taken slightly out of step (easily done).
Average of ratings: Useful (2)
In reply to Howard Miller

Re: Moodle 2.x : Where are the .mbz files stored?

by SVI eSolutions -

I am working on a project where we are changing Moodle somewhat in order to create scheduled courses or templates... Templates are basically backups that can be duplicated and given a start date.  This means that we are adding instances to where backups and restore processes can be accessed.  Basically if a tempate(a backup) is modifified, we want the old template to be deleted and replaced by the new one. This is easy to do in the DB but the original backups still exist as  they appear on the restore page.  Also as the user will be able to create a scheduled course from a tempalte we want to let them retore without having to pass by the restore page.  I have added a button so permit them to "schedule" their course but I can not seem to call the correct 'filename' to create the course.  The backupid fromt he DB is not the correct one...

Can anyone help?

Thanks

In reply to SVI eSolutions

Re: Moodle 2.x : Where are the .mbz files stored?

by Kim Park -

I've been reading on the forum for a bit now and realize that the backups are effectively "hidden", however I would like to be able to delete a backup on occasion.  I'm working to create a course template that I may then restore, as needed, to a new courses.  I've backed up a few iterations of this course and would like to be able to delete older .mbz files if possible as I no longer need them.

Is there a Moodle administrative interface option that will allow for deletion of these backup files?  Or other way that is not "risky" to get rid of these?

If there is another thread regarding deletion of .mbz files, I apologize and have not yet found it and would LOVE a link to it.

Thank you - Kim

In reply to Kim Park

Re: Moodle 2.x : Where are the .mbz files stored?

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Hi Kim, AFAIK, if you go to the Restore page of the course you want to delete the backup file from. Select "Manage backup files" you will come to the management page, right click the file you want to delete and select "Delete"  from the popup menu then it goes. Should work...smile

In reply to Colin Fraser

Re: Moodle 2.x : Where are the .mbz files stored?

by Kim Park -

Hello Colin,

Thank you for the reply.  When I am in the course, choose Restore and then Manage Backup files, I see the screen below...  Even though I have 2 backups of the course (one I'd like to delete), they do not appear in the Manage backup files window.  It appears I can only Add things here...  I was thinking that the backup files would be listed here, but they are not?? 

NOTE: I'm running Moodle 2.1+ (Build: 20110713)

I will restore this course to another category and delete the old course with the backups to resolve it I think, but would be nice to be able to delete backups within the course...

Manage Backup files image

In reply to Kim Park

Re: Moodle 2.x : Where are the .mbz files stored?

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Do you have a "user private back up area" that you can click on underneat the course backup area?

In reply to Kim Park

Re: Moodle 2.x : Where are the .mbz files stored?

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Mine looks like this. Check the breadcrumb of your course. I am in the Restore area of the course. This is what I am not seeing on your image, the three sections of th epage. Could you not be looking in the right place? 

Restore

 

Click on the last button and go to this page:

part 2

 

Average of ratings: Useful (1)
In reply to Colin Fraser

Re: Moodle 2.x : Where are the .mbz files stored?

by Kim Park -

Thanks to both of you, after seeing Mary's image, I realized that I actually had to Add the file I was wishing to Delete, which wasn't intuitive for me I guess? blush  Still getting used to new interface...  At any rate, I added the .mbz file and was able to delete it.  Thanks ever so much, I appreciate the help!

-Kim

Need to Add files to delete them

In reply to Howard Miller

Re: Moodle 2.x : Where are the .mbz files stored?

by sean lancaster -

I have spent about 20 minutes trying to figure this out and this discussion gets the closest to my issue. I had to move to a new hosting company. I backed up my Moodle 2.0.2 class and have Moodle 2.0.2 installed on the new host. I was able to restore 2 of my courses from my desktop. Great. The third course is larger than 2 MB and the system won't let me upload in the same way. So I have used FTP to get the mbz file into my Moodle folder, but I do not know where to place it so that find it using the File Picker (e.g., in Server files or Private files). Can someone guide me or point me somewhere with a solution? Thanks.

In reply to sean lancaster

Re: Moodle 2.x : Where are the .mbz files stored?

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

HI there. Actually, I don't think FTPing it into the Moodle folder like that will make it visible  in server files or private files to be able to access - you will probably need first to make a new folder and set up the file system repository - see here http://docs.moodle.org/20/en/File_system_repository

In reply to sean lancaster

Re: Moodle 2.x : Where are the .mbz files stored?

by Itamar Tzadok -

Afaict, not that simple and probably not possible. For restore purposes uploaded backups are not stored anywhere but rather extracted into a designated folder in moodledata/backup/temp. The designated folder is created specifically for that restore and should have a unique name which is used by the restore controller. You can't do that manually though because there is no way for you to tell the controller what the folder name is.

Online backups are handled by the file api and involve databasing and hashing so there is no way for you to simply upload the file such that the system will treat as a backup file.

smile

In reply to Itamar Tzadok

Re: Moodle 2.x : Where are the .mbz files stored?

by sean lancaster -

Well, that should save me a lot of time trying to do this using backup and restore then. I will instead copy each assignment, gradebook item, and course file over 1 at a time. Thanks.

 

EDIT: I can probably try and just remove the larger files and get the course down from 9.5 MB to just under 2 MB . . . and then my backup and restore system will work, so all is not completely lost. 

In reply to sean lancaster

Re: Moodle 2.x : Where are the .mbz files stored?

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Itamar -in your last post were you answering Sean's original FTP query or were you responding to my suggestion about using the file system repository? Because I would have thought that would work - except I haven't tried it and maybe you have!smile

In reply to Mary Cooch

Re: Moodle 2.x : Where are the .mbz files stored?

by Itamar Tzadok -

I replied to Sean's query, adding to your reply. My reply is qualified by 'afaict'. For this particular thing I don't yet have the user perspective. I just know what the code does. But of course there may be hooks for the user that I'm not aware of. I suppose your expectation is derived from the 1.9 behavior which attaches to every zip file a restore link. The 2.0 backup/restore system seems too specialized for such a naive restore link, but again everything is possible and there may be a hook there, and this should be fairly easy to check by creating a small backup, downloading it, uploading to any location in the file system and checking if it offers a restore option. smile

In reply to Itamar Tzadok

Re: Moodle 2.x : Where are the .mbz files stored?

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Ok..well, here's what I did:

* went to a course,clicked Restore and downloaded a backup to my desktop

*FTP'd it into a folder in my file system repository

*went back to a course, clicked "restore "and then "upload file" and from the filepicker chose my filesystem repository. It recognised, uploaded and successfully restored my backup course. (Caveat: it was only a small course, and I know Sean was wanting to FTP larger courses, but it is definitely worth trying.)

Average of ratings: Useful (4)
In reply to Mary Cooch

Re: Moodle 2.x : Where are the .mbz files stored?

by Carol Cooper-Taylor -
Hi Mary

So where in the Moodle file hierarchy is the my file system repository.

Thanks
In reply to Carol Cooper-Taylor

Re: Moodle 2.x : Where are the .mbz files stored?

by Carol Cooper-Taylor -
Hi

I am trying to restore a very large backup file from Moodle 1.9 into 2.1.1.

Where can I FTP the file so Moodle can see it when I do restore?

Thanks
In reply to Carol Cooper-Taylor

Re: Moodle 2.x : Where are the .mbz files stored?

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
In reply to Mary Cooch

Re: Moodle 2.x : Where are the .mbz files stored?

by Tim Burns -

This (repository functionality) is a beautiful thing. 

Just what Carol needed to upload .mbz moodle backups using an FTP session to a live Moodle site, and be able to easily find them to use to restore. 

I use FTP to sneak around php.ini max_file_size settings. Thanks Mary C. I owe you a beer! 

In reply to Mary Cooch

Re: Moodle 2.x : Where are the .mbz files stored?

by Jorge Rodriguez -

I had a problem uploading a course because the size of the mbz file was bigger than allowed by hosting on the php.ini settings (post_max_size).

I followed the steps of "File System Repository" provided above by Mary and I could upload the file and restore the mbz course.

Many thanks Mary. A great help!!

In reply to Mary Cooch

Re: Moodle 2.x : Where are the .mbz files stored?

by Chad Outten -
Picture of Testers

i can report Mary's suggestion also works nicely for larger courses ie. ~200M

In reply to Joe Cape

Re: Moodle 2.x : Where are the .mbz files stored?

by Alek Hartzog -

I have been working on this as well...I am running moodle 2.1 but would like to upgrade to 2.3

Rather than doing the on-server upgrade (which seems very challenging) I am looking at just starting a new Moodle 2.3 and copying everything in. This should be easy enough for my plugins and theme, but how can I export  1000+ courses and then import them into a new site?

So far I've been unable to get the automated course backup to actually give me the .mbz files in a specific directory as well.

Thank you for your assistance.

-Alek

In reply to Alek Hartzog

Re: Moodle 2.x : Where are the .mbz files stored?

by Rosario Carcò -

Davo explained to me here:

https://moodle.org/mod/forum/discuss.php?d=200616

And someone should test, if the backup-mbz files could also be stored in the file-systems-repository Mary talks about. If you can use it to upload a large mbz-file to restore later, it should also work in the opposite direction, to have all mbz-files stored there.

Rosario

In reply to Alek Hartzog

Re: Moodle 2.x : Where are the .mbz files stored?

by CoreDev Develop -

Hi Alex, 

Do you manage to solve your problem? I have similar situation with you. 

Best Regards,

Yulstar

In reply to CoreDev Develop

Re: Moodle 2.x : Where are the .mbz files stored?

by Mat Dydak -

I have followed Mary's tip of creating the repository.

Uploaded 115Mb large mbz file using ftp transfer protocol onto the server.

Restoration was successful.

max_

In reply to Joe Cape

Re: Moodle 2.x : Where are the .mbz files stored?

by Maite C -

I copy herewith the reply James gave in this site

How to find your .mbz file in moodle 2.x

The backdrop here is the need to move a .mbz file from one server to another.

When I browse to the course that I have backed up, and click restore, i see the backupfile area  for that course.  Right clicking the download link brings up a save as dialog that allows me to *copy the .mbz file to another server.

This works great EXCEPT WHEN THE .mbz file that is bigger than 100 MB.  If the file is larger than 100 MB (and believe me, I have made all the adjustments to the php.ini file) the browser crashes and does not allow me to move or copy the backup file.  I am dead in the water.  And since moodle 2.x hides files so well, its very difficult to find the actual .mbz file in the file system so you can copy it using the OS.

Today, I found this amazing post that detailed how to FIND THE .MBZ file in your filesystem. 

The highlights are this:

  1. Open the db and browse to the mdl_files table
  2. Find the name of the backup file in the mdl_files table in your DB. Look in thefilename field
  3. I filtered by filearea = 'backup' - reduced my file list from 70000 to 150.
  4. Find and copy the hashed name in the contenthash field.
  5. Browse to the server where your datafiles are stored (if not sure, look in the config.php file) - they will not be inside the webroot of the site.  I keep mine on a different drive, the F drive.
  6. Look for the moodledata\filedir (this is the secret location)
  7. Now search for the contenthash field value - that big long string.... there is a file hiding somewhere in the  moodledata\filedir filesystem.  FIND IT.

Mine was in two folders down like moodledata\filedir\xx\xx.

     8. Once you find it, you can copy it.

I copied mine to the server where I would be restoring and renamed it

     9.  Now you are ready to restore the file!

Wow, it restored the first time 100% correctly.   

Moral of the story?

You can find and copy and rename and restore a *hidden backupfile with a little perseverance.
Use the forums, sometimes people are golden! 

Average of ratings: Useful (2)
In reply to Joe Cape

Re: Moodle 2.x : Where are the .mbz files stored?

by Daniel Klein -

Just like any other file Moodle stores, the backup files are stored in moodledata/filedir/{dir1}/{dir2}/ where {dir1} and {dir2} are the first two and the next two characters of the hash of the file. A hash is a seemly random sequence of letters and numbers so you can't tell just from the file name which is the file you're after. Your hashed file name might start with 83b99e... so in this case {dir1} would be 83 and {dir2} would be b9.

However, there are two things you can look for (without digging in the database) that will help you guess which is the file you're after: the time stamp and the file size.

Moodle backup files are usually large, anywhere from a few hundred kB to well over 10MB. If you know when the backup file was created you can use that to narrow down your search too. If your file is the only file in its directory then the directory will have the same time stamp too so that might save you having to look through all the directories.

Once you think you have downloaded the correct file you can check it by opening it in a ZIP extraction program.

There is a lot of inspired guesswork in this method, so it might take a while for you to find the right file, however, it is not impossible and depending on your circumstances can often be done quickly.