The copy course makes a backup of the course to restore thus uses moodledata/temp/backup/ as the build area. Inside there a 'contenthashed' named directory and inside that some xml files with related directories.
$a variable is a module in that course and yes, totally useless info when attempting to trouble shoot this.
This might be re-occuring due to a stuck adhoc task - which are cron jobs that didn't complete for some reason.
There are tables in the DB that track such stuff.
One is mdl_task_adhoc - if cron job is running ok, there's nothing in that table. If you find records in that table ... truncate the table.
There are 3 tables related to backup ...
from mysql client using the DB for the moodle:
show tables like '%backup%';
of those
mdl_backup_courses is a 'tracker' ... take a gander at any row in that table that has the course ID numbers you are having issues with.
That table could also be truncated. As could any of the backup tables.
One could drive him/herself crazy trying to figure it out! To be honest, I'd take the easy way out and truncate any table that tracks related to this issue - it's like starting over and see if that makes this go away!
You did ask for guesses!
'SoS', Ken