Data loss during filedir syncrohization

Data loss during filedir syncrohization

by Joel Mendoza -
Number of replies: 3
Hi guys, just looking for help if exists since today was trying to sync my filedir folder (not the whole moodledata) to a Google Drive using rclone tool but unfortunately the process was suddendly aborted and once restarted a huge amount of files are now absent from my server. I can't calculate the exact number but when access to any course I can see images and labels, but none resource is accessible (SCORM, videos, etc.). 
The only backup I had was actually from the initial installation because after that, disk space was too limited to allow new backups in server. A lot of bad practices were done and now I try to get some help. Let me try to explain the whole process to give you more details:

I setup rclone to have a backup of my server available in Google Drive. Started copying filedir to Google Drive and after some time had an electricity shortage and process was stopped. When electricity was restored I restarted the process but this time by sync instead of copy, and didn't notice that destination and source were switched, meaning my filedir was trying to take information from GDrive. This process was also stopped, error messages appeared telling that MD5 was not matching. At the same time my moodle installation folder was also copied from server to another folder in GDrive, by that moment noticed that can access the platform but resources started being unavailable. I never rebooted server during the process and what have now are folders partially moved to GDrive and missed information in server. OS is CentOS.

This is what I get from php log:

PHP Warning:  readfile(/home/moodledata/filedir/...): failed to open stream: No such file or directory in /home/path_to_moodle/lib/filelib.php on line 1942



Thank you for any advise.
Average of ratings: -
In reply to Joel Mendoza

Re: Data loss during filedir syncrohization

by Ken Task -
Picture of Particularly helpful Moodlers
Where are you hosted?   Sometimes hosting providers make site backups of customer accounts/servers.   Check with them.
If they don't have/offer such a service then ....

Since you mixed rclone and rsync and on the later had the opposite of what you
should have had in source destination, am not sure of what you have ... if much at all.
Might share what your rsync command looked like from your history?

At least your DB wasn't touched ... or was it?
Did you make any course backups?

getbackups bash shell script:

mysql -u [user] -p'[password]' -e "use [dbname];select contenthash,filename,filearea,filesize,timemodified from mdl_files where filename like '%.mbz' order by filesize DESC;" > backups.txt; cat backups.txt;wc -l backups.txt

Output of above will look something like the following clip:

userid    contenthash    filename    filearea    filesize    timemodified

2220    6a3b5bd690feff0c4ca5c8dbbad7077aeb198317    RUSH.moodlebackup.mbz    backup    2708678287    1591221647

14    3f90c84e70101e8ce412d03a08ba83eb92f3a5f4    backup-moodle2-course-99-geo-20190530-0952-nu.mbz    backup    2446141378    1559228171

6896    6aa43848d139263bc79cf71d7a955079ede1d8c2    backup-moodle2-course-126-algebra_1-20150529-1151-nu.mbz    backup    2154026223    1432918591

You could adjust the script to search for and list SCORMS ... all SCORMS are zips.
so rather than '%.mbz' you could do '%.zip' and change the text file from backups.txt to zips.txt

Ditto for videos you uploaded ... all .mp4's?
Change variables for .mp4 and text file to videos.txt

The contenthash values are both the names of the files plus location in filedir.
So taking the first example above:
6a3b5bd690feff0c4ca5c8dbbad7077aeb198317
is in moodledata/filedir/6a/3b/ and the filename is the contenthash value
6a3b5bd690feff0c4ca5c8dbbad7077aeb198317

So to see if that backup file can be copied out of what is remaining in moodledata/filedir:

Again using the example:

From a location where you can see moodledata issuing ls command:

cp moodledata/filedir/6a/3b/6a3b5bd690feff0c4ca5c8dbbad7077aeb198317 /root/RUSH.moodlebackup.mbz

If the cp command fails and tells you file isn't there, it probably isn't!   Can't recreate something that is no longer! sad

Think it would be a technical miracle if you could recover it all.
You might have to settle for what you can get! sad

And then rebuild your entire site content.

Good luck!
'SoS', Ken

In reply to Ken Task

Re: Data loss during filedir syncrohization

by Joel Mendoza -
Thanks a lot for help Ken. Yes, DB was untouched. I've followed your instructions and get the following outomes:

9 backups.txt, 362 videos.txt, 25 SCORM.txt

I got a little lost in the last part of your message, starting from here:

"...So to see if that backup file can be copied out of what is remaining in moodledata/filedir:..."

How can I know which course is linked to which resource in order to try copy out?
BTW, is there any way to create a report containing the list of courses and each filename/contenthash used on it? Like an inventory for me to start the whole process to find/restore missing information.

Thanks.
In reply to Joel Mendoza

Re: Data loss during filedir syncrohization

by Ken Task -
Picture of Particularly helpful Moodlers
How many courses did the site have?

select id,category,fullname,shortname,visible,format from mdl_course;

Note: above would also show how many  categories you had!
Their names and attributes found by making a query of
mdl_categories.

Your best bet for recovering courses are the .mbz backups of courses.  How old those backups are a factor.  If you left course backup options at defaults, the course backups recovered would include users.   The backup file name a hint ... if you do NOT see 'nu' (no user) in the file name, the .mbz file included users and their work in that course.  And the backup file name tells you the short name of the course.

The others: 362 videos.txt, 25 SCORM.txt
would recover only those individual resources used in courses, but wouldn't tell you what course they were in.  At this point, don't think I'd be 'picky' ... and like I said, you might have to rebuild the entire site starting with a fresh install of a Moodle! sad

explain mdl_files;
shows columns contained in mdl_files table.
That's what you have to work with.

You might be able to find what you seek @

or at least what a complicated query would look like for you to adjust seeking what you want.

Am not good at recovering a 'train wreck'!   Sorry 'bout that!  You are gonna have to dig ... a lot! sad  And by the time you finish this recovery project, you'll know more about how moodle works ... and doesn't work!   So there is the good and the bad with this!

'SoS', Ken