Course Reuse, Backup/Restore is not working, CLI and GUI Both

Course Reuse, Backup/Restore is not working, CLI and GUI Both

by dharmik dharmik -
Number of replies: 5

root@courses:/var/www/html/moodle# sudo -u www-data php admin/cli/backup.php --courseid=329 --destination=/path/to/moodledata/temp/backup

Default exception handler: Can't find data record in database table course. Debug: SELECT * FROM {course} WHERE id = ?
[array (
  0 => '329',
)]
Error code: invalidrecord
* line 1659 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
* line 1635 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
* line 83 of /admin/cli/backup.php: call to moodle_database->get_record()

!!! Can't find data record in database table course. !!!
!! SELECT * FROM {course} WHERE id = ?
[array (
  0 => '329',
)]
Error code: invalidrecord !!
!! Stack trace: * line 1659 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
* line 1635 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
* line 83 of /admin/cli/backup.php: call to moodle_database->get_record()

(Bunch of deprecated warnings -- skipped)
Destination directory does not exists or not writable.

Destination direcotry is exist but error showing 'not exists or not writable'

max_input_vars = 6000

above is CLI output, GUI stuck in backup, - "Process Pending"

2025/07/27 11:15:00 [alert] 1778900#1778900: *244 open socket #26 left in connection 7
2025/07/27 11:15:00 [alert] 1778900#1778900: *243 open socket #25 left in connection 15
2025/07/27 11:15:00 [alert] 1778900#1778900: *234 open socket #24 left in connection 20
2025/07/27 11:15:00 [alert] 1778900#1778900: *232 open socket #23 left in connection 28
2025/07/27 11:15:00 [alert] 1778900#1778900: aborting
2025/07/27 11:16:49 [error] 1811908#1811908: *7 FastCGI sent in stderr: "PHP message: PHP Warning:  Attempt to read property "modname" on null in /var/www/moodle/blocks/qtracker/block_qtracker.php on line 118" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: moodlesite.com, request: "GET /my/ HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "moodlesite.com", referrer: "https://moodlesite.com/my/courses.php"
2025/07/27 11:16:51 [error] 1811908#1811908: *7 FastCGI sent in stderr: "PHP message: Debugging: This file is no longer required in Moodle 4.2+. Please do not include/require it. in
* line 25 of /mod/quiz/accessmanager.php: call to debugging()
* line 33 of /blocks/edwiser_grader/classes/external/get_attempt_questions.php: call to require_once()
* line 155 of /lib/classes/component.php: call to include_once()
* line 38 of /blocks/edwiser_grader/classes/external/api.php: call to core_component::classloader()
* line 155 of /lib/classes/component.php: call to include_once()
* line ? of unknownfile: call to core_component::classloader()
* line 62 of /lib/external/classes/external_api.php: call to class_exists()
* line 186 of /lib/external/classes/external_api.php: call to core_external\external_api::external_function_info()
* line 83 of /lib/ajax/service.php: call to core_external\external_api::call_external_function()" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: moodlesite.com, request: "POST /lib/ajax/service.php?sesskey=Jjc4GiW1eI&info=block_edwiser_grader_get_course_quizzes HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "moodlesite.com", referrer: "https://moodlesite.com/my/"
2025/07/27 11:17:17 [error] 1811908#1811908: *7 FastCGI sent in stderr: "PHP message: loading controller from db; PHP message: loading controller from db" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: moodlesite.com, request: "GET /backup/copy.php?id=335 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "moodlesite.com", referrer: "https://moodlesite.com/backup/view.php?id=335"
2025/07/27 11:17:26 [error] 1811908#1811908: *7 FastCGI sent in stderr: "PHP message: loading controller from db; PHP message: loading controller from db; PHP message: instantiating backup controller 6d92c838b4eb71732188cca01746fe96; PHP message: setting controller status to 100; PHP message: loading controller plan; PHP message: setting controller status to 300; PHP message: applying plan defaults; PHP message: setting controller status to 400; PHP message: setting file inclusion to ; PHP message: checking plan security; PHP message: setting controller status to 700; PHP message: saving controller to db; PHP message: calculating controller checksum f75f7daff5e278bb58fa3f8cf77b35c5; PHP message: loading controller from db; PHP message: instantiating restore controller 8f99c7f99a18ce3b8e1748a2f7afde2b; PHP message: setting controller status to 100; PHP message: setting controller status to 200; PHP message: setting controller status to 700; PHP message: saving controller to db; PHP message: calculating controller checksum f75f7daff5e278bb58fa3f8cf77b35c5; PHP message: loading controller from db; PHP message: saving controller to db; PHP message: calculating controller checksum 592bea0f903dd30bdb85bccbfec3e752" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: moodlesite.com, request: "POST /backup/copy.php HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "moodlesite.com", referrer: "https://moodlesite.com/backup/copy.php?id=335"
2025/07/27 11:17:26 [error] 1811908#1811908: *7 FastCGI sent in stderr: "PHP message: loading controller from db; PHP message: loading controller from db; PHP message: loading controller from db" while reading upstream, client: XXX.XXX.XXX.XXX, server: moodlesite.com, request: "GET /backup/copyprogress.php?id=335 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "moodlesite.com", referrer: "https://moodlesite.com/backup/copy.php?id=335"
2025/07/27 11:20:41 [error] 1811908#1811908: *7 FastCGI sent in stderr: "PHP message: loading controller from db; PHP message: loading controller from db; PHP message: loading controller from db" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: moodlesite.com, request: "GET /backup/copy.php?id=335 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "moodlesite.com", referrer: "https://moodlesite.com/backup/view.php?id=335"
2025/07/27 11:21:38 [error] 1811908#1811908: *7 FastCGI sent in stderr: "PHP message: loading controller from db; PHP message: loading controller from db; PHP message: loading controller from db; PHP message: loading controller from db; PHP message: loading controller from db" while reading upstream, client: XXX.XXX.XXX.XXX, server: moodlesite.com, request: "GET /backup/restorefile.php?contextid=19619 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "moodlesite.com", referrer: "https://moodlesite.com/backup/view.php?id=335"

Attachment moodle-info.PNG
Attachment sql-output.PNG
Average of ratings: -
In reply to dharmik dharmik

Course Reuse, Backup/Restore is not working, CLI and GUI Both

by Ken Task -
Picture of Particularly helpful Moodlers

Confusing ...

your CLI backup course ID is 329
Does that course exist?
Make a query of your Moodle DB:

mysql> select id,shortname,fullname from mdl_course where ID=329;

--destination=/path/to/moodledata/temp/backup

I take it that /path/to/ above is hiding the true path?  OR did you actually use /path/to/ in command?

Why would you send it to the very directory moodle is using to build the .mbz file?

The resulting .mbz file would need to be seen by the CLI or the GUI in order to restore.
GUI file chooser has no access to that area of moodledata.

Moodle version 4.1.2

http://www.syndrega.ch/blog/#php-and-dbms-compatibility-of-major-moodle-releases

According to above resource, PHP max is 8.1 - you are running  php8.3-fpm

I see an addon: edwiser_grader.
Is that up to date and compat with the moodle version you are running? and another block_qtracker?

And another debug shows a different course ID? 335

'SoS', Ken

In reply to Ken Task

Course Reuse, Backup/Restore is not working, CLI and GUI Both

by dharmik dharmik -

-> Yes 329 exists in database but it is big size course so I created new one 335 and tried. I found that if I give name to new backup like "newbackup.mbz" than it is saying destination is not exist, without name just '/var/www/moodledata/temp/backup/' backup works, 

during restore, newely created course works. but if tried with course that I want to copy (329) it gives error..

root@B4E1659:/var/www/html/moodle# php admin/cli/restore_backup.php --file=/var/www/html/moodledata/temp/backup/backup-moodle2-course-329-quests_a-20250727-2043.mbz --categoryid=4
== Extracting backup file to: /var/www/html/moodledata/temp/backup/ee5367f46bfc415f657e4d342e215afa ==
== Preprocessing backup file ==
instantiating restore controller 20d6f4807ee067d9559ed976d381bc73
setting controller status to 100
loading backup info
loading controller plan
setting controller status to 300
applying restore defaults
Unknown setting: questionbank
setting controller status to 400
checking plan security
setting controller status to 600
saving controller to db
calculating controller checksum 73a6d0f7f8728fdd627cc0d1d2c1bd2f
loading controller from db
setting controller status to 700
saving controller to db
calculating controller checksum 5be17cdcd3249544e7e6b89fdb2bbbfc
loading controller from db
setting controller status to 800
saving controller to db
calculating controller checksum 6f1e646f74dbee2d2e639b63e24826f6
loading controller from db
PHP Fatal error:  restore_qtype_combined_plugin::convert_backup_to_questiondata() has #[\Override] attribute, but no matching parent method exists in /var/www/html/moodle/question/type/combined/backup/moodle2/restore_qtype_combined_plugin.class.php on line 48

In reply to dharmik dharmik

Course Reuse, Backup/Restore is not working, CLI and GUI Both

by Ken Task -
Picture of Particularly helpful Moodlers

Still confusing ...

With CLI backup you do have control over where the .mbz file is eventually copied to.   With GUI you don't.   IF not to the sea of files in moodledata/filedir/ could be going to priviate files ... your account (which is still in the sea of files - moodledata/filedir/xx/yy/longcontenthashname (note that's not humanly recognizable if one were to attempt to find that file.

From what you've shared this time, It has to do with a quiz and a plugin for quizzes.

There is a line: Unknown setting: questionbank

And the killer:

PHP Fatal error:  restore_qtype_combined_plugin::convert_backup_to_questiondata()

https://moodle.org/plugins/qtype_combined

https://github.com/moodleou/moodle-qtype_combined/issues

How large is the first .mbz file?

When you make the backup of the 329 course via GUI, step through the screens and select 1/2 of the course to be included.   Change the name the backup by adding '1sthalf' just after the 329 in the name.   That should go to your private files.    Then do a second backup, this time selecting the other half - adding to the name '2ndhalf' after the 329.

If you can id the quizzes that have qtype_combined in them you could attempt to exclude those quizzes from the backup.

On the restore ... new course for  1sthalf and if that restores, then restore 2ndhalf to same course.

Still might error ... but splitting the backup in 1/2 you then can look at the individual quiz's in that half.

Your cron job has a task that cleans up moodledata/temp/backup area.   Check the task list for the frequency that runs ... could be that task is attempting to clean up the stuff you are trying to restore.

'SoS', Ken

In reply to Ken Task

Course Reuse, Backup/Restore is not working, CLI and GUI Both

by dharmik dharmik -
Ok, Tried couple of things, updated moodle plugin and switched to PHP 8.1.. Now with CLI I can copy course, with GUI it stuck at 98% but you can see that course copied, still showing process. But when I try to delete that course, it is not deleting.. even tried deleting CLI copied course but it is stuck in loop of delete.. I was working in the sound blends group when this crashed - not problems before that. May be Question bank have issue with linking of new courses with question.. no error in CLI copy, I set debug mode to developer but not a single error I can see.. it is very confusing..
In reply to dharmik dharmik

Course Reuse, Backup/Restore is not working, CLI and GUI Both

by Ken Task -
Picture of Particularly helpful Moodlers

"sound blends group" ... what the heck does that mean?

Sent you a PM ... please respond there!

'SoS', Ken