Another point I forgot to mention with my script to recreate the mdl_backup_courses based on the mdl_course table content, make a backup (mysqldump) of this table before you truncate the table and insert the new records:
mysqldump -uyour-db-user -pyour-db-user-password moodle-database-name mdl_backup_courses > backup_mdl_backup_courses.sql
Restore the backup_mdl_backup_courses.sql with:
mysql -s -uyour-db-user -pyour-db-user-password moodle-database-name< backup_mdl_backup_courses.sql
You can also restore the last backup of your complete database, but this works faster, restore only the mdl_backup_courses table if necessary if you get into trouble with the recreated mdl_backup_courses table. It's always preferred not to test this on your production site if you don't know how Moodle (backup) will behave after this change of the automated backup!