Hi Ken
the files in temp/backup don't look very big - the questions.xml 156 KB
```
/opt/moodle_deploy/moodledata/temp/backup/e61500005ead369497bd49af28446e4b# ls -l
total 280
drwxrwsrwx 39 www-data root 4096 Mar 26 10:54 activities
-rw-rw-rw- 1 www-data root 57 Mar 26 10:54 badges.xml
-rw-rw-rw- 1 www-data root 605 Mar 26 10:54 completion.xml
drwxrwsrwx 2 www-data root 4096 Mar 26 10:54 course
drwxrwsrwx 35 www-data root 4096 Mar 26 10:54 files
-rw-rw-rw- 1 www-data root 36068 Mar 26 10:54 files.xml
-rw-rw-rw- 1 www-data root 106 Mar 26 10:54 grade_history.xml
-rw-rw-rw- 1 www-data root 2899 Mar 26 10:54 gradebook.xml
-rw-rw-rw- 1 www-data root 186 Mar 26 10:54 groups.xml
-rw-rw-rw- 1 www-data root 0 Mar 26 10:54 moodle_backup.log
-rw-rw-rw- 1 www-data root 32204 Mar 26 10:54 moodle_backup.xml
-rw-rw-rw- 1 www-data root 83 Mar 26 10:54 outcomes.xml
-rw-rw-rw- 1 www-data root 156457 Mar 26 10:54 questions.xml
-rw-rw-rw- 1 www-data root 525 Mar 26 10:54 roles.xml
-rw-rw-rw- 1 www-data root 79 Mar 26 10:54 scales.xml
drwxrwsrwx 10 www-data root 4096 Mar 26 10:54 sections
-rw-rw-rw- 1 www-data root 5735 Mar 26 10:54 users.xml
```
running the backup on cli on DEV, seems ok
running the restore on cli on PROD, i get SQL duplicate entries error
```
root@4f0ff257087b:/var/www/html/moodle/admin/cli# /usr/local/bin/php ./restore_backup.php --file=/tmp/backup-moodle2-course-2-ai301-20250326-1534.mbz --categoryid=2 -s
== Extracting backup file to: /home/moodledata/temp/backup/9ffe4f6c6950433d23683a0f4d9d4182 ==
== Preprocessing backup file ==
instantiating restore controller da60ada9893a098c5a52801f20d814b6
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 7c4ab278860a3d172414684a97b7d98c
loading controller from db
setting controller status to 700
saving controller to db
calculating controller checksum bfca2001ccb849164c4654503fcf302d
loading controller from db
setting controller status to 800
saving controller to db
calculating controller checksum d9f8d9fc89ba71422aa540f8442311d4
loading controller from db
== Cleaning temp data ==
Default exception handler: Exception - Error writing to database (Duplicate entry '7-3' for key 'mdl_course_sections.mdl_coursect_cousec_uix'
UPDATE mdl_course_sections SET section = ? WHERE id=?
[array (
0 => 3,
1 => '80',
)]) Debug:
Error code: generalexceptionmessage
* line 133 of /admin/cli/restore_backup.php: core\exception\moodle_exception thrown
!!! Exception - Error writing to database (Duplicate entry '7-3' for key 'mdl_course_sections.mdl_coursect_cousec_uix'
UPDATE mdl_course_sections SET section = ? WHERE id=?
[array (
0 => 3,
1 => '80',
)]) !!!
!!
Error code: generalexceptionmessage !!
!! Stack trace: * line 133 of /admin/cli/restore_backup.php: core\exception\moodle_exception thrown
!!
Potential coding error - existing temptables found when disposing database. Must be dropped!
```
looking at DB, we seem to be replicating the sections (somehow sections for module 4, module 5 missing and i noticed a gap after id=2 .. till id=62)

on mdl_course it looks like this

went back to site admin > manage categories and courses and delete all courses + copies and clear the recycle bin
re-ran the restore course from CLI ... still same error
```
root@4f0ff257087b:/var/www/html/moodle/admin/cli# /usr/local/bin/php ./restore_backup.php --file=/tmp/backup-moodle2-course-2-ai301-20250326-1534.mbz --categoryid=2 -s
== Extracting backup file to: /home/moodledata/temp/backup/0f2513ae1af1302d36cb2a7b398887cc ==
== Preprocessing backup file ==
instantiating restore controller 3dfc3d7120b3d357e12042742f2b834f
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 4120ed15225c31204d123c17d7f2e580
loading controller from db
setting controller status to 700
saving controller to db
calculating controller checksum c05fabbdc282d573cc8be41aa6940be1
loading controller from db
setting controller status to 800
saving controller to db
calculating controller checksum 0e40abbba21a4a0dcbf728a3d7ddd733
loading controller from db
== Cleaning temp data ==
Default exception handler: Exception - Error writing to database (Duplicate entry '8-3' for key 'mdl_course_sections.mdl_coursect_cousec_uix'
UPDATE mdl_course_sections SET section = ? WHERE id=?
[array (
0 => 3,
1 => '86',
)]) Debug:
Error code: generalexceptionmessage
* line 133 of /admin/cli/restore_backup.php: core\exception\moodle_exception thrown
!!! Exception - Error writing to database (Duplicate entry '8-3' for key 'mdl_course_sections.mdl_coursect_cousec_uix'
UPDATE mdl_course_sections SET section = ? WHERE id=?
[array (
0 => 3,
1 => '86',
)]) !!!
!!
Error code: generalexceptionmessage !!
!! Stack trace: * line 133 of /admin/cli/restore_backup.php: core\exception\moodle_exception thrown
!!
Potential coding error - existing temptables found when disposing database. Must be dropped!
```
I wonder if it's something in my Module 4 that's causing some duplicate
Let know if you see something ... while i soldier on ... sigh
Thanks for your help