[3.7] Extract course backup files from moodledata

[3.7] Extract course backup files from moodledata

by Marius S -
Number of replies: 3

Hello,

We have automated backups turned on and it creates course backup files in moodledata+external directory.
We also backup moodledata on server level, so we can access older files.

We need to restore one course but we keep automated backups only for few weeks. However we have moodledata backup and automated backup should be created there.

My question is it possible somehow to extract course backup file/files from moodledata folder?
I see that filenames in moodledata are encrypted, but maybe there is a way to know which file is needed, download it, rename it and restore?

Thanks,
M.

Average of ratings: -
In reply to Marius S

Re: [3.7] Extract course backup files from moodledata

by Ken Task -
Picture of Particularly helpful Moodlers

Have you searched Moodle plugins?

https://moodle.org/plugins/index.php?q=backup

https://moodle.org/plugins/index.php?q=restore

Does visiting a course and pretending to restore show you what you seek?

As far as extracting just .mbz files from moodledata/filedir/ individually or in mass ... yes it's possible, but it would involve db query of mdl_files table to find .mbz files (names and locations - location is the contenthash) then copying those .mbz files to another file system location so they can be seen by Moodle interface for restoring.   No GUI/plugin for that but I do have some cli scripts (a combo of bash shell scripts and .php files that uses xmlint) that currently extracts files from a .mbz file which you could adjust to work with server/moodledata/filedir/ ...

Moosh might have something useful for ya:

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

I imagine this could be massive ... depending.   One would want to have plenty of drive space available me thinks.

'SoS', Ken

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

Re: [3.7] Extract course backup files from moodledata

by Marius S -
Hello Ken,
As I understand contenthash ir encoded. So how I could seach for .mbz file?
Our .mbz file names are backup_moodle2_course-courseid-coursecode-yyyymmdd-hhmm.mbz

Do I need to "decode" the contenthash or I could perform a search?
I am using Adminer (similar to phpmyadmin) to browse database.

Thanks,
Marius.
In reply to Marius S

Re: [3.7] Extract course backup files from moodledata

by Ken Task -
Picture of Particularly helpful Moodlers

contenthash is really the location of the file.

select contenthash,filearea,filename,filesize from `mdl_files` where filename like "%.mbz%" order by filesize DESC

is meta data and will return rows like:

496b7ed2c090160c8d955887f7834c244e8e492b     course     backup-moodle2-course-593-dim-20200522-1149.mbz     30168358282

The contenthash: 496b7ed2c090160c8d955887f7834c244e8e492b

is the location of the file in moodledata/filedir/ and filename ... no humanly recognizable filenames in /moodledata/filedir/

moodledata/filedir/49/6b/496b7ed2c090160c8d955887f7834c244e8e492b

From command line on Linux one could use file -b on that file to see it's mimetype.

'SoS', Ken

Average of ratings: Useful (2)