How to get .mbz files directly from the server (if possible)

How to get .mbz files directly from the server (if possible)

by Gaston Ribot -
Number of replies: 7

Hi guys, I really need some help, I have access to a physical dell powerconnect r420 server that had an old version of Moodle (possibly 2.x) running in Ubuntu 22.04 but has been discontinued, it seems Moodle was not removed from the server along with mysql, php and so on, the problem is that we don't have access through the web browser, therefore we cannot rescue the courses or the backups directly from there, so I'm here stuck with the CLI, not knowing what to do or where to find the files related to the courses and backups. So, is there any way to rescue the .mbz files directly from the server so I can just upload them to our new server? and if not, is there a way to compile all the files related to the different courses we had inside this old server? I ask this because I saw a response in another discussion that was:

Where does Moodle store the courses on mysql which table ?


where someone responded:

"As I understand it, Moodle does not store an entire course in the database, only metadata and other elements about the course. Attached files are located in the Moodledata folder and connected with an encrypted link. Courses are broken into several elements and stored in different parts of the database. Questions are held in the quiz table, activities in the respective activity tables blocks and so on"


I would like to know if the .mbz or an entire course can be retrieved from the server by the cli and also where it is stored, if they are stored in a default directory in moodle or in one of the directories that the administrator may have created. Thank you.

Average of ratings: -
In reply to Gaston Ribot

Re: How to get .mbz files directly from the server (if possible)

by Ken Task -
Picture of Particularly helpful Moodlers

Lucky you!   Happen to be working on this very thing!

bash shell scripts in moodledata/filedir/

Queries to find .mbz files from mdl_files table of DB and contenthash of all .mbz files.

use yourDBname in below
password you put between the ticks .... 'password'.

bash shell script

getbackupfiles

mysql -u root -p'' -e "use moodle;select id,userid,filename,filearea,filesize,component,contenthash from mdl_files where filename like '%.mbz';" > mbzfiles.txt; cat mbzfiles.txt;wc -l mbzfiles.txt
mysql -u root -p'' -e "use moodle;select contenthash from mdl_files where filename like '%.mbz';" > mbzcontenthash.txt; cat mbzcontenthash.txt;wc -l mbzcontenthash.txt

To find the paths ... another script ...

findfiles

#!/bin/bash
#
for i in `cat ./mbzcontenthash.txt`
do
    echo 'Path in que:' $i;
find -name $i >> ffiles.txt;
done
echo 'Done.';

ffiles.txt will show the paths /xx/yy/xxyybunchofletersnumbers

You can check type of file:

file -b /xx/yy/xxyybunchofletersnumbers

should show it's a gzip.

Then the trick is to copy the /xx/yy/xxyybunchofletersnumbers file out to another
directory AND, at the same time, rename the file into how it's seen in the GUI
(haven't gotten that far yet)

Above offered as is so check for 'correctness', typos and adjust to 'taste' ... etc.

When finished, remove the .txt files that were created, but you can leave the scripts in case you need to do again ... or could copy scripts and rename for doctype ... like all .docx files.

'SoS', Ken


In reply to Gaston Ribot

Re: How to get .mbz files directly from the server (if possible)

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Are you sure, you want only the mbz files, means you want to restore the site course-by-course? In case you want to preserver user data, like their forum posts, uploaded files, do you know that those backups contain the said user data?

Faced with this situation, I would try to get a https://docs.moodle.org/en/Site_backup from the broken server and then https://docs.moodle.org/en/Site_restore it in a healthy one. I don't know whether it is feasible in your case - depends on how broken the old site is.

In reply to Visvanath Ratnaweera

Re: How to get .mbz files directly from the server (if possible)

by Gaston Ribot -
Hi, yea I want the old .mbz files that were created in the old server so I can upload them in our new server from the site admin, but I can only do it through the cli
In reply to Gaston Ribot

Re: How to get .mbz files directly from the server (if possible)

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Ha, ha, ha! CLI is the last resort for some, first resort for the others.

Seriously, since your Moodle is dead, you are without the GUI. Means the comfort of tools like the on Dan mentioned are out. I think, Ken explained the CLI procedure. I assume, you only concern is the content, not the user data. I imagine scraping user data from mbz to be cumbersome.
In reply to Gaston Ribot

Re: How to get .mbz files directly from the server (if possible)

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I have to do this all the time to transfer backups between servers. It's a pain. It's actually on my "to do" list to write some sort of plugin to automate it.
Average of ratings:Useful (1)
In reply to Gaston Ribot

Re: How to get .mbz files directly from the server (if possible)

by Ken Task -
Picture of Particularly helpful Moodlers

There are some 'catch 22's' to extracting .mbz's and using them on another server.

If you see 'nu' in backup filename - that means no users.  No assignments/quiz scores, forum post, etc.   Just a shell course.   That could be good due to conflicts with user roles a full backup might present.  In which case, one has to edit user.xml from extracted backup then rebuild the .mbz to restore.   So even if one gets a .mbz might not be able to use it in restoring to another server - depends.

The backups use the site preferences for backups ... and if you can't login to change that, then you get what you get.  Fun and games! (ugh!)

Then there are third party plugins that were on the old site, but not on the new.  More 'fun and games' (double ugh!).

If you have many to do ... a lot of work - some of that 'guess work'!!

'SoS', Ken