HELP: Backup an unreleated course is restoring previous activities in other courses!

HELP: Backup an unreleated course is restoring previous activities in other courses!

by Andrew Normore -
Number of replies: 15

Hi Moodlers, I have a very bad situation! Moodle 2.4 and 2.7 both exhibit the same behaviors... SOME TIMES.

I cannot repeat the problem on demand, but this is the occurrence:

Changes are made to Course-A: Let's update a page from "Hello World" to "Goodbye Moon"

Backup of Course-B, restored as Course-C

Check back to Course-A: "Goodbye Moon" has now reverted back to "Hello World"


Is it possible we have a server configuration issue? Too much traffic (We have the largest intake in quite some time right now). 

Caching? (I've cleared it all)

File permissions?

Moodle bug?


ANY help is greatly appreciated.


Average of ratings: -
In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

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

I don't suppose you have misconfigured your sites and they are using the same moodledata folder?  

You say you cleared caches - you might try manually deleting cache and localcache folders from moodledata folder.  Also clearing caches in your browser.

In reply to Emma Richardson

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Andrew Normore -

Thanks Emma, 

We did have the 5 Moodle installs using the same MySQL user/password. We've updated that now, maybe that's where a wire gets crossed... 

Good call on manually deleting the cache, I've had a weird problem with this before, yeah.

I'll double check Moodledata locations as well. 

We've tried browser cache.


I can see for example, mdl_book_chapter id 123123 content IS being updated by MySQL when the backup runs from another location.

In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Ken Task -
Picture of Particularly helpful Moodlers

Each moodle instance needs separate code, separate moodle data dir, and especially a different DB (DB user/pass could be the same).    So when you check out the config.php files make sure each site is using a different DB.

Emma would have told ya that ... I just happened along! ;)

'spirit of sharing', Ken


In reply to Ken Task

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Andrew Normore -

Yes, but, does Moodle really require a separate DB user for each install? I've never seen this cause issues before.

Do you think it's possible? Does moodle have some sort of global write in the backup restore functions? 

We ARE seeing this behavior cross site. I wonder if there are crossed reference ID's and Moodle gets confused, because it is global.


I have updated our system to have unique users DB. Let's see if the problem goes away... Thanks Ken. You're the Moodle Guru!

In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Ken Task -
Picture of Particularly helpful Moodlers

Run servers with several moodle installs using the same DB server.   Since I'm the only one via command line, I do sometimes use only ONE DB moodle user to access the various instances databases.

User: moodleuser

Has access rights to moodleADB, moodleBDB, and moodleCDB.

Each Moodle should have separate code, DB, and data directories.

Moodle A:  code: /var/www/html/moodlea/   data: /var/www/moodleAdata DB: moodleA

Moodle B: code /var/www/html/moodleb/  data: /var/www/moodleBdata  DB: moodleB

Changes in Moodle A are NOT reflected in Moodle B.

Now if I had mistakenly set the database for Moodle B to the database for Moodle A, then yes, there would be some behavoir such as you have described.

Check each sites config.php file for DB host, DB name.

'spirit of sharing', Ken


In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Ken Task -
Picture of Particularly helpful Moodlers

Just thought of a config that might exhibit that behavior.

2 sites ... Moodle A, Moodle B

Moodle A installed first and used the 'defaults' for the database setup ... db name moodle **prefix mdl_**

Moodle B installed second or later and attempted to use the defaults for database setup but may have found issues in installing.   As a 'work around', installer used the same db name (moodle) but a different prefix ... mdlB_

The same DB user and DB password could have been used in both instances.  And that would not cause any changing of data in tables by itself ... it's just an authorization thing and what priveleges - alter, etc.

So ... don't have sites/DB's set up that way to test things ... but if you have some sort of tool to work with DB's (think phpmyadmin could do this for sure), select a database ... then show tables.

Show tables should have/show the prefix in front of the table names.

'spirit of sharing', Ken

In reply to Ken Task

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Andrew Normore -
Hey that's not a bad idea!


I'll go ahead and change the prefixes as well. Complete separation in possible ways. We have some external stuff that runs some times too. There's no way to pin this down. So bandaid and workaround until it resolves itself. Thanks for the thought!

In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Ken Task -
Picture of Particularly helpful Moodlers

*** NO! *** don't change prefixes!!!!  Changing prefixes to a database involves a lot more than just changing the line in the config.php file of a moodle site.

Check the config.php files of all the instances.

Check DB name ... they all should be different database names.

It's perfectly fine for different databases to have the same prefix.

Here's site that has several Moodles - note each has a different database name:

[root@sos html]# fgrep 'dbname' ./moodle*/config.php
./moodle27/config.php:$CFG->dbname    = 'moodle27';
./moodle30/config.php:$CFG->dbname    = 'moodle30';
./moodle31/config.php:$CFG->dbname    = 'moodle31';
./moodle32/config.php:$CFG->dbname    = 'moodle32';
./moodle33/config.php:$CFG->dbname    = 'moodle33';

but their prefixs are all the same:

[root@sos html]# fgrep 'prefix' ./moodle*/config.php
./moodle27/config.php:$CFG->prefix    = 'mdl_';
./moodle30/config.php:$CFG->prefix    = 'mdl_';
./moodle31/config.php:$CFG->prefix    = 'mdl_';
./moodle32/config.php:$CFG->prefix    = 'mdl_';
./moodle33/config.php:$CFG->prefix    = 'mdl_';

I told you to check the databases with 'show tables' from a db client.   Check the output of the following mysql command to see if there are any tables that have a different prefix:

Examples:

mysql> use moodle33;

mysql> show tables;

That will scroll and finally stop to return you to the mysql prompt and above you will see something like (maybe not exactly - something like):

| mdl_workshopallocation_scheduled |
| mdl_workshopeval_best_settings   |
| mdl_workshopform_accumulative    |
| mdl_workshopform_comments        |
| mdl_workshopform_numerrors       |
| mdl_workshopform_numerrors_map   |
| mdl_workshopform_rubric          |
| mdl_workshopform_rubric_config   |
| mdl_workshopform_rubric_levels   |
+----------------------------------+
381 rows in set (0.00 sec)

See the mdl_ in front of the table names .... that's the prefix.

Do that for each database for each moodle instance.

Please don't jump at what's suggested you check out.   Check it out first!!!!

I hope you've started working this out by backing up databases - even if there might be something wrong in them right now.   We need to attempt to resolve the reason ... rather than taking a sledge hammer approach it might require something more like a finishing hammar.

Mind you  ... not that I would know exactly what to do, cause I've never heard of the situation you've desribed.

'spirit of sharing', Ken




In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

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

That is just so strange.  It was screaming cache to me but if you can actually see things being updated, there about has to be something funky going on in the database somewhere.  

As Ken mentioned, make sure that you don't have two sites accessing same database. I would also check that the user referenced in config.php has the appropriate permissions...

Is the database on the same server as the moodle code and moodledata?  Could there be some network deal going on where the database is disconnecting sometimes?  How are you performing the backups?  Through the gui or through cli?

In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Ken Task -
Picture of Particularly helpful Moodlers

Just how are you seeing that mod_chapter thang is being changed when 'backup runs at another location'?

Am not understanding ...

Backups don't change content.   So is it the 2.4 version 'backup' that's showing/doing something in the 2.7 instance database?  Or vice-versa 2.7 -> 2.4?

What sort of additional plugins do you have installed that could cause interaction between Moodle instances?

In the one example you give, is the mod_book_chapter ID XXXX resource available in say Moodle A ... and someone copied a url to that mod_book and used the URL in Moodle B?

Are both of those instances using the same authentications or some sort of authentication where by moodle user X logs into the 2.4 and they are also logged onto the 2.7?

Comment: but don't upgrade yet .... both versions you are running now are quite old and haven't gotten any fixes to code nor security updates in a while now.  Suggest that after this current issue is at least known as to how/why it is happening, that both instances be brought upwards to a supported version. 

How about some specific technical info ... we know version numbers of the Moodle's involved ... what about other stuff ... Operating System is?   Hosted how and where?  PHP version?   MySQL version ... etc.


'spirit of sharing', Ken


In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Andrew Normore -

Hello everyone, and thank you SO MUCH for your assistance.

It has been the entire weekend, and two work days, with out any reports of incident!

It appears that using individual database accounts has solved the issue. So in a way, this is sort of related to caching, which makes sense. I think some inserts were being triggered from other sites, that HAPPEN to have matching ID's in some SQL statements. This is why we cannot reproduce the bug.

So if you just follow STANDARD MOODLE INSTALL INSTRUCTIONS you can avoid problems like this. 

... and now we know.

I'll report back if we are still experiencing problems, cheers, and thank you again!

In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Andrew Normore -

I got a message this morning, old content that was deleted from a course is now back. sad

Back to the drawing board.

In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

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

Have you been through Ken's response - have you check the names of the databases?  And then the config.php files in the Moodle installations?

Is this just happening with one course?  i.e. Is only a single course getting the content put back?  

In reply to Emma Richardson

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Andrew Normore -

Yeah I've checked through all the config settings, it's pretty straight forward. Been doing it for over a decade... 

It's occurring from 2 different Moodle installs, when a restore function runs.


I think I have no choice but to get down and dirty, and go through all the restore code and breakpoint all SQL writes. 

In reply to Andrew Normore

Re: HELP: Backup an unreleated course is restoring previous activities in other courses!

by Ken Task -
Picture of Particularly helpful Moodlers

2.4 and 2.7 are quite old ... neither supported for fixes now - if it is a bug.  Don't re-call anyone ever reporting such a problem.

No longer have a 2.4 nor a 2.7 now to see if I could mess them up enough to exhibit behavior you are seeing.

To the best of my knowledge about DB's and MySQL ... there is no cache Moodle (any version) would get confused about.

Have you checked on the health of the DB's?   Any tables in need of repair?

Could you save a backup (no user) of one of these errant courses and provide it to someone else for 'inspection'?

One last thought ... in the past folks desiring to reduce code, etc. they used 'special' apache stuff in config.php ... using apache variables for site/location rather than the 'standard/stock' way.

One thing you might do ... dump a Moodle A site database to an sql file .... then, in a text editor, load up the .sql dump and do a search for Moodle site B url's.

'spirit of sharing', Ken